diff --git a/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb b/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb index f4c8d91ca93ff4dad003bed49f5d72ae6723d573..a7ed6c2d22f9249adc46fdcba791f8a84adf2ada 100644 --- a/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb +++ b/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb @@ -249,7 +249,7 @@ " gain_mode=gm,\n", " )\n", " \n", - " jf_consts = CalibrationData.from_condition(\n", + " return CalibrationData.from_condition(\n", " conditions,\n", " calibrations=expected_constants,\n", " detector_name=karabo_id,\n", @@ -260,9 +260,6 @@ " ).require_calibrations(\n", " ['Offset10Hz']\n", " )\n", - " display(jf_consts.summary_table())\n", - "\n", - " return jf_consts, jf_consts.aggregator_names\n", "\n", "def prefer_fixed_gain_constants():\n", " \"\"\"JF corrections in burst mode are only supported when\n", @@ -276,19 +273,16 @@ " \"\"\"\n", " from datetime import datetime\n", "\n", - " from cal_tools.calcat_interface import CalCatError\n", - "\n", - " try:\n", - " jungfrau_consts = jungfrau_cal_mdata(gm=1)\n", - " except CalCatError as e: # TODO: update with CalibrationError class\n", + " jungfrau_consts = jungfrau_cal_mdata(gm=1)\n", + " if not jungfrau_consts:\n", " warning(\n", - " \"No fixed gain constants found. \"\n", - " \"Looking for dynamic gain constant. \"\n", - " f\"(CalCatError: {e}.\")\n", + " \"No fixed gain offset constants found. \"\n", + " \"Looking for dynamic gain constant.\"\n", + " )\n", " else:\n", - " return jungfrau_consts\n", + " return jungfrau_consts, jungfrau_consts.aggregator_names\n", "\n", - " # In case of CALCATError exception look for dynamic gain constants\n", + " # Look for dynamic gain constants\n", " jungfrau_consts = jungfrau_cal_mdata(gm=0)\n", "\n", " das_with_offset = []\n", @@ -297,7 +291,7 @@ " time_difference = creation_time - datetime.fromisoformat(offset_creation_time)\n", " if abs(time_difference.days) > 3:\n", " warnings.warn(\n", - " f\"No dynamic gain constant retrieved for {mod} with at least\"\n", + " f\"Dynamic gain offset constant for {mod} has more than\"\n", " \" 3 days time difference with the RAW data creation date.\"\n", " \" Please make sure there are available constants.\")\n", " else:\n", @@ -324,7 +318,10 @@ "if prefer_fixed_gain_constants_flag:\n", " jungfrau_consts, das_to_correct = prefer_fixed_gain_constants()\n", "else:\n", - " jungfrau_consts, das_to_correct = jungfrau_cal_mdata(gain_mode)" + " jungfrau_consts, das_to_correct = jungfrau_cal_mdata(gain_mode)\n", + " das_to_correct = jungfrau_consts.aggregator_names\n", + "\n", + "jungfrau_consts.summary_table()" ] }, { @@ -1191,7 +1188,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.10" + "version": "3.11.8" } }, "nbformat": 4, diff --git a/src/cal_tools/calcat_interface2.py b/src/cal_tools/calcat_interface2.py index d120b472a50f81843cc983de6f2a0b3c8d84ebdb..f22b745f9d56d23a784de63953941f0af4bb92ad 100644 --- a/src/cal_tools/calcat_interface2.py +++ b/src/cal_tools/calcat_interface2.py @@ -692,6 +692,10 @@ class CalibrationData(Mapping): def __len__(self): return len(self.constant_groups) + def __bool__(self): + # Do we have any constants of any type? + return any(bool(grp) for grp in self.constant_groups.values()) + def __contains__(self, item): return item in self.constant_groups @@ -730,7 +734,10 @@ class CalibrationData(Mapping): """Drop any modules missing the specified constant types""" mods = set(self.aggregator_names) for cal_type in calibrations: - mods.intersection_update(self[cal_type].constants) + if cal_type in self: + mods.intersection_update(self[cal_type].constants) + else: + mods = set() # None of this found return self.select_modules(aggregator_names=mods) def select_modules(