mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-16 17:27:14 +02:00
RawSubFile support multi file access (#173)
This PR is a fix/improvement to a problem that Jonathan had. (#156) The original implementation opened all subfiles at once witch works for normal sized datasets but fails at a certain point (thousands of files). - This solution uses RawSubFile to manage the different file indicies and only opens the file we need - Added logger.h from slsDetectorPackage for debug printing (in production no messages should be visible)
This commit is contained in:
76
src/RawSubFile.test.cpp
Normal file
76
src/RawSubFile.test.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
#include "aare/RawSubFile.hpp"
|
||||
#include "aare/File.hpp"
|
||||
#include "aare/NDArray.hpp"
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include "test_config.hpp"
|
||||
|
||||
using namespace aare;
|
||||
|
||||
TEST_CASE("Read frames directly from a RawSubFile", "[.files]"){
|
||||
auto fpath_raw = test_data_path() / "raw/jungfrau" / "jungfrau_single_d0_f0_0.raw";
|
||||
REQUIRE(std::filesystem::exists(fpath_raw));
|
||||
|
||||
RawSubFile f(fpath_raw, DetectorType::Jungfrau, 512, 1024, 16);
|
||||
REQUIRE(f.rows() == 512);
|
||||
REQUIRE(f.cols() == 1024);
|
||||
REQUIRE(f.pixels_per_frame() == 512 * 1024);
|
||||
REQUIRE(f.bytes_per_frame() == 512 * 1024 * 2);
|
||||
REQUIRE(f.bytes_per_pixel() == 2);
|
||||
|
||||
|
||||
auto fpath_npy = test_data_path() / "raw/jungfrau" / "jungfrau_single_0.npy";
|
||||
REQUIRE(std::filesystem::exists(fpath_npy));
|
||||
|
||||
//Numpy file with the same data to use as reference
|
||||
File npy(fpath_npy, "r");
|
||||
|
||||
CHECK(f.frames_in_file() == 10);
|
||||
CHECK(npy.total_frames() == 10);
|
||||
|
||||
|
||||
DetectorHeader header{};
|
||||
NDArray<uint16_t, 2> image({static_cast<ssize_t>(f.rows()), static_cast<ssize_t>(f.cols())});
|
||||
for (size_t i = 0; i < 10; ++i) {
|
||||
CHECK(f.tell() == i);
|
||||
f.read_into(image.buffer(), &header);
|
||||
auto npy_frame = npy.read_frame();
|
||||
CHECK((image.view() == npy_frame.view<uint16_t>()));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Read frames directly from a RawSubFile starting at the second file", "[.files]"){
|
||||
// we know this file has 10 frames with frame numbers 1 to 10
|
||||
// f0 1,2,3
|
||||
// f1 4,5,6 <-- starting here
|
||||
// f2 7,8,9
|
||||
// f3 10
|
||||
|
||||
auto fpath_raw = test_data_path() / "raw/jungfrau" / "jungfrau_single_d0_f1_0.raw";
|
||||
REQUIRE(std::filesystem::exists(fpath_raw));
|
||||
|
||||
RawSubFile f(fpath_raw, DetectorType::Jungfrau, 512, 1024, 16);
|
||||
|
||||
|
||||
auto fpath_npy = test_data_path() / "raw/jungfrau" / "jungfrau_single_0.npy";
|
||||
REQUIRE(std::filesystem::exists(fpath_npy));
|
||||
|
||||
//Numpy file with the same data to use as reference
|
||||
File npy(fpath_npy, "r");
|
||||
npy.seek(3);
|
||||
|
||||
CHECK(f.frames_in_file() == 7);
|
||||
CHECK(npy.total_frames() == 10);
|
||||
|
||||
|
||||
DetectorHeader header{};
|
||||
NDArray<uint16_t, 2> image({static_cast<ssize_t>(f.rows()), static_cast<ssize_t>(f.cols())});
|
||||
for (size_t i = 0; i < 7; ++i) {
|
||||
CHECK(f.tell() == i);
|
||||
f.read_into(image.buffer(), &header);
|
||||
// frame numbers start at 1 frame index at 0
|
||||
// adding 3 + 1 to verify the frame number
|
||||
CHECK(header.frameNumber == i + 4);
|
||||
auto npy_frame = npy.read_frame();
|
||||
CHECK((image.view() == npy_frame.view<uint16_t>()));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user