diff --git a/notebooks/Gotthard2/Characterize_Darks_Gotthard2_NBC.ipynb b/notebooks/Gotthard2/Characterize_Darks_Gotthard2_NBC.ipynb index 5c49f27a345585539a8d3e82fb34e05a0efd8d19..6b6466f3dc0483d9aace9194d043cad85cf356d7 100644 --- a/notebooks/Gotthard2/Characterize_Darks_Gotthard2_NBC.ipynb +++ b/notebooks/Gotthard2/Characterize_Darks_Gotthard2_NBC.ipynb @@ -30,12 +30,12 @@ "run_low = 9 # run number for G2 dark run, required\n", "\n", "# Parameters used to access raw data.\n", + "input_source_template = \"{karabo_id}/DET/RECEIVER{input_source_affixes}:daqOutput\" # data source template used to read INSTRUMENT keys.\n", + "ctrl_source_template = \"{karabo_id_control}/DET/{control_template}\" # template for control source name (filled with karabo_id_control)\n", "karabo_id = \"FXE_XAD_G2XES\" # karabo prefix of Gotthard-II devices\n", "karabo_da = [\"\"] # data aggregators\n", - "receiver_template = \"RECEIVER{}\" # receiver template used to read INSTRUMENT keys.\n", - "receiver_affixes = [\"\"] # The affix to format into the receiver template to be able to load the correct receiver name from the data.\n", + "input_source_affixes = [\"\"] # The affix to format into the input source template to be able to load the correct module's data.\n", "control_template = \"CONTROL\" # control template used to read CONTROL keys.\n", - "ctrl_source_template = '{}/DET/{}' # template for control source name (filled with karabo_id_control)\n", "karabo_id_control = \"\" # Control karabo ID. Set to empty string to use the karabo-id\n", "\n", "# Parameters for the calibration database.\n", @@ -110,7 +110,10 @@ "if not karabo_id_control:\n", " karabo_id_control = karabo_id\n", "\n", - "ctrl_src = ctrl_source_template.format(karabo_id_control, control_template)\n", + "ctrl_src = ctrl_source_template.format(\n", + " karabo_id_control=karabo_id_control,\n", + " control_template=control_template,\n", + ")\n", "run_nums = gotthard2lib.sort_dark_runs_by_gain(\n", " raw_folder=in_folder,\n", " runs=run_nums,\n", @@ -236,7 +239,12 @@ "print(f\"Processing {karabo_da}\")\n", "\n", "da_to_source = gotthard2lib.map_da_to_source(\n", - " karabo_da, receiver_affixes, receiver_template, run_dc)" + " run_dc,\n", + " karabo_da,\n", + " input_source_template,\n", + " karabo_id,\n", + " input_source_affixes,\n", + ")" ] }, { diff --git a/notebooks/Gotthard2/Correction_Gotthard2_NBC.ipynb b/notebooks/Gotthard2/Correction_Gotthard2_NBC.ipynb index cc5859219033cbc0273f320d5d2835d0efe3cdbf..a424d7f31a2d285fb92321b884d5b69d59be0d6f 100644 --- a/notebooks/Gotthard2/Correction_Gotthard2_NBC.ipynb +++ b/notebooks/Gotthard2/Correction_Gotthard2_NBC.ipynb @@ -58,15 +58,14 @@ "sequences_per_node = 1 # number of sequence files per node if notebook executed through xfel-calibrate, set to 0 to not run SLURM parallel\n", "\n", "# Parameters used to access raw data.\n", + "output_source_template = \"{karabo_id}/CORR/RECEIVER:daqOutput\" # Correction data source template. filled with karabo_id and correction receiver\n", + "ctrl_source_template = \"{karabo_id_control}/DET/{control_template}\" # template for control source name (filled with karabo_id_control)\n", "karabo_id = \"DETLAB_25UM_GH2\" # karabo prefix of Gotthard-II devices\n", "karabo_da = [\"\"] # data aggregators\n", - "receiver_template = \"RECEIVER{}\" # receiver template used to read INSTRUMENT keys.\n", - "receiver_affixes = [\"\"] # The affix to format into the receiver template to be able to load the correct receiver name from the data.\n", + "input_source_affixes = [\"\"] # The affix to format into the input source template to be able to load the correct module's data.\n", + "input_source_template = \"{karabo_id}/DET/RECEIVER{input_source_affixes}:daqOutput\" # data source template used to read INSTRUMENT keys.\n", "control_template = \"CONTROL\" # control template used to read CONTROL keys.\n", - "ctrl_source_template = \"{}/DET/{}\" # template for control source name (filled with karabo_id_control)\n", "karabo_id_control = \"\" # Control karabo ID. Set to empty string to use the karabo-id\n", - "corr_source_template = \"{}/CORR/{}:daqOutput\" # Correction data source template. filled with karabo_id and correction receiver\n", - "corr_receiver = \"\" # Receiver name for corrected data. Leave empty to use the default receiver: - For 50um GH2 data, it will use the same receiver name - For 25um GH2 data, it will use the first (e.g. .._Master) receiver. Specifying a receiver name is recommended.\n", "\n", "# Parameters for calibration database.\n", "cal_db_interface = \"tcp://max-exfl-cal001:8016#8025\" # the database interface to use.\n", @@ -147,7 +146,10 @@ "if not karabo_id_control:\n", " karabo_id_control = karabo_id\n", "\n", - "ctrl_src = ctrl_source_template.format(karabo_id_control, control_template)\n", + "ctrl_src = ctrl_source_template.format(\n", + " karabo_id_control=karabo_id_control,\n", + " control_template=control_template,\n", + ")\n", "\n", "# Run's creation time:\n", "creation_time = calcat_creation_time(in_folder, run, creation_time)\n", @@ -239,20 +241,18 @@ " db_modules = [da_to_pdu[da] for da in karabo_da]\n", "\n", "print(f\"Process modules: {db_modules} for run {run}\")\n", - "if len(receiver_affixes) != len(karabo_da):\n", + "if len(input_source_affixes) != len(karabo_da):\n", " raise ValueError(\n", " \"receiver_affixes & karabo_da are not the same length\")\n", "\n", "da_to_source = gotthard2lib.map_da_to_source(\n", - " karabo_da, receiver_affixes, receiver_template, run_dc)\n", - "data_sources = list(da_to_source.values())\n", - "if not corr_receiver:\n", - " # Defaulting to the first receiver from data_sources.\n", - " # Format expected: '{karabo_id}/DET/{receiver_name}:{output_channel}'.\n", - " # This is acceptable for 50um data but may not be ideal for 25um data. \n", - " # Using corr_receiver is recommended when possible.\n", - " corr_receiver = data_sources[0].split(\"/\")[-1].split(\":\")[0]\n", - " print(f\"Using {corr_receiver} as a receiver name for the corrected data.\")" + " run_dc,\n", + " karabo_da,\n", + " input_source_template,\n", + " karabo_id,\n", + " input_source_affixes,\n", + ")\n", + "data_sources = list(da_to_source.values())" ] }, { @@ -429,7 +429,7 @@ "metadata": {}, "outputs": [], "source": [ - "corr_data_source = corr_source_template.format(karabo_id, corr_receiver)\n", + "corr_data_source = output_source_template.format(karabo_id=karabo_id)\n", "\n", "for raw_file in seq_files:\n", "\n", diff --git a/src/cal_tools/gotthard2/gotthard2lib.py b/src/cal_tools/gotthard2/gotthard2lib.py index bf62d9083e1cedb6dab5312d530e85326b1e5c8c..51f1e6118536ab4836c5ec7319c64b9d5a123c1b 100644 --- a/src/cal_tools/gotthard2/gotthard2lib.py +++ b/src/cal_tools/gotthard2/gotthard2lib.py @@ -5,10 +5,11 @@ from typing import List, Union import extra_data -def map_da_to_source(da, affixes, template, dc): +def map_da_to_source(dc, das, source_template, karabo_id, affixes): da_to_source = {} - for da, aff in zip(da, affixes): - sources = dc.select(f"*{template.format(aff)}:daqOutput").all_sources + for da, aff in zip(das, affixes): + sources = dc.select( + f"*{source_template.format(karabo_id=karabo_id, input_source_affixes=aff)}").all_sources # noqa if len(sources) != 1: raise ValueError(f"No/multiple sources found for {aff!r}") da_to_source[da] = list(sources)[0] diff --git a/tests/test_reference_runs/callab_tests.py b/tests/test_reference_runs/callab_tests.py index 8e8e00ec9efba75bf8943935ddbbae48f3e80a16..08d6f26e2230d6b2f9cc67951a94103023ed5171 100644 --- a/tests/test_reference_runs/callab_tests.py +++ b/tests/test_reference_runs/callab_tests.py @@ -869,8 +869,8 @@ automated_test_config = { "in-folder": "/gpfs/exfel/exp/CALLAB/202130/p900203/raw", "karabo-da": ["GH200/1", "GH200/2",], "control-template": "GOTTHARD2_CTRL", - "receiver-affixes": ["_MASTER", "_SLAVE"], - "receiver-template": "GOTTHARD2{}", + "input-source-affixes": ["MASTER", "SLAVE"], + "input-source-template": "{karabo_id}/DET/GOTTHARD2_{input_source_affixes}:daqOutput", "run-high": "28", # 82 "run-med": "29", # 83 "run-low": "30", # 84 @@ -887,9 +887,9 @@ automated_test_config = { "in-folder": "/gpfs/exfel/exp/CALLAB/202130/p900203/raw", "karabo-da": ["GH200/1", "GH200/2",], "control-template": "GOTTHARD2_CTRL", - "receiver-affixes": ["_MASTER", "_SLAVE"], - "receiver-template": "GOTTHARD2{}", - "corr-receiver": "GOTTHARD2_RECEIVER", + "input-source-affixes": ["MASTER", "SLAVE"], + "input-source-template": "{karabo_id}/DET/GOTTHARD2_{input_source_affixes}:daqOutput", + "output-source-template": "{karabo_id}/CORR/GH200:daqOutput", "run": "31", "karabo-id": "SA1_XTD9_HIREX", "no-offset-correction": True,