From d3df783170e93f8b9ef90865ecd89382d47fa895 Mon Sep 17 00:00:00 2001 From: ahmedk <karim.ahmed@xfel.eu> Date: Tue, 23 Jan 2024 15:07:12 +0100 Subject: [PATCH 1/2] show number of available trains and raise ValueError for runs with no trains --- .../Gotthard2/Correction_Gotthard2_NBC.ipynb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/notebooks/Gotthard2/Correction_Gotthard2_NBC.ipynb b/notebooks/Gotthard2/Correction_Gotthard2_NBC.ipynb index 62853ba7d..ed9be026c 100644 --- a/notebooks/Gotthard2/Correction_Gotthard2_NBC.ipynb +++ b/notebooks/Gotthard2/Correction_Gotthard2_NBC.ipynb @@ -248,6 +248,21 @@ " print(f\"Using {corr_receiver} as a receiver name for the corrected data.\")" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "2551b923", + "metadata": {}, + "outputs": [], + "source": [ + "# Check the available trains to correct.\n", + "total_trains = len(RunDirectory(run_folder).select(data_sources, require_all=True).train_ids)\n", + "if total_trains:\n", + " print(f\"Correcting {total_trains}.\")\n", + "else:\n", + " raise ValueError(f\"No trains to correct for run {run}.\")" + ] + }, { "cell_type": "markdown", "id": "8c852392-bb19-4c40-b2ce-3b787538a92d", @@ -413,8 +428,8 @@ " out_file = out_folder / raw_file.name.replace(\"RAW\", \"CORR\")\n", " # Select module INSTRUMENT sources and deselect empty trains.\n", " dc = H5File(raw_file).select(data_sources, require_all=True)\n", - "\n", " n_trains = len(dc.train_ids)\n", + " print(f\"Correcting {n_trains} for {raw_file}.\")\n", "\n", " # Initialize GH2 data and gain arrays to store in corrected files.\n", " if gh2_detector == \"25um\":\n", -- GitLab From b6d8826422f415ff737e6fdd5b159b6592563454 Mon Sep 17 00:00:00 2001 From: ahmedk <karim.ahmed@xfel.eu> Date: Tue, 23 Jan 2024 15:12:16 +0100 Subject: [PATCH 2/2] skip empty sequence files --- notebooks/Gotthard2/Correction_Gotthard2_NBC.ipynb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/notebooks/Gotthard2/Correction_Gotthard2_NBC.ipynb b/notebooks/Gotthard2/Correction_Gotthard2_NBC.ipynb index ed9be026c..bd1940cf3 100644 --- a/notebooks/Gotthard2/Correction_Gotthard2_NBC.ipynb +++ b/notebooks/Gotthard2/Correction_Gotthard2_NBC.ipynb @@ -429,7 +429,12 @@ " # Select module INSTRUMENT sources and deselect empty trains.\n", " dc = H5File(raw_file).select(data_sources, require_all=True)\n", " n_trains = len(dc.train_ids)\n", - " print(f\"Correcting {n_trains} for {raw_file}.\")\n", + " \n", + " if n_trains == 0:\n", + " warning(f\"Skipping correction. No trains to correct for this sequence file: {raw_file}.\")\n", + " continue\n", + " else:\n", + " print(f\"Correcting {n_trains} for {raw_file}.\")\n", "\n", " # Initialize GH2 data and gain arrays to store in corrected files.\n", " if gh2_detector == \"25um\":\n", -- GitLab