From 5accaf0da49d82c6175aac401d22e37aa98e47b8 Mon Sep 17 00:00:00 2001
From: David Hammer <dhammer@mailbox.org>
Date: Mon, 8 Mar 2021 17:36:18 +0100
Subject: [PATCH] Only define the condition once

---
 .../Characterize_AGIPD_Gain_Darks_NBC.ipynb   | 29 ++++++++++---------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb b/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb
index 2f6e45c84..8ea3880e6 100644
--- a/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb
+++ b/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb
@@ -538,6 +538,21 @@
     "    }"
    ]
   },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# set the operating condition\n",
+    "# note: iCalibrationDB only adds gain_mode if it is truthy, so we don't need to handle None\n",
+    "condition = Conditions.Dark.AGIPD(memory_cells=max_cells,\n",
+    "                                  bias_voltage=bias_voltage,\n",
+    "                                  acquisition_rate=acq_rate,\n",
+    "                                  gain_setting=gain_setting,\n",
+    "                                  gain_mode=(True if fixed_gain_mode else None))"
+   ]
+  },
   {
    "cell_type": "code",
    "execution_count": null,
@@ -554,7 +569,6 @@
     "detinst = getattr(Detectors, dinstance)\n",
     "\n",
     "print('Retrieve pre-existing constants for comparison.')\n",
-    "\n",
     "for qm in res:\n",
     "    qm_db = qm_dict[qm]\n",
     "    karabo_da = qm_db[\"karabo_da\"]\n",
@@ -562,13 +576,6 @@
     "        dconst = getattr(Constants.AGIPD, const)()\n",
     "        dconst.data = res[qm][const]\n",
     "\n",
-    "        # Setting conditions\n",
-    "        condition = Conditions.Dark.AGIPD(memory_cells=max_cells,\n",
-    "                                          bias_voltage=bias_voltage,\n",
-    "                                          acquisition_rate=acq_rate,\n",
-    "                                          gain_setting=gain_setting,\n",
-    "                                          gain_mode=(True if fixed_gain_mode else None))\n",
-    "\n",
     "        # This should be used in case of running notebook\n",
     "        # by a different method other than myMDC which already\n",
     "        # sends CalCat info.\n",
@@ -612,12 +619,6 @@
     "        dconst = getattr(Constants.AGIPD, const)()\n",
     "        dconst.data = res[qm][const]\n",
     "\n",
-    "        # set the operating condition\n",
-    "        condition = Conditions.Dark.AGIPD(memory_cells=max_cells,\n",
-    "                                          bias_voltage=bias_voltage,\n",
-    "                                          acquisition_rate=acq_rate,\n",
-    "                                          gain_setting=gain_setting,\n",
-    "                                          gain_mode=(True if fixed_gain_mode else None))\n",
     "        if db_output:\n",
     "            md = send_to_db(db_module, karabo_id, dconst, condition, file_loc,\n",
     "                            report, cal_db_interface, creation_time=creation_time,\n",
-- 
GitLab