From 7b889820633c5dd58c074cfb3c0386c3a4d98367 Mon Sep 17 00:00:00 2001
From: David Hammer <dhammer@mailbox.org>
Date: Tue, 12 Apr 2022 13:16:31 +0200
Subject: [PATCH] Allow replacing preview-breaking values for GH2 streak, too

---
 src/calng/Gotthard2Correction.py | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/calng/Gotthard2Correction.py b/src/calng/Gotthard2Correction.py
index d03eeb83..126e0dee 100644
--- a/src/calng/Gotthard2Correction.py
+++ b/src/calng/Gotthard2Correction.py
@@ -2,6 +2,7 @@ import enum
 
 import numpy as np
 from karabo.bound import (
+    FLOAT_ELEMENT,
     IMAGEDATA_ELEMENT,
     KARABO_CLASSINFO,
     NODE_ELEMENT,
@@ -232,6 +233,14 @@ class Gotthard2Correction(BaseCorrection):
             .key("preview.outputStreak")
             .dataSchema(streak_preview_schema)
             .commit(),
+
+            FLOAT_ELEMENT(expected)
+            .key("preview.replaceNanWith")
+            .displayedName("Replace streak NaNs by by")
+            .assignmentOptional()
+            .defaultValue(-1000)
+            .reconfigurable()
+            .commit(),
         )
 
         Gotthard2CalcatFriend.add_schema(expected, Gotthard2Correction._managed_keys)
@@ -334,12 +343,16 @@ class Gotthard2Correction(BaseCorrection):
                 metadata,
             )
             # custom additional preview for this 1D detector
+            streak_preview = buffer_array.copy()
+            replacement = self.unsafe_get("preview.replaceNanWith")
+            streak_preview[np.isnan(streak_preview)] = replacement
+            streak_preview[np.isinf(streak_preview)] = replacement
             self.writeChannel(
                 "preview.outputStreak",
                 Hash(
                     "image.data",
                     ImageData(
-                        buffer_array,
+                        streak_preview,
                         Dims(*buffer_array.shape),
                         Encoding.GRAY,
                         bitsPerPixel=32,
-- 
GitLab