From 725c4032f28653516c635638ddcd8fcc6d4d2981 Mon Sep 17 00:00:00 2001
From: Laurent Mercadier <laurent.mercadier@xfel.eu>
Date: Fri, 28 Feb 2025 16:24:38 +0100
Subject: [PATCH] fix dtype when using xr.where()

---
 src/toolbox_scs/detectors/viking.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/toolbox_scs/detectors/viking.py b/src/toolbox_scs/detectors/viking.py
index 0eb3ab4..fe62261 100644
--- a/src/toolbox_scs/detectors/viking.py
+++ b/src/toolbox_scs/detectors/viking.py
@@ -309,6 +309,7 @@ class Viking:
             return
         x = data.newt_x
         spectra = data[key]
+        #print(x)
         mask = xr.ones_like(x, dtype=bool)
         if len(self.BL_SIGNAL_RANGE) > 0:
             if not hasattr(self.BL_SIGNAL_RANGE[0], '__len__'):
@@ -317,8 +318,11 @@ class Viking:
                 ranges = self.BL_SIGNAL_RANGE
             for xrange in ranges:
                 mask = mask & ((x < xrange[0]) | (x > xrange[1]))
-        x_bl = x.where(mask, drop=True).astype(int)
+        x_bl = x.where(mask, drop=True).astype(x.dtype)
         bl = spectra.sel(newt_x=x_bl)
+        #print(mask)
+        #print(x_bl)
+        #print(bl)
         fit = np.polyfit(x_bl, bl.T, self.BL_POLY_DEG)
         if len(spectra.shape) == 1:
             return spectra - np.polyval(fit, x)
-- 
GitLab