diff --git a/notebooks/AGIPD/AGIPD_Retrieve_Constants_Precorrection.ipynb b/notebooks/AGIPD/AGIPD_Retrieve_Constants_Precorrection.ipynb index ffc6e2fa1e83bbe05d7e90541f57671752fcbdfa..3b55820bdf66e55c2668eb76616e6551ef99fb37 100644 --- a/notebooks/AGIPD/AGIPD_Retrieve_Constants_Precorrection.ipynb +++ b/notebooks/AGIPD/AGIPD_Retrieve_Constants_Precorrection.ipynb @@ -176,10 +176,14 @@ "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 len(instr_dc.train_ids) == 0:\n", + " raise ValueError(f\"No images found for {in_folder / f'r{run:04d}'}\")\n", + "# Used to later identify sources without images to skip.\n", + "available_sources = list(instr_dc.all_sources)" ] }, { @@ -188,13 +192,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 needed, as we wont read mem_cells or acq_rate.\n", " ctrl_src=ctrl_src,\n", ")\n", "\n", @@ -224,31 +224,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", + "\n", + " if instrument_src.format(idx) not in available_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(idx)}({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 +258,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", @@ -303,7 +305,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 +326,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 +388,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 +432,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",