diff --git a/notebooks/DynamicFF/Characterize_DynamicFF_NBC.ipynb b/notebooks/DynamicFF/Characterize_DynamicFF_NBC.ipynb index 54c4412b7a4d324f101027ce3bde451dc25d0114..ef9a5e27f60fd33e4a929c134e1469a467b0e136 100644 --- a/notebooks/DynamicFF/Characterize_DynamicFF_NBC.ipynb +++ b/notebooks/DynamicFF/Characterize_DynamicFF_NBC.ipynb @@ -46,6 +46,7 @@ "import datetime\n", "import os\n", "import warnings\n", + "from logging import warning\n", "\n", "warnings.filterwarnings('ignore')\n", "\n", @@ -87,7 +88,7 @@ " {\"detector_identifier\": karabo_id})\n", "\n", "if not pdus[\"success\"]:\n", - " print(\"exception\")\n", + " raise ValueException(\"Failed to retrieve PDUs\")\n", "\n", "detector_info = pdus['data'][0]['detector']\n", "detector = ShimadzuHPVX2(detector_info[\"source_name_pattern\"])\n", @@ -145,9 +146,15 @@ " file_da, _, _ = da.partition('/')\n", " dark_dc = RunDirectory(f\"{in_folder}/r{dark_run:04d}\",\n", " include=f\"RAW-R{dark_run:04d}-{file_da}-S*.h5\")\n", + "\n", + " if source_name not in dark_dc.all_sources:\n", + " print(f\"Source {source_name} for module {da} is missed\")\n", + " continue\n", + "\n", " dark_dc = dark_dc.select([(source_name, image_key)])\n", - " key_data = dark_dc[source_name, image_key]\n", + " conditions = detector.conditions(dark_dc, meta[\"module\"])\n", "\n", + " key_data = dark_dc[source_name, image_key]\n", " images_dark = key_data.ndarray()\n", " ntrain, npulse, ny, nx = images_dark.shape\n", "\n", @@ -160,7 +167,6 @@ " dark = dffc.process_dark(images_dark)\n", "\n", " # put results in the dict\n", - " conditions = detector.conditions(dark_dc, meta[\"module\"])\n", " module_constants = constants.setdefault(meta[\"db_module\"], {})\n", " module_constants[\"Offset\"] = dict(\n", " conditions=conditions, data=dark, pdu_no=meta[\"pdu_no\"],\n", @@ -206,9 +212,22 @@ " file_da, _, _ = da.partition('/')\n", " flat_dc = RunDirectory(f\"{in_folder}/r{flat_run:04d}\",\n", " include=f\"RAW-R{flat_run:04d}-{file_da}-S*.h5\")\n", + "\n", + " if source_name not in flat_dc.all_sources:\n", + " print(f\"Source {source_name} for module {da} is missed\")\n", + " continue\n", + "\n", " flat_dc = flat_dc.select([(source_name, image_key)])\n", - " key_data = flat_dc[source_name][image_key]\n", + " conditions = detector.conditions(flat_dc, meta[\"module\"])\n", "\n", + " dark = constants[meta[\"db_module\"]][\"Offset\"][\"data\"]\n", + " dark_conditions = constants[meta[\"db_module\"]][\"Offset\"][\"conditions\"]\n", + "\n", + " if conditions != dark_conditions:\n", + " ValueError(\"The conditions for flat-field run does not match \"\n", + " \"the dark run conditions. Skip flat-field characterization.\")\n", + "\n", + " key_data = flat_dc[source_name][image_key]\n", " images_flat = key_data.ndarray()\n", " ntrain, npulse, ny, nx = images_flat.shape\n", "\n", @@ -284,7 +303,7 @@ " conditions = constant[\"conditions\"]\n", " conditions_dict = conditions.make_dict(\n", " conditions.calibration_types[constant_name])\n", - " \n", + "\n", " data_to_store = {db_module: {constant_name: {'0': {\n", " 'conditions': conditions_dict,\n", " 'data': constant[\"data\"],\n",