diff --git a/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb b/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb index 8eeadf72ae9b401bd586be629712b398779d2ec5..7b15087996b138a2784b8a8646455fef522be562 100644 --- a/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb +++ b/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb @@ -205,7 +205,9 @@ "if relative_gain:\n", " constant_names += [\"BadPixelsFF10Hz\", \"RelativeGain10Hz\"]\n", "\n", - "jf_metadata = jf_cal.metadata(calibrations=constant_names)" + "jf_metadata = jf_cal.metadata(calibrations=constant_names)\n", + "# Display retrieved calibration constants timestamps\n", + "jf_cal.display_markdown_retrieved_constants(metadata=jf_metadata)" ] }, { diff --git a/notebooks/ePix100/Correction_ePix100_NBC.ipynb b/notebooks/ePix100/Correction_ePix100_NBC.ipynb index 57c48072ca532154fff629183a4a066360ff753b..5158373979d84e14ac643d0c5f61dbd6ccaab81c 100644 --- a/notebooks/ePix100/Correction_ePix100_NBC.ipynb +++ b/notebooks/ePix100/Correction_ePix100_NBC.ipynb @@ -280,15 +280,8 @@ " client=rest_cfg.calibration_client(),\n", ")\n", "const_metadata = epix_cal.metadata(calibrations=constant_names)\n", - "\n", - "mod_to_pdu = epix_cal.mod_to_pdu\n", - "ccvs_url = \"https://in.xfel.eu/calibration/calibration_constant_versions/\"\n", - "for mod, mod_md in const_metadata.items():\n", - " display(Markdown(f\"{mod}({mod_to_pdu[mod]}):\"))\n", - " for cname, c_mdata in mod_md.items():\n", - " display(Markdown(\n", - " f\"- [{cname}]({ccvs_url}/{c_mdata['ccv_id']}): {c_mdata['begin_validity_at']}\"))\n", - "\n", + "# Display retrieved calibration constants timestamps\n", + "epix_cal.display_markdown_retrieved_constants(metadata=const_metadata)\n", "# Load the constant data from files\n", "const_data = epix_cal.ndarray_map(metadata=const_metadata)[karabo_da]\n", "\n", diff --git a/notebooks/pnCCD/Correct_pnCCD_NBC.ipynb b/notebooks/pnCCD/Correct_pnCCD_NBC.ipynb index 557aa099ef290f4efb553b4d162e63c174fc1121..7cefbcab7be90ba22f1323f4d7dd14153496670d 100644 --- a/notebooks/pnCCD/Correct_pnCCD_NBC.ipynb +++ b/notebooks/pnCCD/Correct_pnCCD_NBC.ipynb @@ -342,13 +342,8 @@ " \"Relative gain correction is disabled.\")\n", " corr_bools['relgain'] = False\n", "\n", - "mod_to_pdu = pnccd_cal.mod_to_pdu\n", - "ccvs_url = \"https://in.xfel.eu/calibration/calibration_constant_versions/\"\n", - "for mod, mod_md in pnccd_metadata.items():\n", - " display(Markdown(f\"{mod}({mod_to_pdu[mod]}):\"))\n", - " for cname, c_mdata in mod_md.items():\n", - " display(Markdown(\n", - " f\"- [{cname}]({ccvs_url}/{c_mdata['ccv_id']}): {c_mdata['begin_validity_at']}\"))\n", + "# Display retrieved calibration constants timestamps\n", + "pnccd_cal.display_markdown_retrieved_constants(metadata=pnccd_metadata)\n", "\n", "metadata = pnccd_metadata[karabo_da]\n", "\n", diff --git a/src/cal_tools/calcat_interface.py b/src/cal_tools/calcat_interface.py index bca8e5a3f08f75050537aac0d89c8e165bf373c4..03f3d1437d28a423ee447f370550d5c0df70e9b1 100644 --- a/src/cal_tools/calcat_interface.py +++ b/src/cal_tools/calcat_interface.py @@ -692,6 +692,72 @@ class CalibrationData: return self.load_constants_from_metadata(metadata) + def display_markdown_retrieved_constants( + self, + metadata=None, + ccvs_url="https://in.xfel.eu/calibration/calibration_constant_versions/" # noqa + ): + """ + Display markdown table with reference links for the + retrieved constants. Tables are split into groups of a + maximum of 4 modules. + + Args: + metadata (dict, optional): Metadata for calibration constants. + Defaults to None. + ccvs_url (str, optional): URL for calibration constant versions. + Defaults to + "https://in.xfel.eu/calibration/calibration_constant_versions/". + """ + from IPython.display import Markdown, display + from tabulate import tabulate + + if metadata is None: + metadata = self.metadata() + + calibrations = set() + # Get all calibrations available in the metadata for all modules. + for c in list(metadata.values()): + calibrations |= c.keys() + + cal_groups = [ + list(calibrations)[x:x+4] for x in range(0, len(calibrations), 4)] + + # Loop over groups of calibrations. + for cal_group in cal_groups: + table = [["Modules"] + cal_group] + + # Loop over calibrations and modules to form the next rows. + for mod in list(self.mod_to_pdu): + mod_consts = [] + + for cname in cal_group: + c_mdata = metadata[mod].get(cname) + # A calibration that is available in given metadata. + if c_mdata is not None: + # Have the creation time a reference + # link to the CCV on CALCAT. + c_time = datetime.fromisoformat( + c_mdata["begin_validity_at"]).strftime( + "%Y-%m-%d %H:%M") + mod_consts.append( + f"[{c_time}]({ccvs_url}/{c_mdata['ccv_id']})") + else: + # Constant is not available for this module. + mod_consts.append("___") + + table.append([mod] + mod_consts) + + display( + Markdown( + tabulate( + table, + tablefmt="pipe", + headers="firstrow", + ) + ) + ) + def _build_condition(self, parameters): cond = dict()