From 0d4b2e7b98b73dba169553c769fcab299efe8d4b Mon Sep 17 00:00:00 2001
From: ahmedk <karim.ahmed@xfel.eu>
Date: Mon, 19 Jun 2023 09:37:07 +0200
Subject: [PATCH] fix use_cell_order check part

---
 notebooks/LPD/LPD_Correct_Fast.ipynb              | 15 +++++++--------
 .../LPD_retrieve_constants_precorrection.ipynb    |  6 ++++--
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/notebooks/LPD/LPD_Correct_Fast.ipynb b/notebooks/LPD/LPD_Correct_Fast.ipynb
index d66171b0d..54654b2db 100644
--- a/notebooks/LPD/LPD_Correct_Fast.ipynb
+++ b/notebooks/LPD/LPD_Correct_Fast.ipynb
@@ -102,13 +102,12 @@
     "import extra_data as xd\n",
     "import extra_geom as xg\n",
     "import pasha as psh\n",
-    "\n",
     "from extra_data.components import LPD1M\n",
     "\n",
     "import cal_tools.restful_config as rest_cfg\n",
     "from cal_tools.calcat_interface import LPD_CalibrationData\n",
     "from cal_tools.lpdalgs import correct_lpd_frames\n",
-    "from cal_tools.lpdlib import get_mem_cell_pattern, make_cell_order_condition\n",
+    "from cal_tools.lpdlib import get_mem_cell_order\n",
     "from cal_tools.tools import CalibrationMetadata, calcat_creation_time\n",
     "from cal_tools.files import DataFile"
    ]
@@ -267,7 +266,6 @@
     "            const_data[mod][cname] = const_load_mp.alloc(  # TODO: MAKE SURE WE ERROR OUT FOR MISSING OFFSET\n",
     "                    shape=(256, 256, mem_cells, 3),  # All LPD constants have the same shape.\n",
     "                    dtype=np.uint32 if cname.startswith('BadPixels') else np.float32\n",
-    
     "            )\n",
     "    def load_constant_dataset(wid, index, mod):\n",
     "        for cname, mdata in const_yaml[mod][\"constants\"].items():\n",
@@ -275,20 +273,21 @@
     "                cf[f\"{mdata['dataset']}/data\"].read_direct(const_data[mod][cname])\n",
     "\n",
     "    const_load_mp.map(load_constant_dataset, karabo_da)\n",
-    "\n",
     "else:\n",
-    "    cell_ids_pattern_s = None  # TODO: FIX AFTER REBASING\n",
-    "    if use_cell_order:\n",
+    "    cell_ids_pattern_s = None\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 = make_cell_order_condition(\n",
+    "            use_cell_order, get_mem_cell_pattern(raw_data, det_inp_sources)\n",
+    "        )\n",
     "        print(\"Memory cells order:\", cell_ids_pattern_s)\n",
     "\n",
     "    lpd_cal = LPD_CalibrationData(\n",
     "        detector_name=karabo_id,\n",
     "        modules=karabo_da,\n",
     "        sensor_bias_voltage=bias_voltage,\n",
-    "        memory_cells=mem_cells,  # TODO: ADD MISSING CONDITION AFTER REBASING\n",
+    "        memory_cells=mem_cells,\n",
     "        feedback_capacitor=capacitor,\n",
     "        source_energy=photon_energy,\n",
     "        memory_cell_order=cell_ids_pattern_s,\n",
diff --git a/notebooks/LPD/LPD_retrieve_constants_precorrection.ipynb b/notebooks/LPD/LPD_retrieve_constants_precorrection.ipynb
index 172432643..cc1df118b 100644
--- a/notebooks/LPD/LPD_retrieve_constants_precorrection.ipynb
+++ b/notebooks/LPD/LPD_retrieve_constants_precorrection.ipynb
@@ -114,10 +114,12 @@
     "step_timer.start()\n",
     "\n",
     "cell_ids_pattern_s = None\n",
-    "if use_cell_order:\n",
+    "if use_cell_order != 'never':\n",
     "    # Read the order of memory cells used\n",
     "    raw_data = xd.RunDirectory(Path(in_folder, f'r{run:04d}'))\n",
-    "    cell_ids_pattern_s = get_mem_cell_order(raw_data, det_inp_sources)\n",
+    "    cell_ids_pattern_s = make_cell_order_condition(\n",
+    "        use_cell_order, get_mem_cell_pattern(raw_data, det_inp_sources)\n",
+    "    )\n",
     "    print(\"Memory cells order:\", cell_ids_pattern_s)\n",
     "\n",
     "lpd_cal = LPD_CalibrationData(\n",
-- 
GitLab