diff --git a/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb b/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb index 3cff265cbb2f1314c335a23ffdad9144d947b3c8..a5f9a894ab464fb0a81b32662591578d23e299b0 100644 --- a/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb +++ b/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb @@ -76,6 +76,7 @@ "import sys\n", "import warnings\n", "from functools import partial\n", + "from logging import warn\n", "from pathlib import Path\n", "\n", "import h5py\n", @@ -481,6 +482,7 @@ "outputs": [], "source": [ "# Loop over modules\n", + "empty_seq = 0\n", "for local_karabo_da, mapped_files_module in mapped_files.items():\n", " instrument_src_kda = instrument_src.format(int(local_karabo_da[-2:]))\n", "\n", @@ -502,8 +504,9 @@ " # Raise a WARNING if this sequence has no trains to correct.\n", " # Otherwise, print number of trains with no data.\n", " if corr_ntrains == 0:\n", - " print(f\"\\t- WARNING: No trains to correct for {sequence_file.name}: \"\n", - " f\"Skipping the processing of this file.\")\n", + " warn(f\"No trains to correct for {sequence_file.name}: \"\n", + " \"Skipping the processing of this file.\")\n", + " empty_seq += 1\n", " continue\n", " elif len(all_train_ids) != corr_ntrains:\n", " print(f\"{sequence_file.name} has {len(seq_dc_adc.train_ids) - corr_ntrains} \"\n", @@ -601,7 +604,9 @@ " # Create METDATA datasets\n", " outp_file.create_metadata(like=seq_dc)\n", "\n", - " step_timer.done_step(f'Saving data time.')" + " step_timer.done_step(f'Saving data time.')\n", + "if empty_seq == sum([len(i) for i in mapped_files.values()]):\n", + " raise ValueError(\"No valid trains for RAW data to correct.\")" ] }, { diff --git a/src/cal_tools/step_timing.py b/src/cal_tools/step_timing.py index 790021f0568f5e20d6111904f01c15847cb8fe0b..e95362444b7b315c758d32eb8b2bb8621b3c56ab 100644 --- a/src/cal_tools/step_timing.py +++ b/src/cal_tools/step_timing.py @@ -27,7 +27,8 @@ class StepTimer: def timespan(self): """Wall time from 1st call to start() to last start() or done_step()""" - return self.t_latest - self.t0 + if self.t_latest is not None and self.t0 is not None: + return self.t_latest - self.t0 def print_summary(self): """Show mean & std for each step"""