From da5ead8dacb556bc8b5a74603e2a7b0adffc5680 Mon Sep 17 00:00:00 2001
From: Cyril Danilevski <cydanil@gmail.com>
Date: Thu, 6 May 2021 19:04:45 +0200
Subject: [PATCH] Flake and isort LPD Constants Injection notebook

---
 ...t_calibration_constants_from_h5files.ipynb | 45 +++++++++----------
 1 file changed, 20 insertions(+), 25 deletions(-)

diff --git a/notebooks/LPD/Inject_calibration_constants_from_h5files.ipynb b/notebooks/LPD/Inject_calibration_constants_from_h5files.ipynb
index cc8d2203b..463bf868c 100644
--- a/notebooks/LPD/Inject_calibration_constants_from_h5files.ipynb
+++ b/notebooks/LPD/Inject_calibration_constants_from_h5files.ipynb
@@ -21,8 +21,8 @@
     "constant_names = [\"\"]  # calibration constant name, required.\n",
     "in_folder = \"\"  # calibration constants folder, required.\n",
     "out_folder = \"\"  # output folder to store report path in case the notebook is executed by CLI, required.\n",
-    "proposal = \"\" # Add proposal number to be sent to the database as a part of Raw data location.\n",
-    "runs = [\"\"] # Add list of runs to be sent to the database as a part of Raw data location.\n",
+    "proposal = \"\"  # Add proposal number to be sent to the database as a part of Raw data location.\n",
+    "runs = [\"\"]  # Add list of runs to be sent to the database as a part of Raw data location.\n",
     "\n",
     "# detector parameters:\n",
     "karabo_id = \"FXE_DET_LPD1M-1\"  # detector identifier.\n",
@@ -35,8 +35,8 @@
     "memory_cells = 512  # Number of memory cells. Used for constant conditions.\n",
     "bias_voltage = 250  # bias voltage value. Used for constant conditions.\n",
     "capacitor = 5  # capacitor value. Used for constant conditions.\n",
-    "category = 0 # calibration constant source category, 0 for European XFEl and 1 for RAL. Used for constant conditions.\n",
-    "photon_energy = 9.2 # calibration constant photon energy. Used for constant conditions.\n",
+    "category = 0  # calibration constant source category, 0 for European XFEl and 1 for RAL. Used for constant conditions.\n",
+    "photon_energy = 9.2  # calibration constant photon energy. Used for constant conditions.\n",
     "creation_time = '2020-01-20T14:12:06'  # creation time for the injected constants. required format '2019-01-20T14:12:06'"
    ]
   },
@@ -46,23 +46,14 @@
    "metadata": {},
    "outputs": [],
    "source": [
-    "import multiprocessing\n",
-    "from datetime import datetime\n",
-    "from pathlib import Path\n",
-    "from typing import List, Tuple\n",
-    "\n",
-    "import h5py\n",
-    "\n",
-    "from iCalibrationDB import (\n",
-    "    Constants,\n",
-    "    Conditions,\n",
-    ")\n",
-    "from cal_tools.tools import (\n",
-    "    get_from_db,\n",
-    "    get_pdu_from_db,\n",
-    "    get_report,\n",
-    "    send_to_db,\n",
-    ")"
+    "import multiprocessing  # noqa\n",
+    "from datetime import datetime  # noqa\n",
+    "from pathlib import Path  # noqa\n",
+    "from typing import List, Tuple  # noqa\n",
+    "\n",
+    "import h5py # noqa \n",
+    "from cal_tools.tools import get_pdu_from_db, get_report, send_to_db  # noqa\n",
+    "from iCalibrationDB import Conditions, Constants  # noqa"
    ]
   },
   {
@@ -76,7 +67,7 @@
     "if karabo_da[0].lower() == \"all\":\n",
     "    karabo_da = [f\"LPD{i:02d}\" for i in range(16)]\n",
     "\n",
-    "# if proposal or runs are given assign file_loc \n",
+    "# if proposal or runs are given assign file_loc\n",
     "# for calibration constant versions metadata.\n",
     "file_loc = \"\"\n",
     "if proposal:\n",
@@ -102,7 +93,7 @@
     "    creation_time: str,\n",
     "    constant_names: List[str],\n",
     ") -> Tuple[str, datetime]:\n",
-    "    \n",
+    "\n",
     "    # Validate input parameters:\n",
     "    if not (in_folder):\n",
     "        raise ValueError(\n",
@@ -120,7 +111,10 @@
     "    try:\n",
     "        creation_time = datetime.strptime(creation_time, '%Y-%m-%dT%H:%M:%S')\n",
     "    except ValueError:\n",
-    "        raise ValueError(\"Incorrect data format, should be YYYY-MM-DDTHH:MM:SS i.e. 2019-01-20T14:12:06\")\n",
+    "        raise ValueError(\n",
+    "            \"Incorrect data format, \"\n",
+    "            \"should be YYYY-MM-DDTHH:MM:SS i.e. 2019-01-20T14:12:06\"\n",
+    "        )\n",
     "\n",
     "    for constant in constant_names:\n",
     "        if not hasattr(Constants.LPD, constant):\n",
@@ -187,9 +181,10 @@
     ")\n",
     "\n",
     "# create a report path for calibration constant versions metadata.\n",
+    "report_name = f\"No_report/LPD_{datetime.now().strftime('%Y-%m-%dT%H:%M:%S')}\"\n",
     "report_path = get_report(\n",
     "    out_folder=in_folder,\n",
-    "    default_path=f\"No_report/LPD_{datetime.now().strftime('%Y-%m-%dT%H:%M:%S')}\"\n",
+    "    default_path=report_name\n",
     ")\n",
     "\n",
     "# Calibration constants condition object.\n",
-- 
GitLab