mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-12 12:57:13 +02:00
python
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
17
python/simple-integration-tests/eiger/config_test.py
Normal file
17
python/simple-integration-tests/eiger/config_test.py
Normal file
@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Tue Nov 14 16:49:07 2017
|
||||
|
||||
@author: l_frojdh
|
||||
"""
|
||||
|
||||
fw_version = 22
|
||||
detector_type = 'Eiger'
|
||||
known_hostnames = ['beb083', 'beb098']
|
||||
image_size = (512,1024) #rows, cols
|
||||
module_geometry = (1,2) #horizontal, vertical
|
||||
|
||||
#Remember to change these in the settings file as well!
|
||||
settings_path = '/home/l_frojdh/slsDetectorPackage/settingsdir/eiger'
|
||||
file_path = '/home/l_frojdh/out'
|
27
python/simple-integration-tests/eiger/fixtures.py
Normal file
27
python/simple-integration-tests/eiger/fixtures.py
Normal file
@ -0,0 +1,27 @@
|
||||
import pytest
|
||||
|
||||
from sls_detector import Detector
|
||||
|
||||
@pytest.fixture
|
||||
def detector():
|
||||
from sls_detector import Detector
|
||||
return Detector()
|
||||
|
||||
@pytest.fixture
|
||||
def eiger():
|
||||
from sls_detector import Eiger
|
||||
d = Eiger()
|
||||
d.n_frames = 1
|
||||
d.exposure_time = 1
|
||||
d.file_write = False
|
||||
return d
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def jungfrau():
|
||||
from sls_detector import Jungfrau
|
||||
return Jungfrau()
|
||||
|
||||
detector_type = Detector().detector_type
|
||||
eigertest = pytest.mark.skipif(detector_type != 'Eiger', reason = 'Only valid for Eiger')
|
||||
jungfrautest = pytest.mark.skipif(detector_type != 'Jungfrau', reason = 'Only valid for Jungfrau')
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
33
python/simple-integration-tests/eiger/test.config
Normal file
33
python/simple-integration-tests/eiger/test.config
Normal file
@ -0,0 +1,33 @@
|
||||
detsizechan 1024 512
|
||||
|
||||
#hostname for top+bottom+
|
||||
hostname beb083+beb098+
|
||||
|
||||
#top
|
||||
0:rx_tcpport 1954
|
||||
0:lock 0
|
||||
0:rx_udpport 50010
|
||||
0:rx_udpport2 50011
|
||||
0:rx_hostname mpc2048
|
||||
0:flippeddatax 0
|
||||
|
||||
#bottom
|
||||
1:rx_tcpport 1955
|
||||
1:lock 0
|
||||
1:rx_udpport 50004
|
||||
1:rx_udpport2 50005
|
||||
1:rx_hostname mpc2048
|
||||
1:flippeddatax 1
|
||||
|
||||
settingsdir /home/l_frojdh/slsDetectorPackage/settingsdir/eiger
|
||||
outdir /home/l_frojdh/out
|
||||
vthreshold 1500
|
||||
vtr 4000
|
||||
dr 32
|
||||
|
||||
threaded 1
|
||||
tengiga 0
|
||||
vhighvoltage 150
|
||||
iodelay 660
|
||||
|
||||
#gappixels 1
|
2
python/simple-integration-tests/eiger/test.par
Normal file
2
python/simple-integration-tests/eiger/test.par
Normal file
@ -0,0 +1,2 @@
|
||||
vrf 3000
|
||||
vthreshold 1800
|
44
python/simple-integration-tests/eiger/test_dynamic_range.py
Normal file
44
python/simple-integration-tests/eiger/test_dynamic_range.py
Normal file
@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Testing setting dynamic range for Eiger.
|
||||
If the detector is not Eiger the tests are skipped
|
||||
"""
|
||||
import pytest
|
||||
import config_test
|
||||
from fixtures import detector, eiger, jungfrau, eigertest, jungfrautest
|
||||
from sls_detector.errors import DetectorValueError
|
||||
|
||||
|
||||
@eigertest
|
||||
def test_set_dynamic_range_and_make_acq(eiger):
|
||||
eiger.exposure_time = 0.5
|
||||
eiger.n_frames = 2
|
||||
for dr in [4, 8, 16, 32]:
|
||||
eiger.dynamic_range = dr
|
||||
assert eiger.dynamic_range == dr
|
||||
eiger.acq()
|
||||
assert eiger.frames_caught == 2
|
||||
|
||||
|
||||
@eigertest
|
||||
def test_set_dynamic_range_raises(eiger):
|
||||
with pytest.raises(DetectorValueError):
|
||||
eiger.dynamic_range = 1
|
||||
with pytest.raises(DetectorValueError):
|
||||
eiger.dynamic_range = 75
|
||||
with pytest.raises(DetectorValueError):
|
||||
eiger.dynamic_range = -3
|
||||
with pytest.raises(DetectorValueError):
|
||||
eiger.dynamic_range = 12
|
||||
|
||||
@eigertest
|
||||
def test_set_dynamic_range_reduces_speed(eiger):
|
||||
eiger.readout_clock = 'Full Speed'
|
||||
eiger.dynamic_range = 32
|
||||
assert eiger.dynamic_range == 32
|
||||
assert eiger.readout_clock == 'Quarter Speed'
|
||||
|
||||
eiger.dynamic_range = 16
|
||||
assert eiger.dynamic_range == 16
|
||||
assert eiger.readout_clock == 'Half Speed'
|
119
python/simple-integration-tests/eiger/test_eiger_specific.py
Normal file
119
python/simple-integration-tests/eiger/test_eiger_specific.py
Normal file
@ -0,0 +1,119 @@
|
||||
import pytest
|
||||
import config_test
|
||||
import time
|
||||
from sls_detector.errors import DetectorValueError
|
||||
|
||||
from fixtures import eiger, eigertest
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@eigertest
|
||||
def test_set_matrix_reset(eiger):
|
||||
eiger.eiger_matrix_reset = False
|
||||
assert eiger.eiger_matrix_reset == False
|
||||
eiger.eiger_matrix_reset = True
|
||||
assert eiger.eiger_matrix_reset == True
|
||||
|
||||
@eigertest
|
||||
def test_set_tx_delay_left_single(eiger):
|
||||
eiger.tx_delay.left[0] = 130
|
||||
assert eiger.tx_delay.left[0] == 130
|
||||
eiger.tx_delay.left[1] = 150
|
||||
assert eiger.tx_delay.left[1] == 150
|
||||
eiger.tx_delay.left[0] = 0
|
||||
eiger.tx_delay.left[1] = 0
|
||||
assert eiger.tx_delay.left[0] == 0
|
||||
assert eiger.tx_delay.left[1] == 0
|
||||
|
||||
@eigertest
|
||||
def test_set_tx_delay_right_single(eiger):
|
||||
eiger.tx_delay.right[0] = 130
|
||||
assert eiger.tx_delay.right[0] == 130
|
||||
eiger.tx_delay.right[1] = 150
|
||||
assert eiger.tx_delay.right[1] == 150
|
||||
eiger.tx_delay.right[0] = 0
|
||||
eiger.tx_delay.right[1] = 0
|
||||
assert eiger.tx_delay.right[0] == 0
|
||||
assert eiger.tx_delay.right[1] == 0
|
||||
|
||||
@eigertest
|
||||
def test_set_tx_delay_frame_single(eiger):
|
||||
eiger.tx_delay.frame[0] = 500
|
||||
eiger.tx_delay.frame[1] = 600
|
||||
assert eiger.tx_delay.frame[0] == 500
|
||||
assert eiger.tx_delay.frame[1] == 600
|
||||
|
||||
eiger.tx_delay.frame[0] = 0
|
||||
eiger.tx_delay.frame[1] = 0
|
||||
assert eiger.tx_delay.frame[0] == 0
|
||||
assert eiger.tx_delay.frame[1] == 0
|
||||
|
||||
@eigertest
|
||||
def test_tx_delay_from_list(eiger):
|
||||
eiger.tx_delay.left = [123,456]
|
||||
assert eiger.tx_delay.left[:] == [123,456]
|
||||
eiger.tx_delay.right = [789,100]
|
||||
assert eiger.tx_delay.right[:] == [789,100]
|
||||
eiger.tx_delay.frame = [1000,90000]
|
||||
assert eiger.tx_delay.frame[:] == [1000,90000]
|
||||
|
||||
eiger.tx_delay.left = [0, 0]
|
||||
eiger.tx_delay.right = [0, 0]
|
||||
eiger.tx_delay.frame = [0, 0]
|
||||
assert eiger.tx_delay.left[:] == [0, 0]
|
||||
assert eiger.tx_delay.right[:] == [0, 0]
|
||||
assert eiger.tx_delay.frame[:] == [0, 0]
|
||||
|
||||
@eigertest
|
||||
def test_acitve(eiger):
|
||||
eiger.file_write = False
|
||||
eiger.reset_frames_caught()
|
||||
eiger.active[1] = False
|
||||
eiger.acq()
|
||||
assert eiger._api.getFramesCaughtByReceiver(1) == 0
|
||||
assert eiger._api.getFramesCaughtByReceiver(0) == 1
|
||||
eiger.active = True
|
||||
time.sleep(0.5)
|
||||
eiger.acq()
|
||||
assert eiger.frames_caught == 1
|
||||
|
||||
@eigertest
|
||||
def test_set_default_settings(eiger):
|
||||
eiger.default_settings()
|
||||
assert eiger.n_frames == 1
|
||||
assert eiger.exposure_time == 1
|
||||
assert eiger.period == 0
|
||||
assert eiger.n_cycles == 1
|
||||
assert eiger.dynamic_range == 16
|
||||
|
||||
@eigertest
|
||||
def test_flowcontrol10g(eiger):
|
||||
eiger.flowcontrol_10g = True
|
||||
assert eiger.flowcontrol_10g == True
|
||||
eiger.flowcontrol_10g = False
|
||||
assert eiger.flowcontrol_10g == False
|
||||
|
||||
@eigertest
|
||||
def test_read_vcmp(eiger):
|
||||
eiger.vthreshold = 1500
|
||||
assert eiger.vcmp[:] == [1500]*4*eiger.n_modules
|
||||
|
||||
@eigertest
|
||||
def test_set_vcmp(eiger):
|
||||
eiger.vcmp = [1000,1100,1200,1300,1400,1500,1600,1700]
|
||||
assert eiger.vcmp[:] == [1000,1100,1200,1300,1400,1500,1600,1700]
|
||||
eiger.vthreshold = 1500
|
||||
|
||||
#Disabled only works with receiver on the same pc
|
||||
# @eigertest
|
||||
# def test_setup500k():
|
||||
# from sls_detector import Eiger, free_shared_memory
|
||||
# free_shared_memory()
|
||||
# d = Eiger()
|
||||
# d.setup500k(config_test.known_hostnames)
|
||||
# d.acq()
|
||||
# assert d.rx_tcpport == [1954,1955]
|
||||
# assert d.frames_caught == 1
|
||||
# #could assert more setting but if the frame is caught it worked...
|
128
python/simple-integration-tests/eiger/test_firmware.py
Normal file
128
python/simple-integration-tests/eiger/test_firmware.py
Normal file
@ -0,0 +1,128 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Tests specific for the firmware.
|
||||
|
||||
Check that register values are correct after starting an exposure
|
||||
|
||||
0x4 exposure time
|
||||
0x5 period
|
||||
0x6 sub exposure time
|
||||
|
||||
"""
|
||||
import pytest
|
||||
import config_test
|
||||
from fixtures import detector, eiger, jungfrau, eigertest, jungfrautest
|
||||
from sls_detector.errors import DetectorValueError
|
||||
from sls_detector.utils import eiger_register_to_time
|
||||
|
||||
# testdata_exptimes = [0.001, 0.002, 0.0236]
|
||||
|
||||
@eigertest
|
||||
def test_short_exposure_time(eiger):
|
||||
t = 1.23
|
||||
eiger.exposure_time = t
|
||||
eiger.file_write = False
|
||||
eiger.start_detector()
|
||||
eiger.stop_detector()
|
||||
|
||||
#Register 0x4 holds exposure time
|
||||
reg = eiger.register[0x4]
|
||||
assert pytest.approx(t, 1e-9) == eiger_register_to_time(reg)
|
||||
|
||||
@eigertest
|
||||
def test_short_minimal_exposure_time(eiger):
|
||||
t = 1e-8
|
||||
eiger.exposure_time = t
|
||||
eiger.file_write = False
|
||||
eiger.start_detector()
|
||||
eiger.stop_detector()
|
||||
|
||||
#Register 0x4 holds exposure time
|
||||
reg = eiger.register[0x4]
|
||||
assert pytest.approx(t, 1e-9) == eiger_register_to_time(reg)
|
||||
|
||||
|
||||
@eigertest
|
||||
def test_long_exposure_time(eiger):
|
||||
t = 623
|
||||
eiger.exposure_time = t
|
||||
eiger.file_write = False
|
||||
eiger.start_detector()
|
||||
eiger.stop_detector()
|
||||
|
||||
# Register 0x4 holds exposure time
|
||||
reg = eiger.register[0x4]
|
||||
assert pytest.approx(t, 1e-9) == eiger_register_to_time(reg)
|
||||
|
||||
|
||||
@eigertest
|
||||
def test_short_period(eiger):
|
||||
t = 0.1
|
||||
eiger.exposure_time = 0.001
|
||||
eiger.period = t
|
||||
eiger.file_write = False
|
||||
eiger.start_detector()
|
||||
eiger.stop_detector()
|
||||
|
||||
# Register 0x5 holds period
|
||||
reg = eiger.register[0x5]
|
||||
assert pytest.approx(t, 1e-9) == eiger_register_to_time(reg)
|
||||
|
||||
|
||||
@eigertest
|
||||
def test_long_period(eiger):
|
||||
t = 8900
|
||||
eiger.exposure_time = 0.001
|
||||
eiger.period = t
|
||||
eiger.file_write = False
|
||||
eiger.start_detector()
|
||||
eiger.stop_detector()
|
||||
|
||||
# Register 0x5 holds period
|
||||
reg = eiger.register[0x5]
|
||||
assert pytest.approx(t, 1e-9) == eiger_register_to_time(reg)
|
||||
|
||||
@eigertest
|
||||
def test_zero_period_with_acq(eiger):
|
||||
t = 0
|
||||
eiger.exposure_time = 0.001
|
||||
eiger.period = t
|
||||
eiger.file_write = False
|
||||
eiger.acq()
|
||||
|
||||
# Register 0x5 holds period
|
||||
reg = eiger.register[0x5]
|
||||
assert pytest.approx(t, 1e-9) == eiger_register_to_time(reg)
|
||||
|
||||
|
||||
testdata_times = [0.001, 0.002, 0.0236]
|
||||
@eigertest
|
||||
@pytest.mark.parametrize("t", testdata_times)
|
||||
def test_subexptime(eiger,t):
|
||||
eiger.sub_exposure_time = t
|
||||
eiger.file_write = False
|
||||
eiger.start_detector()
|
||||
eiger.stop_detector()
|
||||
|
||||
# Register 0x6 holds sub exposure time
|
||||
# time is stored straight as n clocks
|
||||
reg = eiger.register[0x6]
|
||||
assert pytest.approx(t, 1e-9) == reg/100e6
|
||||
|
||||
|
||||
@eigertest
|
||||
@pytest.mark.parametrize("t", testdata_times)
|
||||
def test_subdeadtime(eiger, t):
|
||||
eiger.sub_deadtime = t
|
||||
eiger.sub_exposure_time = 1
|
||||
eiger.sub_exposure_time = 0.001
|
||||
eiger.file_write = False
|
||||
eiger.start_detector()
|
||||
eiger.stop_detector()
|
||||
|
||||
# Register 0x7 holds sub period
|
||||
# time is stored straight as n clocks
|
||||
# exptime+deadtime
|
||||
reg = eiger.register[0x7]
|
||||
assert pytest.approx(t, 1e-7) == (reg/100e6-0.001)
|
187
python/simple-integration-tests/eiger/test_general.py
Normal file
187
python/simple-integration-tests/eiger/test_general.py
Normal file
@ -0,0 +1,187 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
General tests for the Detector class. Should not depend on the connected detector. Aim is to have tests working
|
||||
for both Jungfrau and Eiger.
|
||||
|
||||
NOTE! Uses hostnames from config_test
|
||||
"""
|
||||
|
||||
import pytest
|
||||
import config_test
|
||||
from fixtures import detector
|
||||
from sls_detector.errors import DetectorValueError, DetectorError
|
||||
|
||||
|
||||
|
||||
def test_error_handling(detector):
|
||||
with pytest.raises(DetectorError):
|
||||
detector._provoke_error()
|
||||
|
||||
def test_not_busy(detector):
|
||||
"""Test that the detector is not busy from the start"""
|
||||
assert detector.busy == False
|
||||
|
||||
def test_reset_frames_caught(detector):
|
||||
detector.file_write = False
|
||||
detector.acq()
|
||||
assert detector.frames_caught == 1
|
||||
detector.reset_frames_caught()
|
||||
assert detector.frames_caught == 0
|
||||
|
||||
def test_set_busy_true_then_false(detector):
|
||||
"""Test both cases of assignment"""
|
||||
detector.busy = True
|
||||
assert detector.busy == True
|
||||
detector.busy = False
|
||||
assert detector.busy == False
|
||||
|
||||
def test_set_readout_speed(detector):
|
||||
for s in ['Full Speed', 'Half Speed', 'Quarter Speed', 'Super Slow Speed']:
|
||||
detector.readout_clock = s
|
||||
assert detector.readout_clock == s
|
||||
|
||||
def test_wrong_speed_raises_error(detector):
|
||||
with pytest.raises(KeyError):
|
||||
detector.readout_clock = 'Something strange'
|
||||
|
||||
def test_readout_clock_remains(detector):
|
||||
s = detector.readout_clock
|
||||
try:
|
||||
detector.readout_clock = 'This does not exists'
|
||||
except KeyError:
|
||||
pass
|
||||
assert detector.readout_clock == s
|
||||
|
||||
def test_len_method(detector):
|
||||
"""to test this we need to know the length, this we get from the configuration of hostnames"""
|
||||
assert len(detector) == len(config_test.known_hostnames)
|
||||
|
||||
def test_setting_n_cycles_to_zero_gives_error(detector):
|
||||
with pytest.raises(DetectorValueError):
|
||||
detector.n_cycles = 0
|
||||
|
||||
def test_setting_n_cycles_to_negative_gives_error(detector):
|
||||
with pytest.raises(DetectorValueError):
|
||||
detector.n_cycles = -50
|
||||
|
||||
def test_set_cycles_frome_one_to_ten(detector):
|
||||
for i in range(1,11):
|
||||
detector.n_cycles = i
|
||||
assert detector.n_cycles == i
|
||||
detector.n_cycles = 1
|
||||
assert detector.n_cycles == 1
|
||||
|
||||
def test_get_detector_type(detector):
|
||||
assert detector.detector_type == config_test.detector_type
|
||||
|
||||
|
||||
|
||||
def test_set_file_index(detector):
|
||||
detector.file_index = 5
|
||||
assert detector.file_index == 5
|
||||
|
||||
def test_negative_file_index_raises(detector):
|
||||
with pytest.raises(ValueError):
|
||||
detector.file_index = -8
|
||||
|
||||
def test_setting_file_name(detector):
|
||||
fname = 'hej'
|
||||
detector.file_name = fname
|
||||
assert detector.file_name == fname
|
||||
|
||||
def test_set_file_write(detector):
|
||||
detector.file_write = True
|
||||
assert detector.file_write == True
|
||||
|
||||
detector.file_write = False
|
||||
assert detector.file_write == False
|
||||
|
||||
|
||||
|
||||
def test_set_high_voltage(detector):
|
||||
detector.high_voltage = 55
|
||||
assert detector.high_voltage == 55
|
||||
|
||||
def test_negative_voltage_raises(detector):
|
||||
with pytest.raises(DetectorValueError):
|
||||
detector.high_voltage = -5
|
||||
|
||||
def test_high_voltage_raises_on_to_high(detector):
|
||||
with pytest.raises(DetectorValueError):
|
||||
detector.high_voltage = 500
|
||||
|
||||
|
||||
|
||||
def test_get_image_size(detector):
|
||||
"""Compares with the size in the config file"""
|
||||
assert detector.image_size.rows == config_test.image_size[0]
|
||||
assert detector.image_size.cols == config_test.image_size[1]
|
||||
|
||||
def test_get_module_geometry(detector):
|
||||
"""Compares with the size in the config file"""
|
||||
assert detector.module_geometry.horizontal == config_test.module_geometry[0]
|
||||
assert detector.module_geometry.vertical == config_test.module_geometry[1]
|
||||
|
||||
def test_set_nframes(detector):
|
||||
detector.n_frames = 5
|
||||
assert detector.n_frames == 5
|
||||
detector.n_frames = 1
|
||||
assert detector.n_frames == 1
|
||||
|
||||
def test_set_n_measurements(detector):
|
||||
detector.n_measurements = 7
|
||||
assert detector.n_measurements == 7
|
||||
detector.n_measurements = 1
|
||||
assert detector.n_measurements == 1
|
||||
|
||||
def test_negative_nframes_raises(detector):
|
||||
with pytest.raises(DetectorValueError):
|
||||
detector.n_frames = -2
|
||||
|
||||
def test_nmodules(detector):
|
||||
"""Assume that the number of modules should be the same as the number of hostnames"""
|
||||
assert detector.n_modules == len(config_test.known_hostnames)
|
||||
|
||||
def test_is_detector_online(detector):
|
||||
assert detector.online == True
|
||||
|
||||
def test_set_online(detector):
|
||||
detector.online = False
|
||||
assert detector.online == False
|
||||
detector.online = True
|
||||
assert detector.online == True
|
||||
|
||||
|
||||
|
||||
def test_receiver_is_online(detector):
|
||||
assert detector.receiver_online == True
|
||||
|
||||
def test_set_receiver_online(detector):
|
||||
detector.receiver_online = False
|
||||
assert detector.receiver_online == False
|
||||
detector.receiver_online = True
|
||||
assert detector.receiver_online == True
|
||||
|
||||
def test_set_receiver_online_raises_on_non_bool(detector):
|
||||
with pytest.raises(TypeError):
|
||||
detector.receiver_online = 'probably not this'
|
||||
|
||||
|
||||
|
||||
|
||||
def test_set_period(detector):
|
||||
detector.period = 5.123
|
||||
assert detector.period == 5.123
|
||||
detector.period = 0
|
||||
assert detector.period == 0
|
||||
|
||||
|
||||
|
||||
def test_set_timing_mode(detector):
|
||||
detector.timing_mode = 'trigger'
|
||||
assert detector.timing_mode == 'trigger'
|
||||
detector.timing_mode = 'auto'
|
||||
assert detector.timing_mode == 'auto'
|
||||
|
||||
|
38
python/simple-integration-tests/eiger/test_load_config.py
Normal file
38
python/simple-integration-tests/eiger/test_load_config.py
Normal file
@ -0,0 +1,38 @@
|
||||
|
||||
import pytest
|
||||
import config_test
|
||||
import os
|
||||
dir_path = os.path.dirname(os.path.realpath(__file__))
|
||||
from sls_detector.detector import element_if_equal
|
||||
from sls_detector.errors import DetectorValueError
|
||||
|
||||
|
||||
from fixtures import eiger, eigertest
|
||||
|
||||
|
||||
@eigertest
|
||||
def test_load_config_file_eiger(eiger):
|
||||
"""Load a settings file and assert all settings"""
|
||||
eiger.load_config(os.path.join(dir_path, 'test.config'))
|
||||
|
||||
|
||||
assert eiger.rx_tcpport == [1954, 1955]
|
||||
assert eiger.lock == False
|
||||
assert eiger.rx_udpport == [50010, 50011, 50004, 50005]
|
||||
assert eiger.rx_hostname == 'mpc2048'
|
||||
assert eiger.flipped_data_x[:] == [False, True]
|
||||
assert eiger.settings_path == config_test.settings_path
|
||||
assert eiger.file_path == config_test.file_path
|
||||
assert eiger.vthreshold == 1500
|
||||
assert element_if_equal(eiger.dacs.vtr[:]) == 4000
|
||||
assert eiger.dynamic_range == 32
|
||||
assert eiger.tengiga == False
|
||||
assert eiger.high_voltage == 150
|
||||
assert element_if_equal(eiger.dacs.iodelay[:]) == 660
|
||||
|
||||
@eigertest
|
||||
def test_load_parameters_file_eiger(eiger):
|
||||
"""Load a parametes file and assert the settings in the file"""
|
||||
eiger.load_parameters(os.path.join(dir_path, 'test.par'))
|
||||
assert element_if_equal(eiger.dacs.vrf[:]) == 3000
|
||||
assert eiger.vthreshold == 1800
|
81
python/simple-integration-tests/eiger/test_network.py
Normal file
81
python/simple-integration-tests/eiger/test_network.py
Normal file
@ -0,0 +1,81 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Tests for network related functions of the detector
|
||||
"""
|
||||
import pytest
|
||||
import config_test
|
||||
from fixtures import eiger, eigertest, detector
|
||||
|
||||
|
||||
# def test_last_client(detector):
|
||||
# import socket
|
||||
# # We probably should check for multiple ip's
|
||||
# myip = socket.gethostbyname_ex(socket.gethostname())[-1][0]
|
||||
# assert detector.last_client_ip == myip
|
||||
|
||||
def test_get_hostname(detector):
|
||||
for detector_host, config_host in zip(detector.hostname, config_test.known_hostnames):
|
||||
assert detector_host == config_host
|
||||
|
||||
def test_hostname_has_same_length_as_n_modules(detector):
|
||||
assert len(detector.hostname) == detector.n_modules
|
||||
|
||||
|
||||
# # def test_get_receiver_hostname(detector):
|
||||
# # """Assume that the receiver are on the local computer"""
|
||||
# # import socket
|
||||
# # host = socket.gethostname().split('.')[0]
|
||||
# # assert detector.rx_hostname == host
|
||||
|
||||
# def test_set_receiver_hostname(detector):
|
||||
# import socket
|
||||
# host = socket.gethostname().split('.')[0]
|
||||
# phony_host = 'madeup'
|
||||
# detector.rx_hostname = phony_host
|
||||
# assert detector.rx_hostname == phony_host
|
||||
# detector.rx_hostname = host
|
||||
# assert detector.rx_hostname == host
|
||||
|
||||
@eigertest
|
||||
def test_set_rx_zmqport_single_value(eiger):
|
||||
eiger.rx_zmqport = 35000
|
||||
assert eiger.rx_zmqport == [35000, 35001, 35002, 35003]
|
||||
|
||||
@eigertest
|
||||
def test_set_rx_zmqport_list(eiger):
|
||||
eiger.rx_zmqport = [37000, 38000]
|
||||
assert eiger.rx_zmqport == [37000, 37001, 38000, 38001]
|
||||
|
||||
@eigertest
|
||||
def test_set_rx_updport(eiger):
|
||||
ports = [60010,60011,60012,60013]
|
||||
eiger.rx_udpport = ports
|
||||
assert eiger.rx_udpport == ports
|
||||
eiger.acq()
|
||||
assert eiger.frames_caught == 1
|
||||
|
||||
@eigertest
|
||||
def test_rx_tcpport(eiger):
|
||||
ports = eiger.rx_tcpport
|
||||
eiger.rx_tcpport = [2000,2001]
|
||||
assert eiger.rx_tcpport == [2000,2001]
|
||||
eiger.rx_tcpport = ports
|
||||
assert eiger.rx_tcpport == ports
|
||||
eiger.acq()
|
||||
assert eiger.frames_caught == 1
|
||||
|
||||
@eigertest
|
||||
@pytest.mark.new
|
||||
def test_enable_disable_tengiga(eiger):
|
||||
"""
|
||||
This test does not check for dat on the 10Gbit link, only the set and get functions
|
||||
"""
|
||||
eiger.tengiga = True
|
||||
assert eiger.tengiga == True
|
||||
eiger.tengiga = False
|
||||
assert eiger.tengiga == False
|
||||
|
||||
|
||||
|
||||
#TODO! Add test for Jungfrau
|
@ -0,0 +1,54 @@
|
||||
import pytest
|
||||
import config_test
|
||||
from fixtures import detector, eiger, jungfrau, eigertest, jungfrautest
|
||||
from sls_detector.errors import DetectorValueError
|
||||
|
||||
|
||||
|
||||
|
||||
@eigertest
|
||||
@pytest.mark.local
|
||||
def test_set_path(eiger, tmpdir):
|
||||
import os
|
||||
path = os.path.join(tmpdir.dirname, tmpdir.basename)
|
||||
eiger.file_path = path
|
||||
assert eiger.file_path == path
|
||||
|
||||
@eigertest
|
||||
@pytest.mark.local
|
||||
def test_set_path_and_write_files(eiger, tmpdir):
|
||||
import os
|
||||
prefix = 'testprefix'
|
||||
path = os.path.join(tmpdir.dirname, tmpdir.basename)
|
||||
eiger.file_path = path
|
||||
eiger.file_write = True
|
||||
eiger.exposure_time = 0.1
|
||||
eiger.n_frames = 1
|
||||
eiger.timing_mode = 'auto'
|
||||
eiger.file_name = prefix
|
||||
eiger.file_index = 0
|
||||
eiger.acq()
|
||||
|
||||
files = [f.basename for f in tmpdir.listdir()]
|
||||
|
||||
assert len(files) == 5
|
||||
assert (prefix+'_d0_0.raw' in files) == True
|
||||
assert (prefix+'_d1_0.raw' in files) == True
|
||||
assert (prefix+'_d2_0.raw' in files) == True
|
||||
assert (prefix+'_d3_0.raw' in files) == True
|
||||
|
||||
def test_set_discard_policy(detector):
|
||||
detector.frame_discard_policy = 'nodiscard'
|
||||
assert detector.frame_discard_policy == 'nodiscard'
|
||||
detector.frame_discard_policy = 'discardpartial'
|
||||
assert detector.frame_discard_policy == 'discardpartial'
|
||||
detector.frame_discard_policy = 'discardempty'
|
||||
assert detector.frame_discard_policy == 'discardempty'
|
||||
|
||||
def test_set_discard_policy_raises(detector):
|
||||
with pytest.raises(ValueError):
|
||||
detector.frame_discard_policy = 'adjfvadksvsj'
|
||||
|
||||
def test_set_frames_perfile(detector):
|
||||
detector.frames_per_file = 5000
|
||||
assert detector.frames_per_file == 5000
|
47
python/simple-integration-tests/eiger/test_threshold.py
Normal file
47
python/simple-integration-tests/eiger/test_threshold.py
Normal file
@ -0,0 +1,47 @@
|
||||
import pytest
|
||||
import config_test
|
||||
import time
|
||||
from sls_detector.errors import DetectorValueError
|
||||
import os
|
||||
from fixtures import eiger, eigertest
|
||||
|
||||
|
||||
testdata_th = [0,333,500,1750,2000]
|
||||
|
||||
@eigertest
|
||||
@pytest.mark.parametrize("th", testdata_th)
|
||||
def test_set_vthreshold(eiger, th):
|
||||
eiger.vthreshold = th
|
||||
assert eiger.vthreshold == th
|
||||
|
||||
@eigertest
|
||||
def test_vthreshold_with_different_vcmp(eiger):
|
||||
#When vcmp is different for the chip vthreshold should return -1
|
||||
eiger.vthreshold = 1500
|
||||
eiger.dacs.vcmp_ll = 1400
|
||||
assert eiger.vthreshold == -1
|
||||
|
||||
@eigertest
|
||||
def test_set_settingsdir(eiger):
|
||||
path = os.path.dirname( os.path.realpath(__file__) )
|
||||
path = os.path.join(path, 'settingsdir')
|
||||
eiger.settings_path = path
|
||||
assert eiger.settings_path == path
|
||||
|
||||
@eigertest
|
||||
def test_set_trimmed_energies(eiger):
|
||||
en = [5000,6000,7000]
|
||||
eiger.trimmed_energies = en
|
||||
assert eiger.trimmed_energies == en
|
||||
|
||||
|
||||
#TODO! add checks for vcmp as well and improve naming
|
||||
#TODO! remove dependency on beb number
|
||||
testdata_en = [(5000, 500),(5500,750),(6000,1000),(6200,1100),(7000,1500)]
|
||||
@eigertest
|
||||
@pytest.mark.parametrize('val', testdata_en)
|
||||
def test_set_energy_threshold(eiger, val):
|
||||
eiger.settings = 'standard'
|
||||
eiger.threshold = val[0]
|
||||
assert eiger.threshold == val[0]
|
||||
assert eiger.dacs.vrf[0] == val[1]
|
136
python/simple-integration-tests/eiger/test_time.py
Normal file
136
python/simple-integration-tests/eiger/test_time.py
Normal file
@ -0,0 +1,136 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Tests regarding exposure time and period of the detector
|
||||
Set and get test as well as test for duration and on detector
|
||||
measurement of the time.
|
||||
"""
|
||||
import pytest
|
||||
import config_test
|
||||
from fixtures import detector, eiger, jungfrau, eigertest, jungfrautest
|
||||
from sls_detector.errors import DetectorValueError, DetectorError
|
||||
import time
|
||||
|
||||
|
||||
testdata_times = [1e-8, 0.001, 0.5, 3.125, 5.0, 600, 784]
|
||||
@pytest.mark.parametrize("t", testdata_times)
|
||||
def test_set_and_get_exposure_time(eiger, t):
|
||||
"""
|
||||
Test that the exposure time we set in the detector
|
||||
is the same as the one read back
|
||||
"""
|
||||
eiger.exposure_time = t
|
||||
assert eiger.exposure_time == t
|
||||
|
||||
|
||||
def test_negative_exposure_time_raises_error(eiger):
|
||||
with pytest.raises(DetectorValueError):
|
||||
eiger.exposure_time = -15
|
||||
|
||||
|
||||
testdata_times = [0.001, 0.0025, 0.005, 5]
|
||||
@pytest.mark.parametrize("t", testdata_times)
|
||||
def test_set_subexptime(eiger, t):
|
||||
eiger.sub_exposure_time = t
|
||||
assert eiger.sub_exposure_time == t
|
||||
|
||||
|
||||
testdata_times = [-5,6,7,50]
|
||||
@pytest.mark.parametrize("t", testdata_times)
|
||||
def test_set_subextime_too_large_or_neg(eiger, t):
|
||||
with pytest.raises((DetectorError, DetectorValueError)):
|
||||
eiger.sub_exposure_time = t
|
||||
|
||||
|
||||
|
||||
testdata_times = [0.2, 0.5, 1, 2, 5, 7]
|
||||
@pytest.mark.slow
|
||||
@pytest.mark.parametrize("t", testdata_times)
|
||||
def test_measure_exposure_time_from_python(eiger, t):
|
||||
"""
|
||||
The main idea with this test is to make sure the overhead of a
|
||||
single acq is less than tol[s]. This test also catches stupid bugs
|
||||
that would for example not change the exposure time or make acquire
|
||||
not blocking.
|
||||
"""
|
||||
tol = 0.5
|
||||
eiger.dynamic_range = 16
|
||||
eiger.file_write = False
|
||||
eiger.n_frames = 1
|
||||
eiger.exposure_time = t
|
||||
assert eiger.exposure_time == t
|
||||
t0 = time.time()
|
||||
eiger.acq()
|
||||
duration = time.time()-t0
|
||||
assert duration < (t+tol)
|
||||
|
||||
|
||||
testdata_times = [0.5, 1, 3, 5]
|
||||
|
||||
|
||||
@pytest.mark.slow
|
||||
@pytest.mark.parametrize("t", testdata_times)
|
||||
def test_measure_period_from_python_and_detector(eiger, t):
|
||||
tol = 0.5
|
||||
nframes = 5
|
||||
eiger.dynamic_range = 16
|
||||
eiger.file_write = False
|
||||
eiger.n_frames = nframes
|
||||
eiger.exposure_time = 0.001
|
||||
eiger.period = t
|
||||
t0 = time.time()
|
||||
eiger.acq()
|
||||
duration = time.time()-t0
|
||||
assert duration < t*(nframes-1)+tol
|
||||
for mp in eiger.measured_period:
|
||||
assert pytest.approx(mp, 1e-5) == t
|
||||
|
||||
|
||||
testdata_times = [0.001, 0.002, 0.003, 0.005, 0.01]
|
||||
@pytest.mark.parametrize("t", testdata_times)
|
||||
def test_measure_subperiod_nonparallel(eiger, t):
|
||||
readout_time = 500e-6
|
||||
eiger.dynamic_range = 32
|
||||
eiger.file_write = False
|
||||
eiger.flags = 'nonparallel'
|
||||
eiger.n_frames = 1
|
||||
eiger.period = 0
|
||||
eiger.exposure_time = 0.5
|
||||
eiger.sub_exposure_time = t
|
||||
eiger.sub_deadtime = 0
|
||||
eiger.acq()
|
||||
for mp in eiger.measured_subperiod:
|
||||
assert pytest.approx(mp, abs=1e-5) == t+readout_time
|
||||
|
||||
|
||||
@pytest.mark.parametrize("t", testdata_times)
|
||||
def test_measure_subperiod_parallel(eiger, t):
|
||||
readout_time = 12e-6
|
||||
eiger.dynamic_range = 32
|
||||
eiger.file_write = False
|
||||
eiger.flags = 'parallel'
|
||||
eiger.n_frames = 1
|
||||
eiger.period = 0
|
||||
eiger.exposure_time = 0.5
|
||||
eiger.sub_exposure_time = t
|
||||
eiger.sub_deadtime = 0
|
||||
eiger.acq()
|
||||
for mp in eiger.measured_subperiod:
|
||||
assert pytest.approx(mp, abs=1e-5) == t+readout_time
|
||||
|
||||
|
||||
@pytest.mark.parametrize("t", testdata_times)
|
||||
def test_measure_subperiod_parallel_when_changing_deadtime(eiger, t):
|
||||
readout_time = 12e-6
|
||||
exposure_time = 0.001
|
||||
eiger.dynamic_range = 32
|
||||
eiger.file_write = False
|
||||
eiger.flags = 'parallel'
|
||||
eiger.n_frames = 1
|
||||
eiger.period = 0
|
||||
eiger.exposure_time = 0.5
|
||||
eiger.sub_exposure_time = exposure_time
|
||||
eiger.sub_deadtime = t
|
||||
eiger.acq()
|
||||
for mp in eiger.measured_subperiod:
|
||||
assert pytest.approx(mp, abs=1e-5) == t+exposure_time
|
@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Tests for trimbit and dac related functions
|
||||
"""
|
||||
import pytest
|
||||
import config_test
|
||||
from fixtures import detector, eiger, jungfrau, eigertest, jungfrautest
|
||||
from sls_detector.errors import DetectorValueError
|
||||
|
||||
|
||||
@eigertest
|
||||
def test_set_trimbits(eiger):
|
||||
"""Limited values due to time"""
|
||||
for i in [17, 32, 60]:
|
||||
print(i)
|
||||
eiger.trimbits = i
|
||||
assert eiger.trimbits == i
|
||||
|
||||
@eigertest
|
||||
def test_set_trimbits_raises_on_too_big(eiger):
|
||||
with pytest.raises(DetectorValueError):
|
||||
eiger.trimbits = 75
|
||||
|
||||
@eigertest
|
||||
def test_set_trimbits_raises_on_negative(eiger):
|
||||
with pytest.raises(DetectorValueError):
|
||||
eiger.trimbits = -5
|
||||
|
||||
|
||||
# @jungfrautest
|
||||
# def test_jungfrau(jungfrau):
|
||||
# """Example of a test that is not run with Eiger connected"""
|
||||
# pass
|
@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Tests for hostname related functions of the detector
|
||||
"""
|
||||
import pytest
|
||||
import config_test
|
||||
from fixtures import detector, eiger, jungfrau, eigertest, jungfrautest
|
||||
from sls_detector.errors import DetectorValueError
|
||||
|
||||
|
||||
|
||||
def test_firmware_version(detector):
|
||||
assert detector.firmware_version == config_test.fw_version
|
||||
|
||||
|
42
python/simple-integration-tests/eiger/write_tb_files.py
Normal file
42
python/simple-integration-tests/eiger/write_tb_files.py
Normal file
@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Tue May 22 14:13:48 2018
|
||||
|
||||
@author: l_frojdh
|
||||
"""
|
||||
import os
|
||||
from sls_detector_tools.io import write_trimbit_file
|
||||
from sls_detector_tools import mask
|
||||
|
||||
energy = [5000, 6000, 7000]
|
||||
vrf = [500, 1000, 1500]
|
||||
|
||||
for i,e in enumerate(energy):
|
||||
dacs = np.array( [[ 0., 0.], #vsvp
|
||||
[4000., 4000.], #vtr
|
||||
[vrf[i], vrf[i]], #vrf
|
||||
[1400., 1400.], #vrs
|
||||
[4000., 4000.], #vsvn
|
||||
[2556., 2556.], #vtgstv
|
||||
[1400., 1400.], #vcmp_ll
|
||||
[1500., 1500.], #vcmp_lr
|
||||
[4000., 4000.], #vcall
|
||||
[1500., 1500.], #vcmp_rl
|
||||
[1100., 1100.], #rxb_rb
|
||||
[1100., 1100.], #rxb_lb
|
||||
[1500., 1500.], #vcmp_rr
|
||||
[1500., 1500.], #vcp
|
||||
[2000., 2000.], #vcn
|
||||
[1550., 1550.], #vis
|
||||
[ 660., 660.], #iodelay
|
||||
[ 0., 0.], #tau
|
||||
])
|
||||
|
||||
tb = np.zeros((256,1024))
|
||||
|
||||
for beb in [83,98]:
|
||||
write_trimbit_file(f'settingsdir/standard/{e}eV/noise.sn{beb:03d}', tb, dacs[:,0])
|
||||
#print(os.getcwd())
|
||||
|
||||
#print( os.path.realpath(__file__))
|
Reference in New Issue
Block a user