From e81c75da2543fc386bcd99f42cb876c299c94eda Mon Sep 17 00:00:00 2001
From: ahmedk <karim.ahmed@xfel.eu>
Date: Thu, 30 Mar 2023 18:54:29 +0200
Subject: [PATCH] small refactors

---
 .../Characterize_Darks_Gotthard2_NBC.ipynb    | 25 +++++++------------
 .../Gotthard2/Correction_Gotthard2_NBC.ipynb  |  1 -
 2 files changed, 9 insertions(+), 17 deletions(-)

diff --git a/notebooks/Gotthard2/Characterize_Darks_Gotthard2_NBC.ipynb b/notebooks/Gotthard2/Characterize_Darks_Gotthard2_NBC.ipynb
index fbd93209f..04398837f 100644
--- a/notebooks/Gotthard2/Characterize_Darks_Gotthard2_NBC.ipynb
+++ b/notebooks/Gotthard2/Characterize_Darks_Gotthard2_NBC.ipynb
@@ -1,6 +1,7 @@
 {
  "cells": [
   {
+   "attachments": {},
    "cell_type": "markdown",
    "id": "49b6577f-96a5-4dd2-bdd9-da661b2c4619",
    "metadata": {},
@@ -9,10 +10,10 @@
     "\n",
     "Author: European XFEL Detector Group, Version: 1.0\n",
     "\n",
-    "The following is a processing for offset, noise, and Badpixels maps using dark images taken with Gotthard2 detector.\n",
+    "The following is a processing for the dark constants (`Offset`, `Noise`, and `BadPixelsDark`) maps using dark images taken with Gotthard2 detector (GH2 50um or 25um).\n",
     "All constants are evaluated per strip, per pulse, and per memory cell. The maps are calculated for each gain stage that is acquired in 3 separate runs.\n",
     "\n",
-    "The three maps (calibration constants) can be injected to the database and stored locally."
+    "The three maps can be injected to the database (`db_output`) and/or stored locally (`local_output`)."
    ]
   },
   {
@@ -33,15 +34,13 @@
     "karabo_da = [\"GH201\"]  # data aggregators\n",
     "receiver_template = \"RECEIVER\"  # receiver template used to read INSTRUMENT keys.\n",
     "control_template = \"CONTROL\"  # control template used to read CONTROL keys.\n",
-    "instrument_source_template = '{}/DET/{}:daqOutput'  # template for source name (filled with karabo_id & receiver_id). e.g. 'SPB_IRDA_JF4M/DET/JNGFR01:daqOutput'  # noqa\n",
     "ctrl_source_template = '{}/DET/{}'  # template for control source name (filled with karabo_id_control)\n",
     "karabo_id_control = \"\"  # Control karabo ID. Set to empty string to use the karabo-id\n",
     "\n",
     "# Parameters for the calibration database.\n",
-    "use_dir_creation_date = True\n",
     "cal_db_interface = \"tcp://max-exfl-cal001:8020\"  # calibration DB interface to use\n",
     "cal_db_timeout = 300000  # timeout on caldb requests\n",
-    "overwrite_creation_time = \"\"  # To overwrite the measured creation_time. Required Format: YYYY-MM-DD HR:MN:SC.00 e.g. \"2022-06-28 13:00:00.00\"\n",
+    "creation_time = \"\"  # To overwrite the measured creation_time. Required Format: YYYY-MM-DD HR:MN:SC e.g. \"2022-06-28 13:00:00\"\n",
     "db_output = False  # Output constants to the calibration database\n",
     "local_output = True  # Output constants locally\n",
     "\n",
@@ -68,7 +67,6 @@
    "metadata": {},
    "outputs": [],
    "source": [
-    "import datetime\n",
     "import numpy as np\n",
     "import matplotlib.pyplot as plt\n",
     "import pasha as psh\n",
@@ -80,7 +78,7 @@
     "from cal_tools.gotthard2 import gotthard2algs, gotthard2lib\n",
     "from cal_tools.step_timing import StepTimer\n",
     "from cal_tools.tools import (\n",
-    "    get_dir_creation_date,\n",
+    "    calcat_creation_time,\n",
     "    get_constant_from_db_and_time,\n",
     "    get_pdu_from_db,\n",
     "    get_report,\n",
@@ -110,14 +108,9 @@
     "# Read report path to associate it later with injected constants.\n",
     "report = get_report(out_folder)\n",
     "\n",
-    "creation_time = None\n",
-    "if overwrite_creation_time:\n",
-    "    creation_time = datetime.datetime.strptime(\n",
-    "        overwrite_creation_time, \"%Y-%m-%d %H:%M:%S.%f\"\n",
-    "    )\n",
-    "elif use_dir_creation_date:\n",
-    "    creation_time = get_dir_creation_date(in_folder, run_high)\n",
-    "    print(f\"Using {creation_time.isoformat()} as creation time\")\n",
+    "# Run's creation time:\n",
+    "creation_time = calcat_creation_time(in_folder, run_high, creation_time)\n",
+    "print(f\"Creation time: {creation_time}\")\n",
     "\n",
     "\n",
     "if not karabo_id_control:\n",
@@ -228,7 +221,7 @@
     "    Print number of trains to process and number of empty trains.\n",
     "    Raise ValueError if specified trains are less than min_trains.\n",
     "    \"\"\"\n",
-    "    # Specifies total number of trains to proccess.\n",
+    "    # Specifies total number of trains to process.\n",
     "    n_trains = img_key_data.shape[0]\n",
     "    all_trains = len(img_key_data.train_ids)\n",
     "    print(\n",
diff --git a/notebooks/Gotthard2/Correction_Gotthard2_NBC.ipynb b/notebooks/Gotthard2/Correction_Gotthard2_NBC.ipynb
index 659cc6220..f911c682e 100644
--- a/notebooks/Gotthard2/Correction_Gotthard2_NBC.ipynb
+++ b/notebooks/Gotthard2/Correction_Gotthard2_NBC.ipynb
@@ -57,7 +57,6 @@
     "karabo_da = [\"GH201\"]  # data aggregators\n",
     "receiver_template = \"RECEIVER\"  # receiver template used to read INSTRUMENT keys.\n",
     "control_template = \"CONTROL\"  # control template used to read CONTROL keys.\n",
-    "instrument_source_template = \"{}/DET/{}:daqOutput\"  # template for source name (filled with karabo_id & receiver_id). e.g. 'SPB_IRDA_JF4M/DET/JNGFR01:daqOutput'\n",
     "ctrl_source_template = \"{}/DET/{}\"  # template for control source name (filled with karabo_id_control)\n",
     "karabo_id_control = \"\"  # Control karabo ID. Set to empty string to use the karabo-id\n",
     "\n",
-- 
GitLab