From 960e710c00cfb3ff8b16dd9ab7257ee4a8684046 Mon Sep 17 00:00:00 2001
From: Egor Sobolev <egor.sobolev@xfel.eu>
Date: Mon, 5 Aug 2024 14:40:15 +0200
Subject: [PATCH] Apply suggestions: (i) check settings instead of catching
 exception, fix NameError

---
 ...AGIPD_Correct_and_Verify_Summary_NBC.ipynb | 25 +++++++++++--------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/notebooks/AGIPD/AGIPD_Correct_and_Verify_Summary_NBC.ipynb b/notebooks/AGIPD/AGIPD_Correct_and_Verify_Summary_NBC.ipynb
index 13ad6a0cf..d33ae9d81 100644
--- a/notebooks/AGIPD/AGIPD_Correct_and_Verify_Summary_NBC.ipynb
+++ b/notebooks/AGIPD/AGIPD_Correct_and_Verify_Summary_NBC.ipynb
@@ -21,6 +21,7 @@
     "karabo_da = ['-1']  # a list of data aggregators names, Default [-1] for selecting all data aggregators\n",
     "rel_gain_mode = \"off\"  # Select relative gain correction. Choices [`PC`, `CS`, `off`]. (`PC`: Pulse Capacitor, `CS`: Current Source, `off`: Disable relative gain correction). Default: off.\n",
     "# Additional processing\n",
+    "count_lit_pixels = False  # Count the number of pixels registering photons\n",
     "spi_hitfinding = False  # Find hits using lit-pixel counter\n",
     "\n",
     "# SPI hit-finder parameters\n",
@@ -139,18 +140,20 @@
    "metadata": {},
    "outputs": [],
    "source": [
-    "if spi_hitfinding:\n",
+    "if spi_hitfinding and not count_lit_pixels:\n",
+    "    # Operators are not expected to enable SPI hitfidnig without lit-pixels\n",
+    "    # counting. If this happens, warn on the mismatch in the configuration.\n",
+    "    warning(\"SPI hitfinding will be skipped because the required lit-pixel \"\n",
+    "            \"counting is disabled. To run hitfinding, enable also lit-pixel \"\n",
+    "            \"counting with the `--count-lit-pixels` option.\")\n",
+    "\n",
+    "if spi_hitfinding and count_lit_pixels:\n",
     "    display(Markdown(\"# SPI hit finding\"))\n",
-    "    try:\n",
-    "        dc = RunDirectory(out_folder)\n",
-    "        litpx_src = StackedPulseSource.from_datacollection(\n",
-    "            dc, f\"{karabo_id}/CORR/(?P<key>\\d+)CH0:output\", \"litpx\")\n",
-    "    except ValueError:\n",
-    "        litpx_src = None\n",
-    "        warning(\"The data sources of the number of lit-pixels are not found. \"\n",
-    "                \"Use `count_lit_pixels = True`\")\n",
-    "\n",
-    "if litpx_src is not None:    \n",
+    "\n",
+    "    dc = RunDirectory(out_folder)\n",
+    "    litpx_src = StackedPulseSource.from_datacollection(\n",
+    "        dc, f\"{karabo_id}/CORR/(?P<key>\\d+)CH0:output\", \"litpx\")\n",
+    "\n",
     "    hitfinder = SpiHitfinder(\n",
     "        modules=spi_hf_modules,\n",
     "        mode=spi_hf_mode,\n",
-- 
GitLab