first attempt at gappixels

This commit is contained in:
Erik Frojdh committed 2026-10-08 15:36:46 +02:00
1 parent bf0aa4a3bf
commit 406aade696
27 files changed
+995 -186

No files matched your search

+19 -1
View File
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: MPL-2.0
#pragma once
#include "aare/GapPixels.hpp"
#include "aare/MultiThreadedFileReader.hpp"
#include <cstddef>
@@ -79,9 +80,21 @@ inline void define_multi_threaded_file_reader_bindings(py::module_ &m) {
reader.attr("__module__") = "aare.experimental";
reader
.def(py::init<std::filesystem::path, size_t, size_t,
std::optional<size_t>>(),
std::optional<size_t>, std::optional<GapPixels>>(),
py::arg("fname"), py::arg("n_threads"), py::arg("chunk_size"),
py::arg("total_frames") = py::none(),
py::arg("gap_pixels") = py::none())
.def(py::init([](std::filesystem::path fname, size_t n_threads,
size_t chunk_size, std::optional<size_t> total_frames,
bool gap_pixels) {
return MultiThreadedFileReader(
std::move(fname), n_threads, chunk_size, total_frames,
gap_pixels ? std::optional<GapPixels>(GapPixels{})
: std::nullopt);
}),
py::arg("fname"), py::arg("n_threads"), py::arg("chunk_size"),
py::arg("total_frames") = py::none(),
py::arg("gap_pixels") = false,
R"doc(
Read chunks of detector frames concurrently.
@@ -93,7 +106,12 @@ inline void define_multi_threaded_file_reader_bindings(py::module_ &m) {
n_threads: Maximum number of worker threads.
chunk_size: Number of frames read per claimed chunk.
total_frames: Optional frame limit. None reads all frames.
gap_pixels: Insert gap pixels, raw files only. True uses
the default GapPixels configuration. Each worker
uses the configured seed plus its worker index.
)doc")
.def_property_readonly("gap_pixels",
&MultiThreadedFileReader::gap_pixels)
.def(
"read",
[](MultiThreadedFileReader &self) {
+35 -8
View File
@@ -3,6 +3,7 @@
#include "aare/CtbRawFile.hpp"
#include "aare/File.hpp"
#include "aare/Frame.hpp"
#include "aare/GapPixels.hpp"
#include "aare/RawFile.hpp"
#include "aare/RawMasterFile.hpp"
#include "aare/RawSubFile.hpp"
@@ -13,6 +14,7 @@
#include <cstdint>
#include <filesystem>
#include <fmt/format.h>
#include <memory>
#include <pybind11/iostream.h>
#include <pybind11/numpy.h>
#include <pybind11/pybind11.h>
@@ -34,7 +36,33 @@ std::runtime_error raw_file_read_error(RawFile &file,
void define_raw_file_io_bindings(py::module &m) {
py::class_<RawFile>(m, "RawFile")
.def(py::init<const std::filesystem::path &>())
.def(py::init([](const std::filesystem::path &fname,
const GapPixels &gap_pixels) {
return std::make_unique<RawFile>(fname, "r", gap_pixels);
}),
py::arg("fname"), py::arg("gap_pixels"))
.def(py::init([](const std::filesystem::path &fname, bool gap_pixels) {
return std::make_unique<RawFile>(
fname, "r",
gap_pixels ? std::optional<GapPixels>(GapPixels{})
: std::nullopt);
}),
py::arg("fname"), py::arg("gap_pixels") = false, R"(
Open a raw file for reading.
Parameters
----------
fname : path
Master file (.json or .raw).
gap_pixels : bool or GapPixels
Insert gap pixels into every frame. True uses the default
GapPixels configuration. Frame shapes, rows() and cols()
then include the gaps. Only Jungfrau and Eiger are
supported.
)")
.def_property_readonly("gap_pixels", &RawFile::gap_pixels, R"(
Gap pixel configuration, or None when reading without gaps.
)")
.def("read_frame",
[](RawFile &self) {
if (self.n_modules_in_roi().size() > 1) {
@@ -118,8 +146,8 @@ void define_raw_file_io_bindings(py::module &m) {
std::vector<size_t> shape;
shape.reserve(2);
shape.push_back(self.roi_geometries(roi_index).pixels_y());
shape.push_back(self.roi_geometries(roi_index).pixels_x());
shape.push_back(self.rows(roi_index));
shape.push_back(self.cols(roi_index));
py::array image =
allocate_image_data(self.bytes_per_pixel(), shape);
@@ -177,8 +205,8 @@ void define_raw_file_io_bindings(py::module &m) {
for (size_t r = 0; r < number_of_ROIs; r++) {
std::vector<size_t> shape;
shape.reserve(2);
shape.push_back(self.roi_geometries(r).pixels_y());
shape.push_back(self.roi_geometries(r).pixels_x());
shape.push_back(self.rows(r));
shape.push_back(self.cols(r));
images[r] =
allocate_image_data(self.bytes_per_pixel(), shape);
@@ -229,9 +257,8 @@ void define_raw_file_io_bindings(py::module &m) {
if (n_frames == 0) {
throw raw_file_read_error(self, "No frames left in file");
}
std::vector<size_t> shape{
n_frames, self.roi_geometries(roi_index).pixels_y(),
self.roi_geometries(roi_index).pixels_x()};
std::vector<size_t> shape{n_frames, self.rows(roi_index),
self.cols(roi_index)};
// return headers from all subfiles
auto n_mod = self.n_modules_in_roi()[roi_index];
+32 -7
View File
@@ -3,6 +3,7 @@
#include "aare/CtbRawFile.hpp"
#include "aare/File.hpp"
#include "aare/Frame.hpp"
#include "aare/GapPixels.hpp"
#include "aare/ROI.hpp"
#include "aare/RawFile.hpp"
#include "aare/RawMasterFile.hpp"
@@ -29,13 +30,37 @@ void define_file_io_bindings(py::module &m) {
debug, roundRNumber, detType, version, packetMask);
py::class_<File>(m, "File")
.def(py::init([](const std::filesystem::path &fname) {
return File(fname, "r", {});
}))
.def(py::init(
[](const std::filesystem::path &fname, const std::string &mode) {
return File(fname, mode, {});
}))
.def(py::init([](const std::filesystem::path &fname,
const std::string &mode,
std::optional<GapPixels> gap_pixels) {
FileConfig cfg;
cfg.gap_pixels = std::move(gap_pixels);
return File(fname, mode, cfg);
}),
py::arg("fname"), py::arg("mode") = "r",
py::arg("gap_pixels") = py::none())
.def(py::init([](const std::filesystem::path &fname,
const std::string &mode, bool gap_pixels) {
FileConfig cfg;
if (gap_pixels) {
cfg.gap_pixels = GapPixels{};
}
return File(fname, mode, cfg);
}),
py::arg("fname"), py::arg("mode") = "r",
py::arg("gap_pixels") = false, R"(
Open a file for reading.
Parameters
----------
fname : path
Master file (.json, .raw), .npy or .dat file.
mode : str
Only "r" is supported.
gap_pixels : bool or GapPixels
Insert gap pixels when reading raw files. True uses the
default GapPixels configuration.
)")
.def(py::init<const std::filesystem::path &, const std::string &,
const FileConfig &>())
+2
View File
@@ -14,6 +14,7 @@
#include "bind_Defs.hpp"
#include "bind_Eta.hpp"
#include "bind_FastPedestal.hpp"
#include "bind_GapPixels.hpp"
#include "bind_Interpolator.hpp"
#include "bind_MultiThreadedFileReader.hpp"
#include "bind_Pedestal.hpp"
@@ -156,6 +157,7 @@ PYBIND11_MODULE(_aare, m) {
register_calculate_3x3eta<int16_t, 3, 3, uint16_t>(m);
define_defs_bindings(m);
define_gap_pixels_bindings(m);
using Sum_index_pair_d = Sum_index_pair<double, corner>;
PYBIND11_NUMPY_DTYPE(Sum_index_pair_d, sum, index);