diff --git a/notebooks/LPD/LPD_Correct_Fast.ipynb b/notebooks/LPD/LPD_Correct_Fast.ipynb index fec39227a975935f1b9ad75259db527eb03e20f1..e841269afbd6454e8df41e060cc2dfa32675bd12 100644 --- a/notebooks/LPD/LPD_Correct_Fast.ipynb +++ b/notebooks/LPD/LPD_Correct_Fast.ipynb @@ -605,9 +605,9 @@ ], "metadata": { "kernelspec": { - "display_name": "pycal", + "display_name": ".cal2_venv", "language": "python", - "name": "pycal" + "name": "python3" }, "language_info": { "codemirror_mode": { @@ -619,7 +619,12 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.11" + "version": "3.8.11 (default, Jul 2 2021, 14:23:46) \n[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]" + }, + "vscode": { + "interpreter": { + "hash": "8817b9fbc45d4ec68a62bc54fa52c1c5ac00d5619f7fe87d01def1798ea4889e" + } } }, "nbformat": 4, diff --git a/notebooks/LPD/LPD_retrieve_constants_precorrection.ipynb b/notebooks/LPD/LPD_retrieve_constants_precorrection.ipynb index 5362f87e3e32b173c626ee5610496f5af63b9e28..13c7c22721d4833f0f869f54008511035dcfe625 100644 --- a/notebooks/LPD/LPD_retrieve_constants_precorrection.ipynb +++ b/notebooks/LPD/LPD_retrieve_constants_precorrection.ipynb @@ -45,9 +45,10 @@ "metadata": {}, "outputs": [], "source": [ + "from logging import warning\n", "from pathlib import Path\n", "\n", - "from cal_tools.calcat_interface import CalCatError, LPD_CalibrationData\n", + "from cal_tools.calcat_interface import LPD_CalibrationData\n", "from cal_tools.tools import (\n", " CalibrationMetadata,\n", " calcat_creation_time,\n", @@ -96,7 +97,23 @@ "metadata": {}, "outputs": [], "source": [ - "const_data = {}\n", + "step_timer.start()\n", + "lpd_cal = LPD_CalibrationData(\n", + " detector_name=karabo_id,\n", + " modules=karabo_da,\n", + " sensor_bias_voltage=bias_voltage,\n", + " memory_cells=mem_cells,\n", + " feedback_capacitor=capacitor,\n", + " source_energy=photon_energy,\n", + " category=category,\n", + " event_at=creation_time,\n", + " snapshot_at=creation_time,\n", + ")\n", + "constant_names = [\n", + " \"Offset\", \"BadPixelsDark\",\n", + " \"BadPixelsFF\", \"GainAmpMap\",\n", + " \"FFMap\", \"RelativeGain\",\n", + "]\n", "\n", "print('Querying calibration database', end='', flush=True)\n", "start = perf_counter()\n", @@ -116,32 +133,34 @@ " {'parameters_conditions_attributes': condition},\n", " karabo_da=k_da, event_at=creation_time.isoformat())\n", "\n", - " if not resp[\"success\"]:\n", - " print(f\"ERROR: Constants {list(calibrations.values())} \"\n", - " f\"were not retrieved, {resp['app_info']}\")\n", - " for cname in calibrations.values():\n", - " const_mdata[cname] = dict()\n", - " const_mdata[cname][\"file-path\"] = None\n", - " const_mdata[cname][\"dataset-name\"] = None\n", - " const_mdata[cname][\"creation-time\"] = None \n", - " continue\n", + "lpd_cal_metadata = lpd_cal.metadata()\n", "\n", - " for ccv in resp[\"data\"]:\n", - " cc = ccv['calibration_constant']\n", - " cname = calibrations[cc['calibration_id']]\n", - " const_mdata[cname] = dict()\n", - " const_mdata[cname][\"file-path\"] = str(Path(ccv['path_to_file']) / ccv['file_name'])\n", - " const_mdata[cname][\"dataset-name\"] = ccv['data_set_name']\n", - " const_mdata[cname][\"creation-time\"] = ccv['begin_at']\n", - " pdu = ccv['physical_detector_unit']['physical_name']\n", + "# Validate the constants availability and raise/warn correspondingly. \n", + "for mod, ccv_dict in lpd_cal_metadata.items():\n", + " missing_dark_constants = set(\n", + " c for c in [\"Offset\", \"BadPixelsDark\"] if c not in ccv_dict.keys())\n", + " missing_gain_constants = set(\n", + " c for c in [\"BadPixelsFF\", \"GainAmpMap\", \"FFMap\", \"RelativeGain\"] if c not in ccv_dict.keys()) # noqa\n", + " if missing_dark_constants:\n", + " raise KeyError(\n", + " f\"Dark constants {missing_dark_constants} are not available for correction. Module: {mod}\") # noqa\n", + " if missing_gain_constants:\n", + " warning(\n", + " f\"Gain constants {missing_gain_constants} were not retrieved. Module: {mod}\")\n", "\n", - " print('.', end='', flush=True)\n", - " retrieved_constants[k_da][\"physical-detector-unit\"] = pdu\n", + "for mod, ccv_dict in lpd_cal_metadata.items():\n", + " mdata_dict = {\"constants\": dict()}\n", + " for cname, ccv_metadata in ccv_dict.items():\n", + " mdata_dict[\"constants\"][cname] = {\n", + " \"path\": str(lpd_cal.caldb_root / ccv_metadata[\"path\"]),\n", + " \"dataset\": ccv_metadata[\"dataset\"],\n", + " \"creation-time\": ccv_metadata[\"begin_validity_at\"],\n", + " }\n", + " mdata_dict[\"physical-name\"] = ccv_metadata[\"physical_name\"]\n", + " retrieved_constants[mod] = mdata_dict\n", "metadata.save()\n", "\n", - "total_time = perf_counter() - start\n", - "print(f'{total_time:.1f}s')\n", - "print(f\"Stored retrieved constants in {metadata.filename}\")" + "step_timer.done_step(f\"Stored retrieved constants in {metadata.filename}.\")" ] } ], diff --git a/notebooks/ePix100/Correction_ePix100_NBC.ipynb b/notebooks/ePix100/Correction_ePix100_NBC.ipynb index 1fef42f02e397998348955572ed8c55f422b6e2e..e66a4e9050afb29b0c6ad782d7e44f26999b83c5 100644 --- a/notebooks/ePix100/Correction_ePix100_NBC.ipynb +++ b/notebooks/ePix100/Correction_ePix100_NBC.ipynb @@ -846,9 +846,9 @@ ], "metadata": { "kernelspec": { - "display_name": "cal_venv", + "display_name": ".cal2_venv", "language": "python", - "name": "cal_venv" + "name": "python3" }, "language_info": { "codemirror_mode": { @@ -860,7 +860,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.11" + "version": "3.8.11 (default, Jul 2 2021, 14:23:46) \n[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]" }, "latex_envs": { "LaTeX_envs_menu_present": true, @@ -878,6 +878,11 @@ "latex_user_defs": false, "report_style_numbering": false, "user_envs_cfg": false + }, + "vscode": { + "interpreter": { + "hash": "8817b9fbc45d4ec68a62bc54fa52c1c5ac00d5619f7fe87d01def1798ea4889e" + } } }, "nbformat": 4, diff --git a/notebooks/ePix100/ePix100_retrieve_constants_precorrection.ipynb b/notebooks/ePix100/ePix100_retrieve_constants_precorrection.ipynb index d788555091895816de6f1b098e7cb32a8e9a836a..a3bf60258927e6c2eb119d499d291db6058c4890 100644 --- a/notebooks/ePix100/ePix100_retrieve_constants_precorrection.ipynb +++ b/notebooks/ePix100/ePix100_retrieve_constants_precorrection.ipynb @@ -193,9 +193,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3.8.11 ('.cal4_venv')", + "display_name": "cal2_venv", "language": "python", - "name": "python3" + "name": "cal2_venv" }, "language_info": { "codemirror_mode": { @@ -207,7 +207,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.11" + "version": "3.8.11 (default, Jul 2 2021, 14:23:46) \n[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]" }, "orig_nbformat": 4, "vscode": {