Files
aare/python/src/bind_Defs.hpp
T
Erik Fröjdh bf0aa4a3bf
Build on RHEL9 / build (push) Successful in 2m55s
Build on RHEL8 / build (push) Successful in 3m38s
Run tests using data on local RHEL8 / build (push) Failing after 4m35s
Build on local RHEL8 / build (push) Successful in 3m20s
Added missing header guards (#414)
- Python extension. Originally left out since it didn't matter but good
practice for future
- to_string.hpp - this is the important one
2026-10-07 12:04:54 +02:00

122 lines
4.7 KiB
C++

// SPDX-License-Identifier: MPL-2.0
#pragma once
#include <pybind11/operators.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include "aare/defs.hpp"
namespace py = pybind11;
using namespace aare;
void define_defs_bindings(py::module &m) {
auto matterhorn10 = py::class_<Matterhorn10>(m, "Matterhorn10");
matterhorn10.attr("nRows") = Matterhorn10::nRows;
matterhorn10.attr("nCols") = Matterhorn10::nCols;
auto matterhorn02 = py::class_<Matterhorn02>(m, "Matterhorn02");
matterhorn02.attr("nRows") = Matterhorn02::nRows;
matterhorn02.attr("nCols") = Matterhorn02::nCols;
matterhorn02.attr("nHalfCols") = Matterhorn02::nHalfCols;
auto moench04 = py::class_<Moench04>(m, "Moench04");
moench04.attr("nRows") = Moench04::nRows;
moench04.attr("nCols") = Moench04::nCols;
moench04.attr("nPixelsPerSuperColumn") = Moench04::nPixelsPerSuperColumn;
moench04.attr("superColumnWidth") = Moench04::superColumnWidth;
moench04.attr("adcNumbers") = Moench04::adcNumbers;
auto moench05 = py::class_<Moench05>(m, "Moench05");
moench05.attr("nRows") = Moench05::nRows;
moench05.attr("nCols") = Moench05::nCols;
moench05.attr("adcNumbers") = Moench05::adcNumbers;
py::class_<ROI>(m, "ROI")
.def(py::init<>())
.def(py::init<ssize_t, ssize_t, ssize_t, ssize_t>(), py::arg("xmin"),
py::arg("xmax"), py::arg("ymin"), py::arg("ymax"))
.def_readwrite("xmin", &ROI::xmin)
.def_readwrite("xmax", &ROI::xmax)
.def_readwrite("ymin", &ROI::ymin)
.def_readwrite("ymax", &ROI::ymax)
.def(
"slice",
[](const ROI &self) {
return std::make_tuple(py::slice(self.ymin, self.ymax, 1),
py::slice(self.xmin, self.xmax, 1));
},
R"doc(
The slice can be used to index into a 2D array to extract the region of interest.
Returns
-------
tuple of slice
A tuple containing two slice objects for the x and y dimensions.
)doc")
.def("__str__",
[](const ROI &self) {
return fmt::format("ROI: xmin: {} xmax: {} ymin: {} ymax: {}",
self.xmin, self.xmax, self.ymin, self.ymax);
})
.def("__repr__",
[](const ROI &self) {
return fmt::format(
"<ROI: xmin: {} xmax: {} ymin: {} ymax: {}>", self.xmin,
self.xmax, self.ymin, self.ymax);
})
.def("__iter__",
[](const ROI &self) {
return py::make_iterator(&self.xmin, &self.ymax + 1); // NOLINT
})
.def("__eq__", [](const ROI &self, const ROI &other) {
return self.xmin == other.xmin && self.xmax == other.xmax &&
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)
.value("Mythen3", DetectorType::Mythen3)
.value("Moench", DetectorType::Moench)
.value("Moench03", DetectorType::Moench03)
.value("Moench03_old", DetectorType::Moench03_old)
.value("ChipTestBoard", DetectorType::ChipTestBoard)
.value("Unknown", DetectorType::Unknown);
py::enum_<UDPPortPosition>(m, "UDPPortPosition")
.value("LEFT", UDPPortPosition::LEFT)
.value("RIGHT", UDPPortPosition::RIGHT)
.value("TOP", UDPPortPosition::TOP)
.value("BOTTOM", UDPPortPosition::BOTTOM);
py::enum_<TimingMode>(m, "TimingMode")
.value("AUTO_TIMING", TimingMode::AUTO_TIMING)
.value("TRIGGER_EXPOSURE", TimingMode::TRIGGER_EXPOSURE)
.value("GATED", TimingMode::GATED)
.value("BURST_TRIGGER", TimingMode::BURST_TRIGGER)
.value("TRIGGER_GATED", TimingMode::TRIGGER_GATED);
py::enum_<FrameDiscardPolicy>(m, "FrameDiscardPolicy")
.value("NoDiscard", FrameDiscardPolicy::NoDiscard)
.value("Discard", FrameDiscardPolicy::Discard)
.value("DiscardPartial", FrameDiscardPolicy::DiscardPartial);
}