From 275f9eaf9cbca5abbd98523750623a481d9b0903 Mon Sep 17 00:00:00 2001
From: ahmedk <karim.ahmed@xfel.eu>
Date: Wed, 4 Oct 2023 10:55:21 +0200
Subject: [PATCH] decide on splitting the change in two and have the current
 branch only for introducing rel_gain_mode and next branch for replacing
 rel_gain with rel_gain_mode to have one parameter only

---
 notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb      | 13 +++++++++++--
 .../AGIPD_Correct_and_Verify_Summary_NBC.ipynb      |  4 ++--
 webservice/update_config.py                         |  2 +-
 3 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb b/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb
index eaed1327a..f4561c410 100644
--- a/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb
+++ b/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb
@@ -66,7 +66,9 @@
     "\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",
-    "rel_gain = \"off\"  # Select relative gain correction. Choices [`PC`, `CS`, `off`]. (`PC`: Pulse Capacitor, `CS`: Current Source, `off`: Disable relative gain correction). Default: off.\n",
+    "# TODO: Remove this boolean parameter an replace rel_gain_mode with it.\n",
+    "rel_gain = False \n",
+    "rel_gain_mode = \"off\"  # Select relative gain correction. Choices [`PC`, `CS`, `off`]. (`PC`: Pulse Capacitor, `CS`: Current Source, `off`: Disable relative gain correction). Default: off.\n",
     "xray_gain = False # do relative gain correction based on xray data\n",
     "blc_noise = False # if set, baseline correction via noise peak location is attempted\n",
     "blc_stripes = False # if set, baseline corrected via stripes\n",
@@ -213,6 +215,13 @@
     "# Here the hierarchy and dependability for correction booleans are defined\n",
     "corr_bools = {}\n",
     "\n",
+    "# TODO: Remove this part after replacing rel_gain with rel_gain_mode\n",
+    "if rel_gain_mode == 'off':\n",
+    "    if rel_gain:\n",
+    "        rel_gain = 'pc'\n",
+    "else:\n",
+    "    rel_gain == rel_gain_mode\n",
+    "\n",
     "# offset is at the bottom of AGIPD correction pyramid.\n",
     "corr_bools[\"only_offset\"] = only_offset\n",
     "rel_gain = rel_gain.lower()\n",
@@ -220,7 +229,7 @@
     "# Dont apply any corrections if only_offset is requested\n",
     "if not only_offset:\n",
     "    corr_bools[\"adjust_mg_baseline\"] = adjust_mg_baseline\n",
-    "    corr_bools[\"rel_gain\"] = rel_gain  # This is not a boolean anymore.\n",
+    "    corr_bools[\"rel_gain\"] = rel_gain  # This is not a boolean.\n",
     "    corr_bools[\"xray_corr\"] = xray_gain\n",
     "    corr_bools[\"blc_noise\"] = blc_noise\n",
     "    corr_bools[\"blc_stripes\"] = blc_stripes\n",
diff --git a/notebooks/AGIPD/AGIPD_Correct_and_Verify_Summary_NBC.ipynb b/notebooks/AGIPD/AGIPD_Correct_and_Verify_Summary_NBC.ipynb
index 7c3aba0df..17a162ea0 100644
--- a/notebooks/AGIPD/AGIPD_Correct_and_Verify_Summary_NBC.ipynb
+++ b/notebooks/AGIPD/AGIPD_Correct_and_Verify_Summary_NBC.ipynb
@@ -19,7 +19,7 @@
     "karabo_id = \"SPB_DET_AGIPD1M-1\" # karabo karabo_id\n",
     "modules = [-1]\n",
     "karabo_da = ['-1']  # a list of data aggregators names, Default [-1] for selecting all data aggregators\n",
-    "rel_gain = \"off\"  # Select relative gain correction. Choices [`PC`, `CS`, `off`]. (`PC`: Pulse Capacitor, `CS`: Current Source, `off`: Disable relative gain correction). Default: off."
+    "rel_gain_mode = \"off\"  # Select relative gain correction. Choices [`PC`, `CS`, `off`]. (`PC`: Pulse Capacitor, `CS`: Current Source, `off`: Disable relative gain correction). Default: off."
    ]
   },
   {
@@ -106,7 +106,7 @@
     "    display(Latex(tabulate.tabulate(table,\n",
     "                 tablefmt=\"latex\",\n",
     "                 headers=[\"Timestamps\", \"Modules and sequences\"])))\n",
-    "rel_gain_alias = \"CS\" if rel_gain.lower() == \"cs\" else \"PC\"\n",
+    "rel_gain_alias = \"CS\" if rel_gain_mode.lower() == \"cs\" else \"PC\"  # 'off' or 'pc'\n",
     "for const in ['Offset', f'Slopes{rel_gain_alias}', 'SlopesFF']:\n",
     "    print_const_table(const)"
    ]
diff --git a/webservice/update_config.py b/webservice/update_config.py
index 92863dac8..f1ae56d36 100755
--- a/webservice/update_config.py
+++ b/webservice/update_config.py
@@ -15,7 +15,7 @@ AGIPD_CONFIGURATIONS = {
     {
         "common-mode": {'type': bool},
         "force-hg-if-below": {'type': int},
-        "rel-gain": {'type': str},
+        "rel-gain": {'type': bool},
         "xray-gain": {'type': bool},
         "blc-noise": {'type': bool},
         "blc-set-min": {'type': bool},
-- 
GitLab