From 330a6ff86f438fcd439b3a79bd81bb62861cf9b9 Mon Sep 17 00:00:00 2001
From: Philipp Schmidt <philipp.schmidt@xfel.eu>
Date: Mon, 16 May 2022 12:06:04 +0200
Subject: [PATCH] More consistent naming and comments in LPD correct

---
 notebooks/LPD/LPD_Correct_Fast.ipynb | 33 ++++++++++++++--------------
 1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/notebooks/LPD/LPD_Correct_Fast.ipynb b/notebooks/LPD/LPD_Correct_Fast.ipynb
index 12aab1e7d..b27a64e2b 100644
--- a/notebooks/LPD/LPD_Correct_Fast.ipynb
+++ b/notebooks/LPD/LPD_Correct_Fast.ipynb
@@ -39,10 +39,10 @@
     "cal_db_root = '/gpfs/exfel/d/cal/caldb_store'\n",
     "\n",
     "# Operating conditions\n",
-    "mem_cells = 512  # Memory cells.\n",
+    "mem_cells = 512  # Memory cells, LPD constants are always taken with 512 cells.\n",
     "bias_voltage = 250.0  # Detector bias voltage.\n",
     "capacitor = '5pF'  # Capacitor setting: 5pF or 50pF\n",
-    "photon_energy = 9.2  # Photon energy in kEv.\n",
+    "photon_energy = 9.2  # Photon energy in keV.\n",
     "category = 0  # Whom to blame.\n",
     "\n",
     "# Correction parameters\n",
@@ -388,19 +388,19 @@
     "    \n",
     "    # Load raw data for this file.\n",
     "    start = perf_counter()\n",
-    "    in_data = inp_source['image.data'].ndarray().squeeze()\n",
+    "    in_raw = inp_source['image.data'].ndarray().squeeze()\n",
     "    in_cell = inp_source['image.cellId'].ndarray().squeeze()\n",
     "    in_pulse = inp_source['image.pulseId'].ndarray().squeeze()\n",
     "    read_time = perf_counter() - start\n",
     "    \n",
     "    # Allocate output arrays.\n",
-    "    out_pixels = np.zeros((in_data.shape[0], 256, 256), dtype=np.float32)\n",
-    "    out_gain = np.zeros((in_data.shape[0], 256, 256), dtype=np.uint8)\n",
-    "    out_mask = np.zeros((in_data.shape[0], 256, 256), dtype=np.uint32)\n",
+    "    out_data = np.zeros((in_raw.shape[0], 256, 256), dtype=np.float32)\n",
+    "    out_gain = np.zeros((in_raw.shape[0], 256, 256), dtype=np.uint8)\n",
+    "    out_mask = np.zeros((in_raw.shape[0], 256, 256), dtype=np.uint32)\n",
     "            \n",
     "    start = perf_counter()\n",
-    "    correct_lpd_frames(in_data, in_cell,\n",
-    "                       out_pixels, out_gain, out_mask,\n",
+    "    correct_lpd_frames(in_raw, in_cell,\n",
+    "                       out_data, out_gain, out_mask,\n",
     "                       ccv_offsets[aggregator], ccv_gains[aggregator], ccv_masks[aggregator],\n",
     "                       num_threads=num_threads_per_worker)\n",
     "    correct_time = perf_counter() - start\n",
@@ -413,18 +413,17 @@
     "        sel_trains = np.isin(fa.train_ids, dc.train_ids)\n",
     "        \n",
     "        outp_source_name = output_source.format(karabo_id=karabo_id, module_index=module_index)\n",
-    "        \n",
-    "        DataFile.instrument_source_pattern = re.compile(r'^[\\w\\/-]+:\\w+$')\n",
+    "\n",
     "        with DataFile(outp_path, 'w') as outp_file:            \n",
     "            outp_file.create_index(\n",
     "                train_ids=dc.train_ids,\n",
-    "                timestamp=fa.file['INDEX/timestamp'][sel_trains],\n",
-    "                flag=fa.validity_flag[sel_trains])\n",
+    "                timestamps=fa.file['INDEX/timestamp'][sel_trains],\n",
+    "                flags=fa.validity_flag[sel_trains])\n",
     "            \n",
     "            outp_source = outp_file.create_instrument_source(outp_source_name)\n",
     "            \n",
     "            outp_source.create_index(image=image_counts)\n",
-    "            outp_source.create_key('image.data', data=out_pixels)\n",
+    "            outp_source.create_key('image.data', data=out_data)\n",
     "            outp_source.create_key('image.cellId', data=in_cell)\n",
     "            outp_source.create_key('image.pulseId', data=in_pulse)\n",
     "            write_compressed_frames(\n",
@@ -436,16 +435,16 @@
     "    write_time = perf_counter() - start\n",
     "    \n",
     "    total_time = open_time + read_time + correct_time + write_time\n",
-    "    frame_rate = in_data.shape[0] / total_time\n",
+    "    frame_rate = in_raw.shape[0] / total_time\n",
     "    \n",
     "    print('{}\\t{}\\t{:.3f}\\t{:.3f}\\t{:.3f}\\t{:.3f}\\t{:.3f}\\t{}\\t{:.1f}'.format(\n",
     "        wid, aggregator, open_time, read_time, correct_time, write_time, total_time,\n",
-    "        in_data.shape[0], frame_rate))\n",
+    "        in_raw.shape[0], frame_rate))\n",
     "    \n",
-    "    in_data = None\n",
+    "    in_raw = None\n",
     "    in_cell = None\n",
     "    in_pulse = None\n",
-    "    out_pixels = None\n",
+    "    out_data = None\n",
     "    out_gain = None\n",
     "    out_mask = None\n",
     "    gc.collect()\n",
-- 
GitLab