mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-07-13 20:31:49 +02:00
moved bindings for RawSubFile and small fix
This commit is contained in:
@ -66,6 +66,8 @@ class RawSubFile {
|
|||||||
size_t pixels_per_frame() const { return m_rows * m_cols; }
|
size_t pixels_per_frame() const { return m_rows * m_cols; }
|
||||||
size_t bytes_per_pixel() const { return m_bitdepth / bits_per_byte; }
|
size_t bytes_per_pixel() const { return m_bitdepth / bits_per_byte; }
|
||||||
|
|
||||||
|
size_t frames_in_file() const { return n_frames; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void read_with_map(std::byte *image_buf);
|
void read_with_map(std::byte *image_buf);
|
||||||
|
@ -20,6 +20,9 @@
|
|||||||
namespace py = pybind11;
|
namespace py = pybind11;
|
||||||
using namespace ::aare;
|
using namespace ::aare;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Disable warnings for unused parameters, as we ignore some
|
//Disable warnings for unused parameters, as we ignore some
|
||||||
//in the __exit__ method
|
//in the __exit__ method
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
@ -214,36 +217,9 @@ void define_file_io_bindings(py::module &m) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
py::class_<RawSubFile>(m, "RawSubFile")
|
|
||||||
.def(py::init<const std::filesystem::path &, DetectorType, size_t,
|
|
||||||
size_t, size_t>())
|
|
||||||
.def_property_readonly("bytes_per_frame", &RawSubFile::bytes_per_frame)
|
|
||||||
.def_property_readonly("pixels_per_frame",
|
|
||||||
&RawSubFile::pixels_per_frame)
|
|
||||||
.def("seek", &RawSubFile::seek)
|
|
||||||
.def("tell", &RawSubFile::tell)
|
|
||||||
.def_property_readonly("rows", &RawSubFile::rows)
|
|
||||||
.def_property_readonly("cols", &RawSubFile::cols)
|
|
||||||
.def("read_frame",
|
|
||||||
[](RawSubFile &self) {
|
|
||||||
const uint8_t item_size = self.bytes_per_pixel();
|
|
||||||
py::array image;
|
|
||||||
std::vector<ssize_t> shape;
|
|
||||||
shape.reserve(2);
|
|
||||||
shape.push_back(self.rows());
|
|
||||||
shape.push_back(self.cols());
|
|
||||||
if (item_size == 1) {
|
|
||||||
image = py::array_t<uint8_t>(shape);
|
|
||||||
} else if (item_size == 2) {
|
|
||||||
image = py::array_t<uint16_t>(shape);
|
|
||||||
} else if (item_size == 4) {
|
|
||||||
image = py::array_t<uint32_t>(shape);
|
|
||||||
}
|
|
||||||
fmt::print("item_size: {} rows: {} cols: {}\n", item_size, self.rows(), self.cols());
|
|
||||||
self.read_into(
|
|
||||||
reinterpret_cast<std::byte *>(image.mutable_data()));
|
|
||||||
return image;
|
|
||||||
});
|
|
||||||
|
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
// py::class_<ClusterHeader>(m, "ClusterHeader")
|
// py::class_<ClusterHeader>(m, "ClusterHeader")
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "cluster_file.hpp"
|
#include "cluster_file.hpp"
|
||||||
#include "fit.hpp"
|
#include "fit.hpp"
|
||||||
#include "interpolation.hpp"
|
#include "interpolation.hpp"
|
||||||
|
#include "raw_sub_file.hpp"
|
||||||
|
|
||||||
#include "jungfrau_data_file.hpp"
|
#include "jungfrau_data_file.hpp"
|
||||||
|
|
||||||
@ -22,6 +23,7 @@ namespace py = pybind11;
|
|||||||
PYBIND11_MODULE(_aare, m) {
|
PYBIND11_MODULE(_aare, m) {
|
||||||
define_file_io_bindings(m);
|
define_file_io_bindings(m);
|
||||||
define_raw_file_io_bindings(m);
|
define_raw_file_io_bindings(m);
|
||||||
|
define_raw_sub_file_io_bindings(m);
|
||||||
define_ctb_raw_file_io_bindings(m);
|
define_ctb_raw_file_io_bindings(m);
|
||||||
define_raw_master_file_bindings(m);
|
define_raw_master_file_bindings(m);
|
||||||
define_var_cluster_finder_bindings(m);
|
define_var_cluster_finder_bindings(m);
|
||||||
|
65
python/src/raw_sub_file.hpp
Normal file
65
python/src/raw_sub_file.hpp
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
#include "aare/CtbRawFile.hpp"
|
||||||
|
#include "aare/File.hpp"
|
||||||
|
#include "aare/Frame.hpp"
|
||||||
|
#include "aare/RawFile.hpp"
|
||||||
|
#include "aare/RawMasterFile.hpp"
|
||||||
|
#include "aare/RawSubFile.hpp"
|
||||||
|
|
||||||
|
#include "aare/defs.hpp"
|
||||||
|
// #include "aare/fClusterFileV2.hpp"
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <pybind11/iostream.h>
|
||||||
|
#include <pybind11/numpy.h>
|
||||||
|
#include <pybind11/pybind11.h>
|
||||||
|
#include <pybind11/stl.h>
|
||||||
|
#include <pybind11/stl/filesystem.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace py = pybind11;
|
||||||
|
using namespace ::aare;
|
||||||
|
|
||||||
|
auto read_frame_from_RawSubFile(RawSubFile &self) {
|
||||||
|
py::array_t<DetectorHeader> header(1);
|
||||||
|
const uint8_t item_size = self.bytes_per_pixel();
|
||||||
|
std::vector<ssize_t> shape{static_cast<ssize_t>(self.rows()),
|
||||||
|
static_cast<ssize_t>(self.cols())};
|
||||||
|
|
||||||
|
py::array image;
|
||||||
|
if (item_size == 1) {
|
||||||
|
image = py::array_t<uint8_t>(shape);
|
||||||
|
} else if (item_size == 2) {
|
||||||
|
image = py::array_t<uint16_t>(shape);
|
||||||
|
} else if (item_size == 4) {
|
||||||
|
image = py::array_t<uint32_t>(shape);
|
||||||
|
}
|
||||||
|
self.read_into(reinterpret_cast<std::byte *>(image.mutable_data()),
|
||||||
|
header.mutable_data());
|
||||||
|
|
||||||
|
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,
|
||||||
|
size_t, size_t>())
|
||||||
|
.def_property_readonly("bytes_per_frame", &RawSubFile::bytes_per_frame)
|
||||||
|
.def_property_readonly("pixels_per_frame",
|
||||||
|
&RawSubFile::pixels_per_frame)
|
||||||
|
.def_property_readonly("bytes_per_pixel", &RawSubFile::bytes_per_pixel)
|
||||||
|
.def("seek", &RawSubFile::seek)
|
||||||
|
.def("tell", &RawSubFile::tell)
|
||||||
|
.def_property_readonly("rows", &RawSubFile::rows)
|
||||||
|
.def_property_readonly("cols", &RawSubFile::cols)
|
||||||
|
.def_property_readonly("frames_in_file", &RawSubFile::frames_in_file)
|
||||||
|
.def("read_frame", &read_frame_from_RawSubFile);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma GCC diagnostic pop
|
Reference in New Issue
Block a user