diff --git a/python/src/jungfrau_data_file.hpp b/python/src/jungfrau_data_file.hpp index 13a3202..942f6a6 100644 --- a/python/src/jungfrau_data_file.hpp +++ b/python/src/jungfrau_data_file.hpp @@ -20,14 +20,11 @@ using namespace ::aare; #pragma GCC diagnostic ignored "-Wunused-parameter" auto read_dat_frame(JungfrauDataFile &self) { - std::vector shape; - shape.reserve(2); - shape.push_back(self.rows()); - shape.push_back(self.cols()); - - // return headers from all subfiles py::array_t header(1); - py::array_t image(shape); + py::array_t image({ + self.rows(), + self.cols() + }); self.read_into(reinterpret_cast(image.mutable_data()), header.mutable_data()); @@ -41,12 +38,11 @@ auto read_n_dat_frames(JungfrauDataFile &self, size_t n_frames) { if (n_frames == 0) { throw std::runtime_error("No frames left in file"); } - std::vector shape{n_frames, self.rows(), self.cols()}; - // return headers from all subfiles py::array_t header(n_frames); - - py::array_t image(shape); + py::array_t image({ + n_frames, self.rows(), + self.cols()}); self.read_into(reinterpret_cast(image.mutable_data()), n_frames, header.mutable_data()); diff --git a/python/tests/conftest.py b/python/tests/conftest.py index 340f30b..5badf13 100644 --- a/python/tests/conftest.py +++ b/python/tests/conftest.py @@ -11,7 +11,7 @@ def pytest_addoption(parser): def pytest_configure(config): - config.addinivalue_line("markers", "files: mark test as needing image fiels to run") + config.addinivalue_line("markers", "files: mark test as needing image files to run") def pytest_collection_modifyitems(config, items): diff --git a/src/JungfrauDataFile.test.cpp b/src/JungfrauDataFile.test.cpp index db5464b..626a318 100644 --- a/src/JungfrauDataFile.test.cpp +++ b/src/JungfrauDataFile.test.cpp @@ -66,4 +66,29 @@ TEST_CASE("Seek in a JungfrauDataFile", "[.files]"){ REQUIRE(f.read_header().framenum == 60+1); REQUIRE_THROWS(f.seek(86356)); //out of range +} + +TEST_CASE("Open a Jungfrau data file with non zero file index", "[.files]"){ + + auto fpath = test_data_path() / "dat" / "AldoJF65k_000003.dat"; + REQUIRE(std::filesystem::exists(fpath)); + + JungfrauDataFile f(fpath); + + //18 files per data file, opening the 3rd file we ignore the first 3 + REQUIRE(f.total_frames() == 113-18*3); + REQUIRE(f.tell() == 0); + + //Frame numbers start at 1 in the first file + REQUIRE(f.read_header().framenum == 18*3+1); + + // moving relative to the third file + f.seek(5); + REQUIRE(f.read_header().framenum == 18*3+1+5); + + // ignoring the first 3 files + REQUIRE(f.n_files() == 4); + + REQUIRE(f.current_file().stem() == "AldoJF65k_000003"); + } \ No newline at end of file