diff --git a/cal_tools/cal_tools/tools.py b/cal_tools/cal_tools/tools.py index f112c3cf089b62279ee18692ca719e37fd37ed7a..d2f2375b88130b67359d2179505669316626bc0d 100644 --- a/cal_tools/cal_tools/tools.py +++ b/cal_tools/cal_tools/tools.py @@ -78,7 +78,7 @@ def map_modules_from_folder(in_folder, run, path_template, karabo_da, sequences_qm = {} for inset in karabo_da: module_idx = int(inset[-2:]) - name = f"Q{module_idx // 4 + 1}M{module_idx % 4 + 1}" + name = module_index_to_qm(module_idx) module_files[name] = Queue() sequences_qm[name] = 0 mod_ids[name] = module_idx @@ -671,6 +671,13 @@ def get_constant_from_db_and_time(karabo_id: str, karabo_da: str, return data, None +def module_index_to_qm(index: int, total_modules: int = 16): + """Maps module index (0-indexed) to quadrant + module string (1-indexed)""" + modules_per_quad = total_modules // 4 + quad, mod = divmod(index, modules_per_quad) + return f"Q{quad+1}M{mod+1}" + + class CalibrationMetadata(dict): """Convenience class: dictionary stored in metadata YAML file diff --git a/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb b/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb index 8ea3880e68d2c35e1184bf5f1d5d6dbb8dbd1c44..abbc7a72b720adf401501a33a77918b00371a990 100644 --- a/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb +++ b/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb @@ -104,7 +104,7 @@ " show_overview, show_processed_modules)\n", "from cal_tools.tools import (get_dir_creation_date, get_from_db,\n", " get_pdu_from_db, get_random_db_interface,\n", - " get_report, map_gain_stages,\n", + " get_report, map_gain_stages, module_index_to_qm,\n", " run_prop_seq_from_path, save_const_to_h5,\n", " send_to_db)\n", "from iCalibrationDB import Conditions, Constants, Detectors" @@ -252,16 +252,6 @@ "print(f\"Will process a total of {total_sequences} files.\")" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def index_to_qm(i: int):\n", - " return f\"Q{i//4+1}M{i%4+1}\"" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -411,7 +401,7 @@ "for gg, (gain, mapped_files) in enumerate(gain_mapped_files.items()):\n", " dones = []\n", " for i in modules:\n", - " qm = index_to_qm(i)\n", + " qm = module_index_to_qm(i)\n", " if qm in mapped_files and not mapped_files[qm].empty():\n", " fname_in = mapped_files[qm].get()\n", " print(\"Process file: \", fname_in)\n", @@ -427,7 +417,7 @@ " all_cells.append(thiscell)\n", " all_acq_rate.append(thisacq)\n", " for i in modules:\n", - " qm = index_to_qm(i)\n", + " qm = module_index_to_qm(i)\n", " if qm not in offset_g:\n", " offset_g[qm] = np.zeros((offset.shape[0], offset.shape[1], offset.shape[2], 3))\n", " noise_g[qm] = np.zeros_like(offset_g[qm])\n", @@ -498,7 +488,7 @@ "source": [ "res = OrderedDict()\n", "for i in modules:\n", - " qm = index_to_qm(i)\n", + " qm = module_index_to_qm(i)\n", " res[qm] = {\n", " 'Offset': offset_g[qm],\n", " 'Noise': noise_g[qm],\n", @@ -531,7 +521,7 @@ "# Create the modules dict of karabo_das and PDUs\n", "qm_dict = OrderedDict()\n", "for i, k_da in zip(modules, karabo_da):\n", - " qm = index_to_qm(i)\n", + " qm = module_index_to_qm(i)\n", " qm_dict[qm] = {\n", " \"karabo_da\": k_da,\n", " \"db_module\": \"\"\n", @@ -643,7 +633,7 @@ "source": [ "mnames=[]\n", "for i in modules:\n", - " qm = index_to_qm(i)\n", + " qm = module_index_to_qm(i)\n", " mnames.append(qm)\n", " display(Markdown(f'## Position of the module {qm} and its ASICs##'))\n", "show_processed_modules(dinstance, constants=None, mnames=mnames, mode=\"position\")"