From 869eccd6b209a335b362cc339f9b593ca620f9ca Mon Sep 17 00:00:00 2001
From: ahmedk <karim.ahmed@xfel.eu>
Date: Mon, 19 Jun 2023 11:08:32 +0200
Subject: [PATCH] Fixes after testing correction notebook

---
 notebooks/LPD/LPD_Correct_Fast.ipynb | 35 +++++++++++++---------------
 1 file changed, 16 insertions(+), 19 deletions(-)

diff --git a/notebooks/LPD/LPD_Correct_Fast.ipynb b/notebooks/LPD/LPD_Correct_Fast.ipynb
index 6011e9b3a..aa5897be5 100644
--- a/notebooks/LPD/LPD_Correct_Fast.ipynb
+++ b/notebooks/LPD/LPD_Correct_Fast.ipynb
@@ -105,7 +105,7 @@
     "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.calcat_interface import CalCatError, 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.tools import CalibrationMetadata, calcat_creation_time\n",
@@ -278,7 +278,6 @@
     "            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",
@@ -291,13 +290,19 @@
     "        event_at=creation_time,\n",
     "        client=rest_cfg.calibration_client(),\n",
     "    )\n",
-    "    const_data = lpd_cal.ndarray_map(\n",
-    "        [\n",
-    "            \"Offset\", \"BadPixelsDark\",\n",
-    "            \"BadPixelsFF\", \"GainAmpMap\",\n",
-    "            \"FFMap\", \"RelativeGain\",\n",
-    "        ]\n",
-    "    )"
+    "    const_data = {mod: {\"no-constants-retrieved\": None} for mod in karabo_da}\n",
+    "    try:\n",
+    "        const_data = lpd_cal.ndarray_map(\n",
+    "            [\n",
+    "                \"Offset\", \"BadPixelsDark\",\n",
+    "                \"BadPixelsFF\", \"GainAmpMap\",\n",
+    "                \"FFMap\", \"RelativeGain\",\n",
+    "            ]\n",
+    "        )\n",
+    "    except CalCatError as e:\n",
+    "        warning(e)\n",
+    "total_time = perf_counter() - start\n",
+    "print(f'Loading constants {total_time:.1f}s')"
    ]
   },
   {
@@ -315,20 +320,12 @@
     "        warning(f\"Offset constant is not available to correct {mod}\")  # noqa\n",
     "        karabo_da.remove(mod)\n",
     "    if warn_missing_constants:\n",
-    "        warning(f\"Gain constants {missing_gain_constants} were not retrieved for {mod}\")\n",
-    "    if (\n",
-    "        calibrations.get(\"BadPixelsDark\") and\n",
-    "        calibrations[\"BadPixelsDark\"].dtype != np.uint32\n",
-    "    ):  # Old LPD constants are stored as float32.\n",
-    "        calibrations[\"BadPixelsDark\"] = calibrations[\"BadPixelsDark\"].astype(np.uint32, copy=False)\n",
+    "        warning(f\"Gain constants {warn_missing_constants} were not retrieved for {mod}\")\n",
     "if not karabo_da:  # Offsets are missing for all modules.\n",
     "    raise Exception(\"Could not find offset constants for all modules, will not correct data.\")\n",
     "\n",
     "# Remove skipped correction modules from data_to_process\n",
-    "data_to_process = [(mod, in_f, out_f) for mod, in_f, out_f in data_to_process if mod in [karabo_da]]\n",
-    "\n",
-    "total_time = perf_counter() - start\n",
-    "print(f'{total_time:.1f}s')"
+    "data_to_process = [(mod, in_f, out_f) for mod, in_f, out_f in data_to_process if mod in karabo_da]"
    ]
   },
   {
-- 
GitLab