From d84c8ae414de57f1ea2cb575eb37de1de0300745 Mon Sep 17 00:00:00 2001
From: Cyril Danilevski <cyril.danilevski@xfel.eu>
Date: Wed, 20 Jan 2021 23:58:51 +0100
Subject: [PATCH] [AGIPD] [Correct Summary] Make use of karabo_id to only load
 data from that detector

---
 .../AGIPD/AGIPD_Correct_and_Verify.ipynb      | 36 +++++++++----------
 1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb b/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb
index 3da8c22de..ef66f4a21 100644
--- a/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb
+++ b/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb
@@ -673,25 +673,23 @@
    "metadata": {},
    "outputs": [],
    "source": [
-    "def get_trains_data(run_folder, source, include, tid=None, path='*/DET/*', modules=16, fillvalue=np.nan):\n",
-    "    \"\"\"\n",
-    "    Load single train for all module\n",
+    "def get_trains_data(run_folder, source, include, detector_id, tid=None, modules=16, fillvalue=np.nan):\n",
+    "    \"\"\"Load single train for all module\n",
     "    \n",
     "    :param run_folder: Path to folder with data\n",
     "    :param source: Data source to be loaded\n",
-    "    :param include: Inset of file name to be considered \n",
+    "    :param include: Inset of file name to be considered\n",
+    "    :param detector_id: The karabo id of the detector to get data for\n",
     "    :param tid: Train Id to be loaded. First train is considered if None is given\n",
     "    :param path: Path to find image data inside h5 file\n",
-    "    \n",
     "    \"\"\"\n",
     "    run_data = RunDirectory(run_folder, include)\n",
-    "    if tid:\n",
-    "        tid, data = run_data.select('*/DET/*', source).train_from_id(tid)\n",
-    "        return tid, stack_detector_data(train=data, data=source, fillvalue=fillvalue, modules=modules)\n",
+    "    if tid is not None:\n",
+    "        tid, data = run_data.select(f'{detector_id}/DET/*', source).train_from_id(tid)\n",
     "    else:\n",
-    "        for tid, data in run_data.select('*/DET/*', source).trains(require_all=True):\n",
-    "            return tid, stack_detector_data(train=data, data=source, fillvalue=fillvalue, modules=modules)\n",
-    "    return None, None"
+    "        tid, data = next(iter(run_data.select(f'{detector_id}/DET/*', source).trains(require_all=True)))\n",
+    "        \n",
+    "    return tid, stack_detector_data(train=data, data=source, fillvalue=fillvalue, modules=modules)"
    ]
   },
   {
@@ -718,14 +716,14 @@
    "outputs": [],
    "source": [
     "include = '*S00000*' if sequences is None else f'*S{sequences[0]:05d}*'\n",
-    "tid, corrected = get_trains_data(f'{out_folder}/', 'image.data', include, modules=nmods)\n",
-    "_, gains = get_trains_data(f'{out_folder}/', 'image.gain', include, tid, modules=nmods)\n",
-    "_, mask = get_trains_data(f'{out_folder}/', 'image.mask', include, tid, modules=nmods)\n",
-    "_, blshift = get_trains_data(f'{out_folder}/', 'image.blShift', include, tid, modules=nmods)\n",
-    "_, cellId = get_trains_data(f'{out_folder}/', 'image.cellId', include, tid, modules=nmods)\n",
-    "_, pulseId = get_trains_data(f'{out_folder}/', 'image.pulseId', include, tid,\n",
-    "                             modules=nmods, fillvalue=0)\n",
-    "_, raw = get_trains_data(f'{in_folder}/r{run:04d}/', 'image.data', include, tid, modules=nmods)"
+    "tid, corrected = get_trains_data(out_folder, 'image.data', include, karabo_id, modules=nmods)\n",
+    "\n",
+    "_, gains = get_trains_data(out_folder, 'image.gain', include, tid, karabo_id, modules=nmods)\n",
+    "_, mask = get_trains_data(out_folder, 'image.mask', include, tid, karabo_id, modules=nmods)\n",
+    "_, blshift = get_trains_data(out_folder, 'image.blShift', include, tid, karabo_id, modules=nmods)\n",
+    "_, cellId = get_trains_data(out_folder, 'image.cellId', include, tid, karabo_id, modules=nmods)\n",
+    "_, pulseId = get_trains_data(out_folder, 'image.pulseId', include, tid, karabo_id, modules=nmods, fillvalue=0)\n",
+    "_, raw = get_trains_data(f'{in_folder}/r{run:04d}/', 'image.data', include, tid, karabo_id, modules=nmods)"
    ]
   },
   {
-- 
GitLab