diff --git a/notebooks/Gotthard2/Correction_Gotthard2_NBC.ipynb b/notebooks/Gotthard2/Correction_Gotthard2_NBC.ipynb index c70f1b709914371bd81f5ba3298a798fc0317b67..b2276642ab3ce770c31fd958846d63d5e91bdace 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 as configured.')\n", + "if empty_seq == len(seq_files):\n", + " exit_notebook(f\"All sequence files contain no data for correction.\")" ] }, { 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/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb b/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb index c70815791b0c5c9187f8a2694bef9e309772b494..fabc733cea1b8ae9870228ce2f805201f9bebd9a 100644 --- a/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb +++ b/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb @@ -101,6 +101,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", @@ -738,8 +739,7 @@ "\n", " step_timer.done_step(f'Saving data time.')\n", "if empty_seq == sum([len(i) for i in mapped_files.values()]):\n", - " warning(\"No valid trains for RAW data to correct.\")\n", - " sys.exit(0)" + " exit_notebook(f\"All sequence files contain no data for correction.\")" ] }, { @@ -766,8 +766,7 @@ "outputs": [], "source": [ "if skip_plots:\n", - " print('Skipping plots')\n", - " sys.exit(0)" + " exit_notebook('Skipping plots as configured.')" ] }, { diff --git a/notebooks/ePix100/Correction_ePix100_NBC.ipynb b/notebooks/ePix100/Correction_ePix100_NBC.ipynb index 29b6abd174f8182c436a2ef687ea3bb426c23418..fc7ce25391655f497b1e0411ad03c875bc8d9d3e 100644 --- a/notebooks/ePix100/Correction_ePix100_NBC.ipynb +++ b/notebooks/ePix100/Correction_ePix100_NBC.ipynb @@ -103,6 +103,7 @@ "from cal_tools.files import DataFile\n", "from cal_tools.tools import (\n", " calcat_creation_time,\n", + " exit_notebook,\n", " write_constants_fragment,\n", ")\n", "from cal_tools.step_timing import StepTimer\n", @@ -656,8 +657,7 @@ "\n", " step_timer.done_step('Storing data.')\n", "if empty_seq == len(seq_files):\n", - " warning(\"No valid trains for RAW data to correct.\")\n", - " exit(0)" + " exit_notebook(f\"All sequence files contain no data for correction.\")" ] }, { diff --git a/notebooks/pnCCD/Correct_pnCCD_NBC.ipynb b/notebooks/pnCCD/Correct_pnCCD_NBC.ipynb index 124216bbf643a14a7e2de4f9f8674d6d60ba1905..9ffabbb4b1593327ad6bdac026f69ac454802431 100644 --- a/notebooks/pnCCD/Correct_pnCCD_NBC.ipynb +++ b/notebooks/pnCCD/Correct_pnCCD_NBC.ipynb @@ -117,6 +117,7 @@ "\n", "from cal_tools.tools import (\n", " calcat_creation_time,\n", + " exit_notebook,\n", " write_constants_fragment,\n", ")\n", "from cal_tools.step_timing import StepTimer" @@ -784,8 +785,7 @@ " step_timer.done_step(f'Storing data.')\n", "# Exit and raise warning if there are no data to correct for all sequences.\n", "if empty_seq == len(seq_files):\n", - " warning(\"No valid trains for RAW data to correct.\")\n", - " sys.exit(0)" + " exit_notebook(f\"All sequence files contain no data for correction.\")" ] }, { 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)