diff --git a/notebooks/LPD/LPD_Correct_Fast.ipynb b/notebooks/LPD/LPD_Correct_Fast.ipynb index b2fb1ef45448c52da9096bb416556f96f5c35e5a..04d35400aafeaa9197d79ff6a11439d697c84df0 100644 --- a/notebooks/LPD/LPD_Correct_Fast.ipynb +++ b/notebooks/LPD/LPD_Correct_Fast.ipynb @@ -109,9 +109,8 @@ "from cal_tools.lpdalgs import correct_lpd_frames\n", "from cal_tools.lpdlib import get_mem_cell_pattern, make_cell_order_condition\n", "from cal_tools.tools import (\n", - " CalibrationMetadata,\n", " calcat_creation_time,\n", - " write_constants_fragment,\n", + " write_constants_fragment_extracal,\n", ")\n", "from cal_tools.files import DataFile" ] @@ -238,6 +237,7 @@ "cell_type": "code", "execution_count": null, "metadata": { + "scrolled": false, "tags": [] }, "outputs": [], @@ -312,45 +312,6 @@ "data_to_process = [(mod, in_f, out_f) for mod, in_f, out_f in data_to_process if mod in karabo_da]" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def write_constants_fragment(\n", - " out_folder: Path,\n", - " calib_data: CalibrationData,\n", - " caldb_root: Path,\n", - "):\n", - " \"\"\"Record calibration constants metadata to a fragment file.\n", - "\n", - " Args:\n", - " out_folder (Path): The output folder to store the fragment file.\n", - " det_metadata (dict): A dictionary with the desired detector metadata.\n", - " {karabo_da: {constant_name: metadata}}\n", - " caldb_root (Path): The calibration database root path for constant files.\n", - " \"\"\"\n", - " retrieved_consts = {}\n", - " for kda, pdu in zip(calib_data.aggregator_names, calib_data.pdu_names):\n", - " retrieved_consts[kda] = {\n", - " \"physical-name\": pdu,\n", - " \"constants\": {},\n", - " }\n", - " \n", - " for cname, multimodconst in calib_data.items():\n", - " for kda in multimodconst.aggregator_names:\n", - " const = multimodconst[kda]\n", - " retrieved_consts[kda][\"constants\"][cname] = {\n", - " \"path\": str(caldb_root / const.path),\n", - " \"dataset\": const.dataset,\n", - " \"creation-time\": const.metadata(\"begin_validity_at\"),\n", - " \"ccv_id\": const.ccv_id\n", - " }\n", - "\n", - " CalibrationMetadata(out_folder).add_fragment({\"retrieved-constants\": retrieved_consts})" - ] - }, { "cell_type": "code", "execution_count": null, @@ -358,7 +319,7 @@ "outputs": [], "source": [ "# write constants metadata to fragment YAML\n", - "write_constants_fragment(\n", + "write_constants_fragment_extracal(\n", " out_folder=(metadata_folder or out_folder),\n", " calib_data=lpd_consts,\n", " caldb_root=cal_db_root,\n", @@ -722,7 +683,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/tools.py b/src/cal_tools/tools.py index 0161fb8922db89a638ac1c8e70ca27e88da2882d..b922efd35cafb252681bc22cb82cd938e6bcbc24 100644 --- a/src/cal_tools/tools.py +++ b/src/cal_tools/tools.py @@ -970,6 +970,8 @@ def write_constants_fragment( ): """Record calibration constants metadata to a fragment file. + This variant works with the calcat_interface module in this package. + Args: out_folder (Path): The output folder to store the fragment file. det_metadata (dict): A dictionary with the desired detector metadata. @@ -993,6 +995,40 @@ def write_constants_fragment( CalibrationMetadata(out_folder).add_fragment(metadata) +def write_constants_fragment_extracal( + out_folder: Path, + calib_data, + caldb_root: Path, +): + """Record calibration constants metadata to a fragment file. + + This variant works with the extra.calibration API for found constants. + + Args: + out_folder (Path): The output folder to store the fragment file. + calib_data (extra.calibration.CalibrationData): Retrieved constant details + caldb_root (Path): The calibration database root path for constant files. + """ + retrieved_consts = {} + for kda, pdu in zip(calib_data.aggregator_names, calib_data.pdu_names): + retrieved_consts[kda] = { + "physical-name": pdu, + "constants": {}, + } + + for cname, multimodconst in calib_data.items(): + for kda in multimodconst.aggregator_names: + const = multimodconst[kda] + retrieved_consts[kda]["constants"][cname] = { + "path": str(caldb_root / const.path), + "dataset": const.dataset, + "creation-time": const.metadata("begin_validity_at"), + "ccv_id": const.ccv_id + } + + CalibrationMetadata(out_folder).add_fragment({"retrieved-constants": retrieved_consts}) + + def write_compressed_frames( arr: np.ndarray, ofile: h5py.File,