first implementation

This commit is contained in:
Erik Frojdh
2026-05-22 16:17:46 +02:00
parent 52b5cf6b9f
commit 913dd0da54
5 changed files with 180 additions and 0 deletions
+78
View File
@@ -0,0 +1,78 @@
// SPDX-License-Identifier: MPL-2.0
#include "aare/PixelHistogram.hpp"
#include "np_helper.hpp"
#include <cstdint>
#include <pybind11/numpy.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
namespace py = pybind11;
using namespace ::aare;
void define_pixel_histogram_bindings(py::module &m) {
py::class_<PixelHistogram>(m, "PixelHistogram",
"A histogram for pixel-wise statistics")
.def(py::init<int, int, int, double, double>(),
R"(
Initialize a PixelHistogram.
Args:
rows: Number of rows in the detector
cols: Number of columns in the detector
n_bins: Number of histogram bins
xmin: Minimum value for histogram range
xmax: Maximum value for histogram range
)",
py::arg("rows"), py::arg("cols"), py::arg("n_bins"),
py::arg("xmin"), py::arg("xmax"))
.def("fill",
[](PixelHistogram &self,
py::array_t<double, py::array::forcecast> image) {
auto view = make_view_2d(image);
self.fill(view);
},
R"(
Fill the histogram with image data.
Args:
image: A 2D numpy array of pixel values (dtype: float64)
)",
py::arg("image"))
.def("hdata",
[](const PixelHistogram &self) {
auto ptr = new NDArray<int32_t, 3>(self.hdata());
return return_image_data(ptr);
},
R"(
Get the histogram data as a numpy array.
Returns:
A 3D numpy array containing the histogram bins for each pixel
)")
.def("bin_centers",
[](const PixelHistogram &self) {
auto ptr = new NDArray<double, 1>(self.bin_centers());
return return_image_data(ptr);
},
R"(
Get the bin centers along the value axis.
Returns:
A 1D numpy array containing the center values for each histogram bin
)")
.def("bin_edges",
[](const PixelHistogram &self) {
auto ptr = new NDArray<double, 1>(self.bin_edges());
return return_image_data(ptr);
},
R"(
Get the bin edges along the value axis.
Returns:
A 1D numpy array containing the edge values for the histogram bins
)");
}
+2
View File
@@ -12,6 +12,7 @@
#include "bind_Defs.hpp"
#include "bind_Eta.hpp"
#include "bind_Interpolator.hpp"
#include "bind_PixelHistogram.hpp"
#include "bind_PixelMap.hpp"
#include "bind_RawFile.hpp"
#include "bind_calibration.hpp"
@@ -64,6 +65,7 @@ PYBIND11_MODULE(_aare, m) {
define_raw_master_file_bindings(m);
define_var_cluster_finder_bindings(m);
define_pixel_map_bindings(m);
define_pixel_histogram_bindings(m);
define_pedestal_bindings<double>(m, "Pedestal_d");
define_pedestal_bindings<float>(m, "Pedestal_f");
define_fit_bindings(m);