diff --git a/src/cal_tools/agipdlib.py b/src/cal_tools/agipdlib.py index 404c40d04d01b6b9d91b708892761e893068b811..dbca752e3b41b93ddb9b4ca9ccce0032a49f11af 100644 --- a/src/cal_tools/agipdlib.py +++ b/src/cal_tools/agipdlib.py @@ -374,12 +374,13 @@ class AgipdCtrlRuns: """ Args: karabo_id_control (Optional[str], optional): - Karabo ID for control device. + Karabo ID for control device. Returns: int: Bias voltage. """ - bias_voltages = [c.get_bias_voltage(karabo_id_control) for c in self.run_ctrls] + bias_voltages = [ + c.get_bias_voltage(karabo_id_control) for c in self.run_ctrls] self._validate_same_value("Bias Voltage", bias_voltages) return bias_voltages[0] @@ -396,7 +397,7 @@ class AgipdCtrlRuns: """ Args: creation_time (Optional[datetime], optional): - Creation time for the runs. + Creation time for the runs. Returns: float: Gain Setting diff --git a/tests/test_agipdlib.py b/tests/test_agipdlib.py index ad1a92f42f956d291adebedbfb6df61a929d4e32..4e0d791250b3db644f9bd5939b102d1e0f067751 100644 --- a/tests/test_agipdlib.py +++ b/tests/test_agipdlib.py @@ -1,12 +1,14 @@ from datetime import datetime from extra_data import RunDirectory +import pytest -from cal_tools.agipdlib import AgipdCtrl +from cal_tools.agipdlib import AgipdCtrl, AgipdCtrlRuns +from cal_tools.enums import AgipdGainMode SPB_AGIPD_INST_SRC = 'SPB_DET_AGIPD1M-1/DET/0CH0:xtdf' -CTRL_SRC = 'SPB_IRU_AGIPD1M1/MDL/FPGA_COMP' - +SPB_AGIPD_KARABO_CTRL_ID = 'SPB_IRU_AGIPD1M1' +CTRL_SRC = f'{SPB_AGIPD_KARABO_CTRL_ID}/MDL/FPGA_COMP' def test_get_acq_rate_ctrl(mock_agipd1m_run): # Current up to date data with acq_rate stored @@ -136,8 +138,8 @@ def test_get_bias_voltage( # Read bias voltage for HED_DET_AGIPD500K from slow data. agipd_ctrl = AgipdCtrl( run_dc=RunDirectory(mock_agipd500k_run), - image_src=SPB_AGIPD_INST_SRC, - ctrl_src=CTRL_SRC) + image_src=None, + ctrl_src=None) bias_voltage = agipd_ctrl.get_bias_voltage( karabo_id_control="HED_EXP_AGIPD500K2G") @@ -198,3 +200,110 @@ def test_get_gain_mode(mock_agipd1m_run): gain_mode = agipd_ctrl.get_gain_mode() assert isinstance(gain_mode, int) assert gain_mode == 0 + + +""" +Testing `AgipdCtrlRuns` + +Runs used: +FIXED: /gpfs/exfel/exp/CALLAB/202130/p900203/raw/[9011,9012,9013] +ADAPTIVE: /gpfs/exfel/exp/CALLAB/202130/p900203/raw/[9015,9016,9017] +""" +def _initialize_agipd_ctrls( + runs, + raw_folder="/gpfs/exfel/exp/CALLAB/202130/p900203/raw/" +): + return [AgipdCtrl( + run_dc=RunDirectory(f"{raw_folder}/r{r:04d}"), + ctrl_src=CTRL_SRC, + image_src=SPB_AGIPD_INST_SRC, + karabo_id_control=SPB_AGIPD_KARABO_CTRL_ID, + ) for r in runs] + + +@pytest.mark.requires_gpfs +def test_get_memory_cells_runs(): + fixed_ctrls = _initialize_agipd_ctrls([9011, 9012, 9013]) + ctrl_runs = AgipdCtrlRuns(run_ctrls=fixed_ctrls) + assert 352 == ctrl_runs.get_memory_cells() + + adaptive_ctrls = _initialize_agipd_ctrls([9015, 9016, 9017]) + ctrl_runs = AgipdCtrlRuns(run_ctrls=adaptive_ctrls) + assert 352 == ctrl_runs.get_memory_cells() + + +@pytest.mark.requires_gpfs +def test_get_bias_voltage_runs(): + fixed_ctrls = _initialize_agipd_ctrls([9011, 9012, 9013]) + ctrl_runs = AgipdCtrlRuns(run_ctrls=fixed_ctrls) + assert 300 == ctrl_runs.get_bias_voltage() + + adaptive_ctrls = _initialize_agipd_ctrls([9015, 9016, 9017]) + ctrl_runs = AgipdCtrlRuns(run_ctrls=adaptive_ctrls) + assert 300 == ctrl_runs.get_bias_voltage() + + +@pytest.mark.requires_gpfs +def test_get_integration_time_runs(): + fixed_ctrls = _initialize_agipd_ctrls([9011, 9012, 9013]) + ctrl_runs = AgipdCtrlRuns(run_ctrls=fixed_ctrls) + assert 12 == ctrl_runs.get_integration_time() + + adaptive_ctrls = _initialize_agipd_ctrls([9015, 9016, 9017]) + ctrl_runs = AgipdCtrlRuns(run_ctrls=adaptive_ctrls) + assert 20 == ctrl_runs.get_integration_time() + + +@pytest.mark.requires_gpfs +def test_get_acquisition_rate_runs(): + fixed_ctrls = _initialize_agipd_ctrls([9011, 9012, 9013]) + ctrl_runs = AgipdCtrlRuns(run_ctrls=fixed_ctrls) + assert 1.1 == ctrl_runs.get_acq_rate() + + adaptive_ctrls = _initialize_agipd_ctrls([9015, 9016, 9017]) + ctrl_runs = AgipdCtrlRuns(run_ctrls=adaptive_ctrls) + assert 1.1 == ctrl_runs.get_acq_rate() + + +@pytest.mark.requires_gpfs +def test_get_gain_setting_runs(): + fixed_ctrls = _initialize_agipd_ctrls([9011, 9012, 9013]) + ctrl_runs = AgipdCtrlRuns(run_ctrls=fixed_ctrls) + assert 0 == ctrl_runs.get_gain_setting() + + adaptive_ctrls = _initialize_agipd_ctrls([9015, 9016, 9017]) + ctrl_runs = AgipdCtrlRuns(run_ctrls=adaptive_ctrls) + assert 0 == ctrl_runs.get_gain_setting() + + +@pytest.mark.requires_gpfs +def test_get_gain_mode_runs(): + fixed_ctrls = _initialize_agipd_ctrls([9011, 9012, 9013]) + ctrl_runs = AgipdCtrlRuns(run_ctrls=fixed_ctrls) + assert [ + AgipdGainMode.FIXED_HIGH_GAIN, + AgipdGainMode.FIXED_MEDIUM_GAIN, + AgipdGainMode.FIXED_LOW_GAIN + ] == ctrl_runs.get_gain_modes() + + adaptive_ctrls = _initialize_agipd_ctrls([9015, 9016, 9017]) + ctrl_runs = AgipdCtrlRuns(run_ctrls=adaptive_ctrls) + assert [AgipdGainMode.ADAPTIVE_GAIN]*3 == ctrl_runs.get_gain_modes() + + +@pytest.mark.requires_gpfs +def test_fixed_gain_mode(): + fixed_ctrls = _initialize_agipd_ctrls([9011, 9012, 9013]) + ctrl_runs = AgipdCtrlRuns(run_ctrls=fixed_ctrls) + assert True == ctrl_runs.fixed_gain_mode() + + adaptive_ctrls = _initialize_agipd_ctrls([9015, 9016, 9017]) + ctrl_runs = AgipdCtrlRuns(run_ctrls=adaptive_ctrls) + assert False == ctrl_runs.fixed_gain_mode() + +@pytest.mark.requires_gpfs +def test_raise_fixed_gain_mode(): + adaptive_fixed = _initialize_agipd_ctrls([9011, 9016, 9017]) + with pytest.raises(ValueError) as e: + ctrl_runs = AgipdCtrlRuns(run_ctrls=adaptive_fixed) + ctrl_runs.fixed_gain_mode()