mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-12-21 12:01:19 +01:00
rx_roi also accepts sequence of 2 ints
This commit is contained in:
@@ -34,7 +34,7 @@ This document describes the differences between v10.0.1 and v10.0.0
|
||||
Python
|
||||
-------
|
||||
|
||||
* receiver ROI can be set from Python using command ``rx_roi``(it supports any sequence of four ints e.g. a tuple (xmin, xmax, ymin, ymax) or a sequence of such for multiple ROIS)
|
||||
* receiver ROI can be set from Python using command ``rx_roi``(it supports any sequence of four or two (for mythen3 and gotthard) ints e.g. a tuple (xmin, xmax, ymin, ymax) or a sequence of such for multiple ROIS)
|
||||
* one can clear all ROI's from Python using command ``rx_clearroi``
|
||||
|
||||
|
||||
|
||||
@@ -324,8 +324,9 @@ class Detector(CppDetectorApi):
|
||||
Note
|
||||
-----
|
||||
Each ROI should be represented as a sequence of 4 ints (x_start, y_start, x_end, y_end). \n
|
||||
For mythen3 or gotthard2 pass a sequence of 2 ints (x_start, x_end) \n
|
||||
For multiple ROI's pass a sequence of sequence \n
|
||||
Example: [[0, 100, 50, 100]] \n
|
||||
Example: [[0, 100, 50, 100], [260, 270, 50,100]] \n
|
||||
"""
|
||||
# TODO: maybe better to accept py::object in setRxROI and handle there?
|
||||
if not isinstance(rois, Sequence):
|
||||
|
||||
@@ -100,7 +100,8 @@ template <> struct type_caster<std::chrono::nanoseconds> {
|
||||
|
||||
// Type caster for sls::defs::ROI from tuple
|
||||
template <> struct type_caster<sls::defs::ROI> {
|
||||
PYBIND11_TYPE_CASTER(sls::defs::ROI, _("Sequence[int, int, int, int]"));
|
||||
PYBIND11_TYPE_CASTER(sls::defs::ROI, _("Sequence[int, int, int, int] or "
|
||||
"Sequence[int, int]"));
|
||||
|
||||
// convert c++ ROI to python tuple
|
||||
static handle cast(const sls::defs::ROI &roi, return_value_policy, handle) {
|
||||
@@ -118,7 +119,7 @@ template <> struct type_caster<sls::defs::ROI> {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (seq.size() != 4)
|
||||
if (seq.size() != 4 && seq.size() != 2)
|
||||
return false;
|
||||
// Check if each element is an int
|
||||
for (auto item : seq) {
|
||||
@@ -129,8 +130,12 @@ template <> struct type_caster<sls::defs::ROI> {
|
||||
|
||||
value.xmin = seq[0].cast<int>();
|
||||
value.xmax = seq[1].cast<int>();
|
||||
|
||||
if (seq.size() == 4) {
|
||||
value.ymin = seq[2].cast<int>();
|
||||
value.ymax = seq[3].cast<int>();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -38,8 +38,18 @@ def pytest_collection_modifyitems(config, items):
|
||||
if "withdetectorsimulators" in item.keywords:
|
||||
item.add_marker(skip)
|
||||
|
||||
#helper fixture for servers
|
||||
@pytest.fixture
|
||||
def test_with_simulators():
|
||||
def servers(request):
|
||||
try:
|
||||
return request.param # comes from @pytest.mark.parametrize(..., indirect=True)
|
||||
except AttributeError:
|
||||
# fallback default if the test did not parametrize
|
||||
return ['eiger', 'jungfrau', 'mythen3', 'gotthard2', 'ctb', 'moench', 'xilinx_ctb']
|
||||
return request.param
|
||||
|
||||
@pytest.fixture
|
||||
def test_with_simulators(servers):
|
||||
""" Fixture to automatically setup virtual detector servers for testing. """
|
||||
|
||||
LOG_PREFIX_FNAME = '/tmp/slsDetectorPackage_virtual_PythonAPI_test'
|
||||
@@ -47,7 +57,6 @@ def test_with_simulators():
|
||||
|
||||
with open(MAIN_LOG_FNAME, 'w') as fp:
|
||||
try:
|
||||
servers = ['moench']
|
||||
nmods = 2
|
||||
for server in servers:
|
||||
for ninterfaces in range(1,2):
|
||||
|
||||
@@ -6,8 +6,19 @@ from conftest import test_with_simulators
|
||||
from slsdet import Detector
|
||||
|
||||
@pytest.mark.withdetectorsimulators
|
||||
@pytest.mark.parametrize("servers", [["eiger"]], indirect=True)
|
||||
def test_rx_ROI(test_with_simulators):
|
||||
""" Test setting and getting rx_ROI property of Detector class. """
|
||||
""" Test setting and getting rx_ROI property of Detector class for moench. """
|
||||
|
||||
d = Detector()
|
||||
d.rx_roi = (0, 10, 10, 20)
|
||||
roi = d.rx_roi
|
||||
assert roi == [(0, 10, 10, 20)]
|
||||
|
||||
@pytest.mark.withdetectorsimulators
|
||||
@pytest.mark.parametrize("servers", [["moench"]], indirect=True)
|
||||
def test_rx_ROI_moench(test_with_simulators, servers):
|
||||
""" Test setting and getting rx_ROI property of Detector class for moench. """
|
||||
|
||||
d = Detector()
|
||||
d.rx_roi = (0, 10, 10, 20)
|
||||
@@ -27,4 +38,21 @@ def test_rx_ROI(test_with_simulators):
|
||||
roi = d.rx_roi
|
||||
assert roi == [(-1,-1,-1,-1)]
|
||||
|
||||
@pytest.mark.withdetectorsimulators
|
||||
@pytest.mark.parametrize("servers", [["mythen3"]], indirect=True)
|
||||
def test_rx_ROI_mythen(test_with_simulators, servers):
|
||||
""" Test setting and getting rx_ROI property of Detector class for mythen. """
|
||||
|
||||
d = Detector()
|
||||
d.rx_roi = (0, 10)
|
||||
roi = d.rx_roi
|
||||
assert roi == [(0, 10, -1, -1)]
|
||||
|
||||
#d.rx_roi = [[5,15, 0, 1]] # not allowed for mythen3
|
||||
|
||||
d.rx_roi = [0,10, -1, -1]
|
||||
|
||||
assert d.rx_roi == [(0,10,-1,-1)]
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -217,6 +217,7 @@ def loadConfig(name, rx_hostname = 'localhost', settingsdir = None, log_file_fp
|
||||
d.udp_dstport2 = DEFAULT_UDP_DST_PORTNO + 1
|
||||
|
||||
d.rx_hostname = rx_hostname
|
||||
|
||||
d.udp_dstip = 'auto'
|
||||
|
||||
if name != "eiger":
|
||||
|
||||
Reference in New Issue
Block a user