diff --git a/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb b/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb index d97fd8dfdfdb3655423d7825e43062e06ef3a0f2..1eabbfbda7bae774b2ed215cbf2640b52df48a4a 100644 --- a/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb +++ b/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb @@ -35,7 +35,7 @@ "ctrl_source_template = '{}/MDL/FPGA_COMP' # path to control information\n", "karabo_id_control = \"MID_EXP_AGIPD1M1\" # karabo-id for control device\n", "\n", - "slopes_ff_from_files = \"\" # Path to locally stored SlopesFF and BadPixelsFF constants, loaded in precorrection notebook\n", + "slopes_ff_from_path = '' # Path to override SlopesFF and BadPixelsFF constants by locally stored ones, only allowed with --non-reproducible.\n", "\n", "creation_time = \"\" # To overwrite the measured creation_time. Required Format: YYYY-MM-DD HR:MN:SC e.g. \"2022-06-28 13:00:00\"\n", "cal_db_interface = \"tcp://max-exfl-cal001:8015#8045\" # the database interface to use\n", @@ -737,6 +737,56 @@ "agipd_cal.display_markdown_retrieved_constants(metadata=agipd_metadata)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "if slopes_ff_from_path:\n", + " # Commissioning flag to inject custom FF calibration data.\n", + " \n", + " ff_path = Path(slopes_ff_from_path)\n", + "\n", + " da_pdu_map = {pdu_da: next(iter(pdu_ccvs.values()))['physical_name']\n", + " for pdu_da, pdu_ccvs in agipd_metadata.items()}\n", + "\n", + " def _override_ccvs_from_file(ccv_path, calibrations=['SlopesFF', 'BadPixelsFF']):\n", + " num_overrides = 0\n", + " \n", + " with h5py.File(ccv_path, 'r') as ccv_file:\n", + " for pdu_da, pdu_name in da_pdu_map.items():\n", + " try:\n", + " pdu_group = ccv_file[pdu_name]\n", + " except KeyError:\n", + " continue\n", + "\n", + " for calibration in calibrations:\n", + " if calibration in pdu_group:\n", + " print(f'Overwriting {calibration} for {pdu_name} @ {pdu_da} from {ccv_path}')\n", + " agipd_metadata[pdu_da][calibration]['path'] = ccv_path\n", + " num_overrides += 1\n", + "\n", + " return num_overrides\n", + "\n", + " num_overrides = 0\n", + "\n", + " if ff_path.is_file():\n", + " # Single file with one more or calibrations and PDUs\n", + " num_overrides += _override_ccvs_from_file(ff_path)\n", + "\n", + " elif ff_path.is_dir():\n", + " # Directory with multiple files named const_{calibration}_{pdu}.h5\n", + " for ccv_file in ff_path.glob('const_*_*.h5'):\n", + " num_overrides += _override_ccvs_from_file(ccv_file)\n", + "\n", + " else:\n", + " raise ValueError('slopes_ff_from_path not pointing to an existing file or directory')\n", + "\n", + " if num_overrides == 0:\n", + " warning(f'no usable overrides found in {slopes_ff_from_path}')" + ] + }, { "cell_type": "code", "execution_count": null,