From 0a995d3058e24ffbf90e8e4f30069f53138a06d4 Mon Sep 17 00:00:00 2001
From: Philipp Schmidt <philipp.schmidt@xfel.eu>
Date: Mon, 12 Jul 2021 10:54:19 +0200
Subject: [PATCH] Add notebook parameter for AGIPD integration time to override
 detection

---
 notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb             | 4 +++-
 .../AGIPD/AGIPD_Retrieve_Constants_Precorrection.ipynb     | 4 +++-
 notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb    | 7 ++++---
 .../AGIPD/Characterize_AGIPD_Gain_FlatFields_Summary.ipynb | 6 ++++--
 notebooks/AGIPD/Chracterize_AGIPD_Gain_PC_NBC.ipynb        | 4 +++-
 5 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb b/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb
index 5a257ef44..0d9de779b 100644
--- a/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb
+++ b/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb
@@ -49,6 +49,7 @@
     "max_pulses = [0, 500, 1] # range list [st, end, step] of maximum pulse indices within a train. 3 allowed maximum list input elements.\n",
     "mem_cells_db = 0 # set to a value different than 0 to use this value for DB queries\n",
     "cell_id_preview = 1 # cell Id used for preview in single-shot plots\n",
+    "integration_time = -1 # integration time, negative values for auto-detection.\n",
     "\n",
     "# Correction parameters\n",
     "blc_noise_threshold = 5000 # above this mean signal intensity now baseline correction via noise is attempted\n",
@@ -376,7 +377,8 @@
     "gain_mode = get_gain_mode(control_fn, h5path_ctrl)\n",
     "\n",
     "# Evaluate integration time\n",
-    "integration_time = get_integration_time(control_fn, h5path_ctrl)"
+    "if integration_time < 0:\n",
+    "    integration_time = get_integration_time(control_fn, h5path_ctrl)"
    ]
   },
   {
diff --git a/notebooks/AGIPD/AGIPD_Retrieve_Constants_Precorrection.ipynb b/notebooks/AGIPD/AGIPD_Retrieve_Constants_Precorrection.ipynb
index f6b3b4751..e5dc04b60 100644
--- a/notebooks/AGIPD/AGIPD_Retrieve_Constants_Precorrection.ipynb
+++ b/notebooks/AGIPD/AGIPD_Retrieve_Constants_Precorrection.ipynb
@@ -44,6 +44,7 @@
     "photon_energy = 9.2 # photon energy in keV\n",
     "max_cells_db_dark = 0  # set to a value different than 0 to use this value for dark data DB queries\n",
     "max_cells_db = 0 # set to a value different than 0 to use this value for DB queries\n",
+    "integration_time = -1 # integration time, negative values for auto-detection.\n",
     "\n",
     "# Correction Booleans\n",
     "only_offset = False # Apply only Offset correction. if False, Offset is applied by Default. if True, Offset is only applied.\n",
@@ -163,7 +164,8 @@
     "gain_mode = agipdlib.get_gain_mode(control_fn, h5path_ctrl)\n",
     "\n",
     "# Evaluate integration time\n",
-    "integration_time = agipblib.get_integration_time(control_fn, h5path_ctrl)\n",
+    "if integration_time < 0:\n",
+    "    integration_time = agipblib.get_integration_time(control_fn, h5path_ctrl)\n",
     "            \n",
     "print(f\"Gain setting: {gain_setting}\")\n",
     "print(f\"Gain mode: {gain_mode.name}\")\n",
diff --git a/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb b/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb
index 565947c2d..35fddcd6a 100644
--- a/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb
+++ b/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb
@@ -186,9 +186,10 @@
     "else:\n",
     "    print(f'Something is clearly wrong; slow data indicates gain modes {run_gain_modes}')\n",
     "\n",
-    "integration_times = [get_integration_time(fn, h5path_ctrl) for fn in control_names]\n",
-    "if len(set(integration_times)) > 1:\n",
-    "    print(f'WARNING: integration time is not constant across the specified dark runs')\n",
+    "if integration_time < 0:\n",
+    "    integration_times = [get_integration_time(fn, h5path_ctrl) for fn in control_names]\n",
+    "    if len(set(integration_times)) > 1:\n",
+    "        print(f'WARNING: integration time is not constant across the specified dark runs')\n",
     "\n",
     "integration_time = integration_times[0]\n",
     "\n",
diff --git a/notebooks/AGIPD/Characterize_AGIPD_Gain_FlatFields_Summary.ipynb b/notebooks/AGIPD/Characterize_AGIPD_Gain_FlatFields_Summary.ipynb
index 51f0de6dc..7ab5a24ef 100644
--- a/notebooks/AGIPD/Characterize_AGIPD_Gain_FlatFields_Summary.ipynb
+++ b/notebooks/AGIPD/Characterize_AGIPD_Gain_FlatFields_Summary.ipynb
@@ -59,7 +59,8 @@
     "bias_voltage = 300 # Bias voltage\n",
     "acq_rate = 0. # the detector acquisition rate, use 0 to try to auto-determine\n",
     "gain_setting = 0.1 # the gain setting, use 0.1 to try to auto-determine\n",
-    "photon_energy = 8.05 # photon energy in keV"
+    "photon_energy = 8.05 # photon energy in keV\n",
+    "integration_time = -1 # integration time, negative values for auto-detection."
    ]
   },
   {
@@ -164,7 +165,8 @@
     "            gain_setting = 0\n",
     "\n",
     "# Evaluate integration time\n",
-    "integration_time = get_integration_time(filename, h5path_ctrl)\n",
+    "if integration_time < 0:\n",
+    "    integration_time = get_integration_time(filename, h5path_ctrl)\n",
     "            \n",
     "# Evaluate detector instance for mapping\n",
     "instrument = karabo_id.split(\"_\")[0]\n",
diff --git a/notebooks/AGIPD/Chracterize_AGIPD_Gain_PC_NBC.ipynb b/notebooks/AGIPD/Chracterize_AGIPD_Gain_PC_NBC.ipynb
index 14e5d5747..75c1a43da 100644
--- a/notebooks/AGIPD/Chracterize_AGIPD_Gain_PC_NBC.ipynb
+++ b/notebooks/AGIPD/Chracterize_AGIPD_Gain_PC_NBC.ipynb
@@ -58,6 +58,7 @@
     "mem_cells = 0.  # number of memory cells used, use 0 to auto-derive\n",
     "acq_rate = 0. # the detector acquisition rate, use 0 to try to auto-determine\n",
     "gain_setting = 0.1 # gain setting can have value 0 or 1, Default=0.1 for no (None) gain-setting\n",
+    "integration_time = -1 # integration time, negative values for auto-detection.\n",
     "\n",
     "interlaced = False # assume interlaced data format, for data prior to Dec. 2017\n",
     "fit_hook = True # fit a hook function to medium gain slope\n",
@@ -243,7 +244,8 @@
     "            sequences = []\n",
     "print(f\"Gain setting: {gain_setting}\")\n",
     "\n",
-    "integration_time = get_integration_time(control_fname, h5path_ctrl)\n",
+    "if integration_time < 0:\n",
+    "    integration_time = get_integration_time(control_fname, h5path_ctrl)\n",
     "print(f\"Integration time: {integration_time}\")"
    ]
   },
-- 
GitLab