diff --git a/include/aare/RawFile.hpp b/include/aare/RawFile.hpp index 82106bc..0209733 100644 --- a/include/aare/RawFile.hpp +++ b/include/aare/RawFile.hpp @@ -72,6 +72,7 @@ class RawFile : public FileInterface { size_t bitdepth() const override; xy geometry(); size_t n_modules() const; + size_t n_modules_in_roi() const; RawMasterFile master() const; diff --git a/python/src/raw_file.hpp b/python/src/raw_file.hpp index 8b8a5a6..83f1110 100644 --- a/python/src/raw_file.hpp +++ b/python/src/raw_file.hpp @@ -65,7 +65,7 @@ void define_raw_file_io_bindings(py::module &m) { header = py::array_t(n_frames); } else { header = py::array_t( - {self.n_modules(), n_frames}); + {self.n_modules_in_roi(), n_frames}); } // py::array_t header({self.n_mod(), n_frames}); @@ -103,5 +103,6 @@ void define_raw_file_io_bindings(py::module &m) { .def_property_readonly("geometry", &RawFile::geometry) .def_property_readonly("detector_type", &RawFile::detector_type) .def_property_readonly("master", &RawFile::master) - .def_property_readonly("n_modules", &RawFile::n_modules); + .def_property_readonly("n_modules", &RawFile::n_modules) + .def_property_readonly("n_modules_in_roi", &RawFile::n_modules_in_roi); } \ No newline at end of file diff --git a/python/tests/test_RawFile.py b/python/tests/test_RawFile.py new file mode 100644 index 0000000..769b4e6 --- /dev/null +++ b/python/tests/test_RawFile.py @@ -0,0 +1,14 @@ +import pytest +from aare import RawFile + +@pytest.mark.files +def test_read_rawfile_with_roi(test_data_path): + + # Starting with f1 there is now 7 frames left in the series of files + print(test_data_path) + with RawFile(test_data_path / "raw/SingleChipROI/Data_master_0.json") as f: + headers, frames = f.read() + + assert headers.size == 10100 + assert frames.shape == (10100, 256, 256) + \ No newline at end of file diff --git a/src/RawFile.cpp b/src/RawFile.cpp index 788d012..f03ec89 100644 --- a/src/RawFile.cpp +++ b/src/RawFile.cpp @@ -62,7 +62,7 @@ void RawFile::read_into(std::byte *image_buf, size_t n_frames, this->get_frame_into(m_current_frame++, image_buf, header); image_buf += bytes_per_frame(); if (header) - header += m_geometry.n_modules(); + header += m_geometry.n_modules_in_roi(); } } @@ -98,6 +98,9 @@ size_t RawFile::bitdepth() const { return m_master.bitdepth(); } xy RawFile::geometry() { return m_master.geometry(); } size_t RawFile::n_modules() const { return m_geometry.n_modules(); }; +size_t RawFile::n_modules_in_roi() const { + return m_geometry.n_modules_in_roi(); +}; void RawFile::open_subfiles() { if (m_mode == "r") diff --git a/src/RawFile.test.cpp b/src/RawFile.test.cpp index 978d011..7eb3707 100644 --- a/src/RawFile.test.cpp +++ b/src/RawFile.test.cpp @@ -257,12 +257,21 @@ TEST_CASE_PRIVATE(aare, open_multi_module_file_with_roi, RawFile f(fpath, "r"); - REQUIRE(f.master().roi().value().width() == 256); - REQUIRE(f.master().roi().value().height() == 256); + SECTION("read 2 frames") { + REQUIRE(f.master().roi().value().width() == 256); + REQUIRE(f.master().roi().value().height() == 256); - CHECK(f.m_geometry.n_modules() == 2); + CHECK(f.m_geometry.n_modules() == 2); - CHECK(f.m_geometry.n_modules_in_roi() == 1); + CHECK(f.m_geometry.n_modules_in_roi() == 1); + + auto frames = f.read_n(2); + + CHECK(frames.size() == 2); + + CHECK(frames[0].rows() == 256); + CHECK(frames[1].cols() == 256); + } } } // close namespace aare