solved merge conflict

This commit is contained in:
mazzol_a committed 2026-10-06 16:07:23 +02:00
commit 9a0fa9cdc4
52 files changed
+401 -175

No files matched your search

+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
-5
View File
@@ -13,9 +13,6 @@ namespace py = pybind11;
using namespace aare;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
template <typename Type, uint8_t ClusterSizeX, uint8_t ClusterSizeY,
typename CoordType>
void define_Cluster(py::module &m, const std::string &typestr) {
@@ -140,5 +137,3 @@ void reduce_to_2x2(py::module &m) {
row-major order.
)doc");
}
#pragma GCC diagnostic pop
-5
View File
@@ -20,9 +20,6 @@ namespace py = pybind11;
using namespace aare;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
template <typename T, uint8_t ClusterSizeX, uint8_t ClusterSizeY,
typename CoordType = uint16_t>
void define_ClusterCollector(py::module &m, const std::string &typestr) {
@@ -42,5 +39,3 @@ void define_ClusterCollector(py::module &m, const std::string &typestr) {
},
py::return_value_policy::take_ownership);
}
#pragma GCC diagnostic pop
+5 -12
View File
@@ -13,11 +13,6 @@
#include <string>
#include <utility>
// Disable warnings for unused parameters, as we ignore some
// in the __exit__ method
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
namespace py = pybind11;
using namespace ::aare;
@@ -171,14 +166,12 @@ void define_ClusterFile(py::module &m, const std::string &typestr) {
.def("__enter__", [](ClusterFile<ClusterType> &self) { return &self; })
.def("__exit__",
[](ClusterFile<ClusterType> &self,
const std::optional<pybind11::type> &exc_type,
const std::optional<pybind11::object> &exc_value,
const std::optional<pybind11::object> &traceback) {
self.close();
})
[[maybe_unused]] const std::optional<pybind11::type> &exc_type,
[[maybe_unused]] const std::optional<pybind11::object>
&exc_value,
[[maybe_unused]] const std::optional<pybind11::object>
&traceback) { self.close(); })
.def("__iter__", [](ClusterFile<ClusterType> &self) { return &self; })
.def("__next__",
[](File &self) { return ChunkIterator(self.chunks()).next(); });
}
#pragma GCC diagnostic pop
-5
View File
@@ -17,9 +17,6 @@
namespace py = pybind11;
using namespace aare;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
template <typename T, uint8_t ClusterSizeX, uint8_t ClusterSizeY,
typename CoordType = uint16_t>
void define_ClusterFileSink(py::module &m, const std::string &typestr) {
@@ -34,5 +31,3 @@ void define_ClusterFileSink(py::module &m, const std::string &typestr) {
const std::filesystem::path &>())
.def("stop", &ClusterFileSink<ClusterType>::stop);
}
#pragma GCC diagnostic pop
-5
View File
@@ -20,9 +20,6 @@ namespace py = pybind11;
using namespace aare;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
template <typename T, uint8_t ClusterSizeX, uint8_t ClusterSizeY,
typename CoordType = uint16_t>
void define_ClusterFinder(py::module &m, const std::string &typestr) {
@@ -92,5 +89,3 @@ void define_ClusterFinder(py::module &m, const std::string &typestr) {
},
py::arg("frame").noconvert(), py::arg("frame_number") = 0);
}
#pragma GCC diagnostic pop
+2 -6
View File
@@ -20,9 +20,6 @@ namespace py = pybind11;
using namespace aare;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
template <typename T, uint8_t ClusterSizeX, uint8_t ClusterSizeY,
typename CoordType = uint16_t>
void define_ClusterFinderMT(py::module &m, const std::string &typestr) {
@@ -55,7 +52,8 @@ void define_ClusterFinderMT(py::module &m, const std::string &typestr) {
py::arg("frame").noconvert(), py::arg("frame_number") = 0)
.def_property_readonly(
"cluster_size",
[](ClusterFinderMT<ClusterType, uint16_t, pd_type> &self) {
[]([[maybe_unused]] ClusterFinderMT<ClusterType, uint16_t, pd_type>
&self) {
return py::make_tuple(ClusterSizeX, ClusterSizeY);
})
.def("clear_pedestal",
@@ -93,5 +91,3 @@ void define_ClusterFinderMT(py::module &m, const std::string &typestr) {
py::arg("nSigma"),
R"(sets the number of sigma for all cluster finders.)");
}
#pragma GCC diagnostic pop
+7 -12
View File
@@ -18,9 +18,6 @@ namespace py = pybind11;
using namespace aare;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
template <typename Type, uint8_t ClusterSizeX, uint8_t ClusterSizeY,
typename CoordType = uint16_t>
void define_ClusterVector(py::module &m, const std::string &typestr) {
@@ -123,8 +120,8 @@ void define_ClusterVector(py::module &m, const std::string &typestr) {
"padding.")
.def_property_readonly(
"fmt",
[typestr](ClusterVector<ClusterType> &self) {
return fmt_format<ClusterType>;
[typestr]([[maybe_unused]] ClusterVector<ClusterType> &self) {
return fmt_format<ClusterType>();
},
"PEP 3118 format string for one stored cluster.")
@@ -145,11 +142,11 @@ void define_ClusterVector(py::module &m, const std::string &typestr) {
.def_buffer(
[typestr](ClusterVector<ClusterType> &self) -> py::buffer_info {
return py::buffer_info(
self.data(), /* Pointer to buffer */
self.item_size(), /* Size of one scalar */
fmt_format<ClusterType>, /* Format descriptor */
1, /* Number of dimensions */
{self.size()}, /* Buffer dimensions */
self.data(), /* Pointer to buffer */
self.item_size(), /* Size of one scalar */
fmt_format<ClusterType>(), /* Format descriptor */
1, /* Number of dimensions */
{self.size()}, /* Buffer dimensions */
{self.item_size()} /* Strides (in bytes) for each index */
);
});
@@ -228,5 +225,3 @@ void define_3x3_reduction(py::module &m) {
)doc",
py::arg("clustervector"));
}
#pragma GCC diagnostic pop
+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>
@@ -77,6 +78,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)
@@ -16,6 +16,7 @@
#include <pybind11/stl/filesystem.h>
namespace py = pybind11;
using aare::ssize_t;
inline py::dtype multi_threaded_reader_numpy_dtype(const aare::Dtype &dtype) {
using aare::Dtype;
+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)
+1
View File
@@ -9,6 +9,7 @@
#include <pybind11/stl_bind.h>
namespace py = pybind11;
using aare::ssize_t;
template <typename DataType>
py::array_t<DataType>
+7 -11
View File
@@ -21,11 +21,6 @@
namespace py = pybind11;
using namespace ::aare;
// Disable warnings for unused parameters, as we ignore some
// in the __exit__ method
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
void define_file_io_bindings(py::module &m) {
PYBIND11_NUMPY_DTYPE(DetectorHeader, frameNumber, expLength, packetNumber,
@@ -122,9 +117,12 @@ void define_file_io_bindings(py::module &m) {
})
.def("__enter__", [](File &self) { return &self; })
.def("__exit__",
[](File &self, const std::optional<pybind11::type> &exc_type,
const std::optional<pybind11::object> &exc_value,
const std::optional<pybind11::object> &traceback) {
[]([[maybe_unused]] File &self,
[[maybe_unused]] const std::optional<pybind11::type> &exc_type,
[[maybe_unused]] const std::optional<pybind11::object>
&exc_value,
[[maybe_unused]] const std::optional<pybind11::object>
&traceback) {
// self.close();
})
.def("__iter__", [](File &self) { return &self; })
@@ -146,7 +144,7 @@ void define_file_io_bindings(py::module &m) {
self.read_into(
reinterpret_cast<std::byte *>(image.mutable_data()));
return image;
} catch (std::runtime_error &e) {
} catch (std::runtime_error &) {
throw py::stop_iteration();
}
});
@@ -160,6 +158,4 @@ void define_file_io_bindings(py::module &m) {
.def_property_readonly("start", &ScanParameters::start)
.def_property_readonly("stop", &ScanParameters::stop)
.def_property_readonly("step", &ScanParameters::step);
#pragma GCC diagnostic pop
}
+1
View File
@@ -11,6 +11,7 @@
namespace py = pybind11;
using namespace pybind11::literals;
using aare::ssize_t;
template <typename Model>
py::object
+7 -12
View File
@@ -15,11 +15,6 @@
namespace py = pybind11;
using namespace ::aare;
// Disable warnings for unused parameters, as we ignore some
// in the __exit__ method
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
auto read_dat_frame(JungfrauDataFile &self) {
py::array_t<JungfrauDataHeader> header(1);
py::array_t<uint16_t> image({self.rows(), self.cols()});
@@ -119,20 +114,20 @@ void define_jungfrau_data_file_io_bindings(py::module &m) {
)")
.def("__enter__", [](JungfrauDataFile &self) { return &self; })
.def("__exit__",
[](JungfrauDataFile &self,
const std::optional<pybind11::type> &exc_type,
const std::optional<pybind11::object> &exc_value,
const std::optional<pybind11::object> &traceback) {
[]([[maybe_unused]] JungfrauDataFile &self,
[[maybe_unused]] const std::optional<pybind11::type> &exc_type,
[[maybe_unused]] const std::optional<pybind11::object>
&exc_value,
[[maybe_unused]] const std::optional<pybind11::object>
&traceback) {
// self.close();
})
.def("__iter__", [](JungfrauDataFile &self) { return &self; })
.def("__next__", [](JungfrauDataFile &self) {
try {
return read_dat_frame(self);
} catch (std::runtime_error &e) {
} catch (std::runtime_error &) {
throw py::stop_iteration();
}
});
}
#pragma GCC diagnostic pop
+7 -2
View File
@@ -112,8 +112,13 @@ struct fmt_format_trait<Cluster<T, ClusterSizeX, ClusterSizeY, CoordType>> {
}
};
template <typename ClusterType>
auto fmt_format = fmt_format_trait<ClusterType>::value();
// Function-local static rather than a variable template: MSVC does not run
// the dynamic initializer of a variable template instantiated from inside
// another template, which left the format string empty.
template <typename ClusterType> const std::string &fmt_format() {
static const std::string value = fmt_format_trait<ClusterType>::value();
return value;
}
/**
* Helper function to allocate image data given item size and shape
+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
+7 -11
View File
@@ -61,11 +61,6 @@ auto read_n_frames_from_RawSubFile(RawSubFile &self, size_t n_frames) {
return py::make_tuple(header, image);
}
// Disable warnings for unused parameters, as we ignore some
// in the __exit__ method
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
void define_raw_sub_file_io_bindings(py::module &m) {
py::class_<RawSubFile>(m, "RawSubFile")
.def(py::init<const std::filesystem::path &, DetectorType, size_t,
@@ -89,17 +84,18 @@ void define_raw_sub_file_io_bindings(py::module &m) {
})
.def("__enter__", [](RawSubFile &self) { return &self; })
.def("__exit__",
[](RawSubFile &self, const std::optional<pybind11::type> &exc_type,
const std::optional<pybind11::object> &exc_value,
const std::optional<pybind11::object> &traceback) {})
[]([[maybe_unused]] RawSubFile &self,
[[maybe_unused]] const std::optional<pybind11::type> &exc_type,
[[maybe_unused]] const std::optional<pybind11::object>
&exc_value,
[[maybe_unused]] const std::optional<pybind11::object>
&traceback) {})
.def("__iter__", [](RawSubFile &self) { return &self; })
.def("__next__", [](RawSubFile &self) {
try {
return read_frame_from_RawSubFile(self);
} catch (std::runtime_error &e) {
} catch (std::runtime_error &) {
throw py::stop_iteration();
}
});
}
#pragma GCC diagnostic pop
+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)"