bindings for xy

This commit is contained in:
Erik Fröjdh
2026-10-04 09:54:55 +02:00
parent 6f5e6b4702
commit f2db33365e
7 changed files with 90 additions and 4 deletions
+1
View File
@@ -25,6 +25,7 @@ from ._aare import Pedestal_d, Pedestal_f, ClusterFinder_Cluster3x3i, VarCluster
from ._aare import DetectorType, FrameDiscardPolicy, ReadoutMode
from ._aare import hitmap
from ._aare import ROI
from ._aare import xy
from ._aare import corner
from ._aare import UDPPortPosition
+16
View File
@@ -1,4 +1,5 @@
// SPDX-License-Identifier: MPL-2.0
#include <pybind11/operators.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
@@ -74,6 +75,21 @@ void define_defs_bindings(py::module &m) {
self.ymin == other.ymin && self.ymax == other.ymax;
});
py::class_<xy>(m, "xy")
.def(py::init<uint32_t, uint32_t>(), py::arg("row"), py::arg("col"))
.def_readwrite("row", &xy::row)
.def_readwrite("col", &xy::col)
.def("__repr__",
[](const xy &self) {
return fmt::format("xy(row={}, col={})", self.row, self.col);
})
.def("__iter__",
[](const xy &self) {
return py::iter(py::make_tuple(self.row, self.col));
})
.def(py::self == py::self)
.def(py::self != py::self);
py::enum_<DetectorType>(m, "DetectorType")
.value("Jungfrau", DetectorType::Jungfrau)
.value("Eiger", DetectorType::Eiger)
+8 -1
View File
@@ -318,7 +318,14 @@ void define_raw_file_io_bindings(py::module &m) {
Cols for the given ROI.
)")
.def_property_readonly("bitdepth", &RawFile::bitdepth)
.def_property_readonly("geometry", &RawFile::geometry)
.def_property_readonly("geometry", &RawFile::geometry, R"(
Number of modules along each axis of the detector.
Returns
-------
xy
Module rows and columns.
)")
.def_property_readonly("detector_type", &RawFile::detector_type)
.def_property_readonly("master", &RawFile::master)
.def_property_readonly("n_modules", &RawFile::n_modules)
+16 -2
View File
@@ -67,9 +67,23 @@ void define_raw_master_file_bindings(py::module &m) {
.def_property_readonly("total_frames_expected",
&RawMasterFile::total_frames_expected)
.def_property_readonly("detector_layout",
&RawMasterFile::detector_layout)
&RawMasterFile::detector_layout, R"(
Number of modules along each axis of the detector
Returns
----------
xy
Module rows and columns
)")
.def_property_readonly("udp_interfaces_per_module",
&RawMasterFile::udp_interfaces_per_module)
&RawMasterFile::udp_interfaces_per_module, R"(
Number of UDP interfaces along each axis of a module
Returns
----------
xy
UDP interface rows and columns
)")
.def_property_readonly("analog_samples", &RawMasterFile::analog_samples,
R"(
Number of analog samples
+15 -1
View File
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: MPL-2.0
import pytest
import json
from aare import File, RawFile, RawSubFile, DetectorType, ROI, UDPPortPosition
from aare import File, RawFile, RawSubFile, DetectorType, ROI, UDPPortPosition, xy
import numpy as np
@@ -237,6 +237,20 @@ def test_raw_frame_count_across_rois(small_raw_file, short_module):
reader.read_roi(roi_index)
def test_raw_file_geometry(small_raw_file):
metadata = json.loads(small_raw_file.read_text())
metadata["Geometry"] = {"x": 1, "y": 2}
small_raw_file.write_text(json.dumps(metadata))
for index in range(2):
data = (small_raw_file.parent / f"run_d0_f{index}_0.raw").read_bytes()
(small_raw_file.parent / f"run_d1_f{index}_0.raw").write_bytes(data)
reader = RawFile(small_raw_file)
assert reader.geometry == xy(row=2, col=1)
assert reader.master.detector_layout == xy(row=2, col=1)
assert reader.master.udp_interfaces_per_module == xy(row=1, col=1)
@pytest.mark.parametrize("disabled_port", [0, 1])
def test_raw_frame_count_with_disabled_udp_port(small_raw_file, disabled_port):
metadata = json.loads(small_raw_file.read_text())
+26
View File
@@ -0,0 +1,26 @@
# SPDX-License-Identifier: MPL-2.0
from aare import xy
def test_xy_fields():
layout = xy(row=2, col=3)
assert layout.row == 2
assert layout.col == 3
layout.row = 4
assert layout.row == 4
def test_xy_unpacks_as_row_col():
row, col = xy(2, 3)
assert (row, col) == (2, 3)
def test_xy_comparison():
assert xy(2, 3) == xy(2, 3)
assert xy(2, 3) != xy(3, 2)
assert xy(2, 3) != (2, 3)
def test_xy_repr():
assert repr(xy(2, 3)) == "xy(row=2, col=3)"