From 54788b868a490fd430ac5b29f1a30559c5163659 Mon Sep 17 00:00:00 2001
From: Karim Ahmed <karim.ahmed@xfel.eu>
Date: Wed, 10 Feb 2021 14:18:56 +0100
Subject: [PATCH] adding changes for agipdlib.py

---
 cal_tools/cal_tools/agipdlib.py                  | 11 ++++++++---
 notebooks/DSSC/Characterize_DSSC_Darks_NBC.ipynb | 13 ++++++++-----
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/cal_tools/cal_tools/agipdlib.py b/cal_tools/cal_tools/agipdlib.py
index 598ab81be..f89f643fd 100644
--- a/cal_tools/cal_tools/agipdlib.py
+++ b/cal_tools/cal_tools/agipdlib.py
@@ -840,10 +840,15 @@ class AgipdCorrections:
         # or with only simple pulse ranging.
         if pulse_step > 1 or \
                 allpulses[first_pulse] >= allpulses[last_pulse]:
-            can_calibrate = can_calibrate and np.isin(allpulses, cal_pulses)
+            can_calibrate = np.logical_and(can_calibrate,
+                                           np.isin(allpulses, cal_pulses))
         else:
-            can_calibrate = can_calibrate and (allpulses <= np.min(cal_pulses))  # noqa
-            can_calibrate = can_calibrate and (allpulses >= np.max(cal_pulses))  # noqa
+            # Check interesection between array of booleans and
+            # array of pulses to calibrate.
+            can_calibrate = np.logical_and(can_calibrate,
+                                           (allpulses <= np.max(cal_pulses)),
+                                           (allpulses >= np.min(cal_pulses))
+                                           )
 
         return can_calibrate
 
diff --git a/notebooks/DSSC/Characterize_DSSC_Darks_NBC.ipynb b/notebooks/DSSC/Characterize_DSSC_Darks_NBC.ipynb
index 43d7d2437..fd8d225f5 100644
--- a/notebooks/DSSC/Characterize_DSSC_Darks_NBC.ipynb
+++ b/notebooks/DSSC/Characterize_DSSC_Darks_NBC.ipynb
@@ -315,11 +315,14 @@
     "all_cells = []\n",
     "checksums = {}\n",
     "\n",
-    "tGain, encodedGain, operatingFreq = get_dssc_ctrl_data(in_folder + f\"/r{:04d}/\".format(offset_runs[\"high\"]),\n",
-    "                                                       slow_data_pattern,\n",
-    "                                                       slow_data_aggregators,\n",
-    "                                                       offset_runs[\"high\"])\n",
-    "\n",
+    "try:\n",
+    "    tGain, encodedGain, operatingFreq = get_dssc_ctrl_data(in_folder + \"/r{:04d}/\".format(offset_runs[\"high\"]),\n",
+    "                                                           slow_data_pattern,\n",
+    "                                                           slow_data_aggregators,\n",
+    "                                                           offset_runs[\"high\"])\n",
+    "except KeyError:\n",
+    "    print(\"ERROR: Couldn't access slow data to read tGain, encodedGain, and operatingFreq \\n\")\n",
+    "    \n",
     "for gain, mapped_files in gain_mapped_files.items():\n",
     "    inp = []\n",
     "    dones = []\n",
-- 
GitLab