From cfb4708a91ab73cf480ddd5b166b7f7ead34d7d0 Mon Sep 17 00:00:00 2001
From: ahmedk <karim.ahmed@xfel.eu>
Date: Fri, 1 Apr 2022 06:57:04 +0200
Subject: [PATCH] skip PC sanitization with constants of v1

---
 src/cal_tools/agipdlib.py | 58 +++++++++++++++++++++++----------------
 1 file changed, 34 insertions(+), 24 deletions(-)

diff --git a/src/cal_tools/agipdlib.py b/src/cal_tools/agipdlib.py
index 820d83a4f..f68e3b5d7 100644
--- a/src/cal_tools/agipdlib.py
+++ b/src/cal_tools/agipdlib.py
@@ -1225,30 +1225,40 @@ class AgipdCorrections:
                 pc_high_l_med = np.nanmedian(pc_high_l, axis=(0, 1))
                 pc_med_l_med = np.nanmedian(pc_med_l, axis=(0, 1))
 
-                # sanitize PC data
-                # (it should be done already on the level of constants)
-                # In the following loop,
-                # replace `nan`s across memory cells with
-                # the median value calculated previously.
-                # Then, values outside of the valid range (0.8 and 1.2)
-                # are fixed to the median value.
-                # This is applied for high and medium gain stages
-                for i in range(self.max_cells):
-                    pc_high_m[np.isnan(pc_high_m[..., i]), i] = pc_high_med[i]
-                    pc_med_m[np.isnan(pc_med_m[..., i]), i] = pc_med_med[i]
-
-                    pc_high_l[np.isnan(pc_high_l[..., i]), i] = pc_high_l_med[i]
-                    pc_med_l[np.isnan(pc_med_l[..., i]), i] = pc_med_l_med[i]
-
-                    pc_high_m[(pc_high_m[..., i] < 0.8 * pc_high_med[i]) |
-                              (pc_high_m[..., i] > 1.2 * pc_high_med[i]), i] = pc_high_med[i]  # noqa
-                    pc_med_m[(pc_med_m[..., i] < 0.8 * pc_med_med[i]) |
-                             (pc_med_m[..., i] > 1.2 * pc_med_med[i]), i] = pc_med_med[i]  # noqa
-
-                    pc_high_l[(pc_high_l[..., i] < 0.8 * pc_high_l_med[i]) |
-                              (pc_high_l[..., i] > 1.2 * pc_high_l_med[i]), i] = pc_high_l_med[i]  # noqa
-                    pc_med_l[(pc_med_l[..., i] < 0.8 * pc_med_l_med[i]) |
-                             (pc_med_l[..., i] > 1.2 * pc_med_l_med[i]), i] = pc_med_l_med[i]  # noqa
+                if variant == 0:
+                    # sanitize PC data with CCV variant = 0.
+                    # Sanitization is already done for constants
+                    # with CCV variant = 1
+                    # In the following loop,
+                    # replace `nan`s across memory cells with
+                    # the median value calculated previously.
+                    # Then, values outside of the valid range (0.8 and 1.2)
+                    # are fixed to the median value.
+                    # This is applied for high and medium gain stages
+                    for i in range(self.max_cells):
+                        pc_high_m[
+                            np.isnan(pc_high_m[..., i]), i] = pc_high_med[i]
+                        pc_med_m[
+                            np.isnan(pc_med_m[..., i]), i] = pc_med_med[i]
+
+                        pc_high_l[
+                            np.isnan(pc_high_l[..., i]), i] = pc_high_l_med[i]
+                        pc_med_l[
+                            np.isnan(pc_med_l[..., i]), i] = pc_med_l_med[i]
+
+                        pc_high_m[
+                            (pc_high_m[..., i] < 0.8 * pc_high_med[i]) |
+                            (pc_high_m[..., i] > 1.2 * pc_high_med[i]), i] = pc_high_med[i]  # noqa
+                        pc_med_m[
+                            (pc_med_m[..., i] < 0.8 * pc_med_med[i]) |
+                            (pc_med_m[..., i] > 1.2 * pc_med_med[i]), i] = pc_med_med[i]  # noqa
+
+                        pc_high_l[
+                            (pc_high_l[..., i] < 0.8 * pc_high_l_med[i]) |
+                            (pc_high_l[..., i] > 1.2 * pc_high_l_med[i]), i] = pc_high_l_med[i]  # noqa
+                        pc_med_l[
+                            (pc_med_l[..., i] < 0.8 * pc_med_l_med[i]) |
+                            (pc_med_l[..., i] > 1.2 * pc_med_l_med[i]), i] = pc_med_l_med[i]  # noqa
 
                 # ration between HG and MG per pixel per mem cell used
                 # for rel gain calculation
-- 
GitLab