From 997efa150e9ba8e3799c5e87bc928602cbb6e204 Mon Sep 17 00:00:00 2001
From: Thomas Kluyver <thomas.kluyver@xfel.eu>
Date: Tue, 9 May 2023 19:08:33 +0200
Subject: [PATCH] Automatic use_cell_order for LPD-1M correction

---
 notebooks/LPD/LPD_Correct_Fast.ipynb | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/notebooks/LPD/LPD_Correct_Fast.ipynb b/notebooks/LPD/LPD_Correct_Fast.ipynb
index 58c3fbada..5401afd13 100644
--- a/notebooks/LPD/LPD_Correct_Fast.ipynb
+++ b/notebooks/LPD/LPD_Correct_Fast.ipynb
@@ -46,7 +46,7 @@
     "capacitor = '5pF'  # Capacitor setting: 5pF or 50pF\n",
     "photon_energy = 9.2  # Photon energy in keV.\n",
     "category = 0  # Whom to blame.\n",
-    "use_cell_order = False  # Whether to use memory cell order as a detector condition (not stored for older constants)\n",
+    "use_cell_order = 'auto'  # Whether to use memory cell order as a detector condition; auto/always/never\n",
     "\n",
     "# Correction parameters\n",
     "offset_corr = True  # Offset correction.\n",
@@ -154,7 +154,10 @@
     "    do_sequence = [int(x) for x in sequences].__contains__    \n",
     "    \n",
     "# List of detector sources.\n",
-    "det_inp_sources = [input_source.format(karabo_id=karabo_id, module_index=int(da[-2:])) for da in karabo_da]"
+    "det_inp_sources = [input_source.format(karabo_id=karabo_id, module_index=int(da[-2:])) for da in karabo_da]\n",
+    "\n",
+    "if use_cell_order not in {'auto', 'always', 'never'}:\n",
+    "    raise ValueError(\"use_cell_order must be auto/always/never\")"
    ]
   },
   {
@@ -264,10 +267,10 @@
     "        dict(parameter_id=13, value=256),  # Pixels X\n",
     "        dict(parameter_id=14, value=256),  # Pixels Y\n",
     "    ]\n",
-    "    if use_cell_order:\n",
+    "    if use_cell_order != 'never':\n",
     "        # Read the order of memory cells used\n",
     "        raw_data = xd.DataCollection.from_paths([e[1] for e in data_to_process])\n",
-    "        cell_ids_pattern_s = get_mem_cell_order(raw_data, det_inp_sources)\n",
+    "        cell_ids_pattern_s = get_mem_cell_order(raw_data, det_inp_sources, use_cell_order)\n",
     "        print(\"Memory cells order:\", cell_ids_pattern_s)\n",
     "\n",
     "        dark_condition = base_condition + [\n",
-- 
GitLab