Skip to content
Snippets Groups Projects
Commit 21276174 authored by Cyril Danilevski's avatar Cyril Danilevski :scooter:
Browse files

Adapt agipdlib.get_acq_rate to fetch rate from MDL control data

parent 3fa2cd9e
No related branches found
No related tags found
1 merge request!353[AGIPD] [DARK] Add support for AGIPD mini half in dark calibration
from pathlib import Path
from typing import Optional, Tuple
import h5py
import numpy as np
import sharedmem
......@@ -22,16 +25,49 @@ def get_num_cells(fname, loc, module):
return options[np.argmin(dists)]
def get_acq_rate(fname, loc, module):
with h5py.File(fname, "r") as f:
try:
pulses = \
np.squeeze(f[f"INSTRUMENT/{loc}/DET/{module}CH0:xtdf/image/pulseId"][:2]) # noqa
diff = pulses[1] - pulses[0]
except:
diff = 0
options = {8: 0.5, 4: 1.1, 2: 2.2, 1: 4.5}
return options.get(diff, None)
def get_acq_rate(slow_paths: Tuple[str, str],
fast_paths: Tuple[str, str, int]) -> Optional[float]:
"""Get the acquisition rate from said detector module.
If the data is available from the middlelayer FPGA_COMP device, then it is
retrieved from there. If not, the rate is calculated from two different pulses
time.
The first entry is deliberatly not used, as the detector just began operating,
and it might have skipped a train.
:param slow_paths: in which file and h5 path to look for slow data.
The first string is the filename with complete path,
the second string is the key `karabo_id_control`
:param fast_paths: in which module file and h5 path to look for pulses.
The first string is the filename with complete path,
the second string is the module device name `karabo_id`,
the third parameter is the module number, used to navigate
through the h5 file structure.
:return acq_rate: the acquisition rate. If not found in either files, return None.
"""
# Attempt to look for acquisition rate in slow data
slow_data_file, karabo_id_control = slow_paths
slow_data_file = Path(slow_data_file)
if slow_data_file.exists():
slow_data_path = f'CONTROL/{karabo_id_control}/MDL/FPGA_COMP/bunchStructure/repetitionRate/value' # noqa
with h5py.File(slow_data_file, "r") as fin:
if slow_data_path in fin:
return fin[slow_data_path][3]
# Compute acquisition rate from fast data
fast_data_file, karabo_id, module = fast_paths
fast_data_file = Path(fast_data_file)
if fast_data_file.exists():
fast_data_path = f'INSTRUMENT/{karabo_id}/DET/{module}CH0:xtdf/image/pulseId'
with h5py.File(fast_data_file) as fin:
if fast_data_path in fin:
pulses = np.squeeze(fin[fast_data_path][1:3])
diff = pulses[1] - pulses[0]
options = {8: 0.5, 4: 1.1, 2: 2.2, 1: 4.5}
return options.get(diff, None)
def get_gain_setting(fname, h5path_ctrl):
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment