diff --git a/notebooks/Gotthard2/Correction_Gotthard2_NBC.ipynb b/notebooks/Gotthard2/Correction_Gotthard2_NBC.ipynb index c70f1b709914371bd81f5ba3298a798fc0317b67..1ef16054eaed34685a96c5a606911b1d7eff658c 100644 --- a/notebooks/Gotthard2/Correction_Gotthard2_NBC.ipynb +++ b/notebooks/Gotthard2/Correction_Gotthard2_NBC.ipynb @@ -121,6 +121,7 @@ "from cal_tools.step_timing import StepTimer\n", "from cal_tools.tools import (\n", " calcat_creation_time,\n", + " exit_notebook,\n", " map_seq_files,\n", " write_constants_fragment,\n", ")\n", @@ -428,7 +429,7 @@ "outputs": [], "source": [ "corr_data_source = output_source_template.format(karabo_id=karabo_id)\n", - "\n", + "empty_seq = 0\n", "for raw_file in seq_files:\n", "\n", " out_file = out_folder / raw_file.name.replace(\"RAW\", \"CORR\")\n", @@ -437,6 +438,7 @@ " n_trains = len(dc.train_ids)\n", "\n", " if n_trains == 0:\n", + " empty_seq += 1\n", " warning(f\"Skipping correction. No trains to correct for this sequence file: {raw_file}.\")\n", " continue\n", " else:\n", @@ -550,10 +552,9 @@ "outputs": [], "source": [ "if skip_plots:\n", - " print(\"Skipping plots\")\n", - " import sys\n", - "\n", - " sys.exit(0)" + " exit_notebook('Skipping plots due to user request.')\n", + "if empty_seq == len(seq_files):\n", + " exit_notebook('Skipping plots because no data correction have been applied.')" ] }, { diff --git a/notebooks/Gotthard2/Summary_Darks_Gotthard2_NBC.ipynb b/notebooks/Gotthard2/Summary_Darks_Gotthard2_NBC.ipynb index 411aeeca47430d3f9738850b9efe3be71aa96c61..3780f9266e4eb90cd65fc85e31116f3aea8fd465 100644 --- a/notebooks/Gotthard2/Summary_Darks_Gotthard2_NBC.ipynb +++ b/notebooks/Gotthard2/Summary_Darks_Gotthard2_NBC.ipynb @@ -36,9 +36,8 @@ "\n", "# Skip the whole notebook if local_output is false in the preceding notebooks.\n", "if not local_output:\n", - " print('No local constants saved. Skipping summary plots')\n", - " import sys\n", - " sys.exit(0)" + " from cal_tools.tools import exit_notebook\n", + " exit_notebook('No local constants saved. Skipping summary plots')" ] }, { diff --git a/src/cal_tools/tools.py b/src/cal_tools/tools.py index 600a79e4d4a3601ced569ca008ef51b1f9d5b32c..81be77efff25b2b34e54142f764373af14689ca8 100644 --- a/src/cal_tools/tools.py +++ b/src/cal_tools/tools.py @@ -1145,3 +1145,9 @@ class DisplayTables: tabulate(t, tablefmt="latex_raw", headers="firstrow") for t in prepd_tables ) + + +def exit_notebook(message): + import sys + print(message) + sys.exit(0)