From 2a4bd898e1777ab69f4736201081072e43ec8c2f Mon Sep 17 00:00:00 2001
From: ahmedk <karim.ahmed@xfel.eu>
Date: Tue, 21 May 2024 13:25:38 +0200
Subject: [PATCH] fix for the second module

---
 .../Gotthard2/Characterize_Darks_Gotthard2_NBC.ipynb   | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/notebooks/Gotthard2/Characterize_Darks_Gotthard2_NBC.ipynb b/notebooks/Gotthard2/Characterize_Darks_Gotthard2_NBC.ipynb
index cac1795f6..5ece45ff6 100644
--- a/notebooks/Gotthard2/Characterize_Darks_Gotthard2_NBC.ipynb
+++ b/notebooks/Gotthard2/Characterize_Darks_Gotthard2_NBC.ipynb
@@ -53,7 +53,7 @@
     "single_photon = -1  # Detector single photon mode (High/Low CDS), set to -1 to use value in raw file.\n",
     "\n",
     "# Parameters used for calculating calibration constants\n",
-    "bpix_noise_nitrs = 2  # number of maximum iterations to actively try to reach correct number of badpixels of NOISE_OUT_OF_THRESHOLD type. Leave -1 to keep iterating until finding maximum number of badpixels.\n",
+    "bpix_noise_nitrs = 5  # number of maximum iterations to actively try to reach correct number of badpixels of NOISE_OUT_OF_THRESHOLD type. Leave -1 to keep iterating until finding maximum number of badpixels.\n",
     "# Parameters used during selecting raw data trains.\n",
     "min_trains = 1  # Minimum number of trains that should be available to process dark constants. Default 1.\n",
     "max_trains = 1000  # Maximum number of trains to use for processing dark constants. Set to 0 to use all available trains.\n",
@@ -480,7 +480,8 @@
     "    nmap = noise_map[mod].copy()\n",
     "    last_nbpix = 0\n",
     "    # Calculate NOISE_OUT_OF_THRESHOLD bpix in multiple iterations.\n",
-    "    while bpix_noise_nitrs > 0:\n",
+    "    nitr = -1\n",
+    "    while nitr != bpix_noise_nitrs:\n",
     "        badpixels_map[mod][\n",
     "            eval_bpidx(nmap)\n",
     "        ] |= BadPixels.NOISE_OUT_OF_THRESHOLD.value\n",
@@ -488,9 +489,10 @@
     "        recent_nbpix = np.count_nonzero(badpixels_map[mod])\n",
     "\n",
     "        if last_nbpix == recent_nbpix:\n",
-    "            bpix_noise_nitrs = 0\n",
+    "            # skip iterations if no more difference.\n",
+    "            nitr = bpix_noise_nitrs\n",
     "        else:\n",
-    "            bpix_noise_nitrs = bpix_noise_nitrs - 1\n",
+    "            nitr += 1\n",
     "        last_nbpix = recent_nbpix\n",
     "\n",
     "    if local_output:\n",
-- 
GitLab