diff --git a/notebooks/AGIPD/AGIPD_Correct_and_Verify_Summary_NBC.ipynb b/notebooks/AGIPD/AGIPD_Correct_and_Verify_Summary_NBC.ipynb index 5ba5cf50a1ed14dc7309c05959f8cd8c4a37ce17..ef845a4d0cfcc0cda1c3cf581b3fc7896023e503 100644 --- a/notebooks/AGIPD/AGIPD_Correct_and_Verify_Summary_NBC.ipynb +++ b/notebooks/AGIPD/AGIPD_Correct_and_Verify_Summary_NBC.ipynb @@ -101,7 +101,9 @@ " timestamp = const_data[const]\n", " table_data.setdefault(timestamp, []).append(f\"{seq}:{mod}\")\n", " table = []\n", - " if len(table_data) == 1:\n", + " if not len(table_data):\n", + " table.append([\"No constants retrieved\"])\n", + " elif len(table_data) == 1:\n", " table.append([[*table_data][0], \"All modules\"])\n", " else:\n", " for timestamp, seqmod in table_data.items():\n", @@ -115,13 +117,6 @@ "for const in ['Offset', 'SlopesPC', 'SlopesFF']:\n", " print_const_table(const)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/notebooks/AGIPD/AGIPD_Retrieve_Constants_Precorrection.ipynb b/notebooks/AGIPD/AGIPD_Retrieve_Constants_Precorrection.ipynb index 2cd11eb0b59cbb97f5c72c5e2ac9670e5573b95e..8051980183b2de5b3bea11a3051f36dcc2238edf 100644 --- a/notebooks/AGIPD/AGIPD_Retrieve_Constants_Precorrection.ipynb +++ b/notebooks/AGIPD/AGIPD_Retrieve_Constants_Precorrection.ipynb @@ -176,10 +176,12 @@ "source": [ "run_dc = RunDirectory(in_folder / f\"r{run:04d}\")\n", "\n", - "# set everything up filewise\n", - "mapped_files, _, _, _, _ = tools.map_modules_from_folder(\n", - " str(in_folder), run, path_template, karabo_da, sequences=[0]\n", - ")" + "instrument_src = instrument_source_template.format(karabo_id, receiver_template)\n", + "\n", + "instr_dc = run_dc.select(instrument_src.format(\"*\"), require_all=True)\n", + "\n", + "if not instr_dc.train_ids:\n", + " raise ValueError(f\"No images found for {in_folder / f'r{run:04d}'}\")" ] }, { @@ -188,13 +190,9 @@ "metadata": {}, "outputs": [], "source": [ - "# Read AGIPD conditions from the 1st sequence of 1st module and slow data.\n", - "instrument_src = instrument_source_template.format(karabo_id, receiver_template)\n", - "instrument_src_mod = instrument_src.format(0)\n", - "\n", "agipd_cond = agipdlib.AgipdCtrl(\n", " run_dc=run_dc,\n", - " image_src=None, # Not need, as we wont read mem_cells or acq_rate.\n", + " image_src=None, # Not neededed, as we wont read mem_cells or acq_rate.\n", " ctrl_src=ctrl_src,\n", ")\n", "\n", @@ -224,31 +222,33 @@ "outputs": [], "source": [ "def retrieve_constants(\n", - " karabo_da: str, idx: int\n", + " k_da: str, idx: int\n", ") -> Tuple[str, str, float, float, str, dict]:\n", " \"\"\"\n", " Retrieve constants for a module.\n", "\n", " :return:\n", - " karabo_da: karabo data aggregator.\n", + " k_da: karabo data aggregator.\n", " acq_rate: acquisition rate parameter.\n", " mem_cells: number of memory cells.\n", " mdata_dict: (DICT) dictionary with the metadata for the retrieved constants.\n", " \"\"\"\n", + " # check if this module has images to process.\n", + " if instrument_src.format(idx) not in instr_dc.all_sources:\n", + " print(\"ERROR: No raw images found for \"\n", + " f\"{tools.module_index_to_qm(idx)}({k_da}).\")\n", + "\n", + " return None, k_da, None, None\n", + "\n", + " agipd_cond.image_src = instrument_src.format(idx)\n", + "\n", " if mem_cells == 0:\n", - " # either or look around in sequence files\n", - " agipd_cond.image_src = instrument_src.format(idx)\n", + " # Read value from fast data.\n", " local_mem_cells = agipd_cond.get_num_cells()\n", " else:\n", - " # or use overriding notebook parameter\n", + " # or use overriding notebook parameter.\n", " local_mem_cells = mem_cells\n", "\n", - " # maybe we never found this in a sequence file...\n", - " if local_mem_cells is None:\n", - " raise ValueError(\n", - " \"No raw images found for \"\n", - " f\"{tools.module_index_to_qm(module_index)}({karabo_da}) for all sequences\")\n", - "\n", " if acq_rate == 0.:\n", " local_acq_rate = agipd_cond.get_acq_rate()\n", " else:\n", @@ -256,7 +256,7 @@ "\n", " # avoid retrieving constant, if requested.\n", " if nodb_with_dark:\n", - " return\n", + " return None, k_da, None, None\n", "\n", " const_dict = agipdlib.assemble_constant_dict(\n", " corr_bools,\n", @@ -288,7 +288,7 @@ "\n", " if slopes_ff_from_files and const_name in [\"SlopesFF\", \"BadPixelsFF\"]:\n", " const_mdata[\"file-path\"] = (\n", - " f\"{slopes_ff_from_files}/slopesff_bpmask_module_{tools.module_index_to_qm(module_index)}.h5\") # noqa\n", + " f\"{slopes_ff_from_files}/slopesff_bpmask_module_{tools.module_index_to_qm(idx)}.h5\") # noqa\n", " const_mdata[\"creation-time\"] = \"00:00:00\"\n", " continue\n", " \n", @@ -303,7 +303,7 @@ "\n", " _, mdata = tools.get_from_db(\n", " karabo_id,\n", - " karabo_da,\n", + " k_da,\n", " getattr(Constants.AGIPD, const_name)(),\n", " condition,\n", " getattr(np, const_init_fun)(const_shape),\n", @@ -324,7 +324,7 @@ " const_mdata[\"file-path\"] = const_dict[const_name][:2]\n", " const_mdata[\"creation-time\"] = None\n", "\n", - " return mdata_dict, karabo_da, local_acq_rate, local_mem_cells" + " return mdata_dict, k_da, local_acq_rate, local_mem_cells" ] }, { @@ -386,8 +386,11 @@ "source": [ "acq_rate_mods = []\n", "mem_cells_mods = []\n", - "for md_dict, karabo_da, acq_rate, mem_cells in results:\n", - " retrieved_constants[karabo_da] = md_dict\n", + "for md_dict, k_da, acq_rate, mem_cells in results:\n", + " if acq_rate is None and mem_cells is None:\n", + " continue\n", + " md_dict, k_da, acq_rate, mem_cells\n", + " retrieved_constants[k_da] = md_dict\n", " mem_cells_mods.append(mem_cells)\n", " acq_rate_mods.append(acq_rate)\n", "\n", @@ -427,6 +430,8 @@ "timestamps = {}\n", "\n", "for k_da, module_name in da_to_qm.items():\n", + " if k_da not in retrieved_constants.keys():\n", + " continue\n", " module_timestamps = timestamps[module_name] = {}\n", " module_constants = retrieved_constants[k_da]\n", "\n",