mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-25 04:31:10 +02:00
added eiger quad test
This commit is contained in:
@ -1,14 +1,74 @@
|
|||||||
import pytest
|
import pytest
|
||||||
from aare import RawFile
|
from aare import RawFile
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
@pytest.mark.files
|
@pytest.mark.files
|
||||||
def test_read_rawfile_with_roi(test_data_path):
|
def test_read_rawfile_with_roi(test_data_path):
|
||||||
|
|
||||||
# Starting with f1 there is now 7 frames left in the series of files
|
# 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:
|
with RawFile(test_data_path / "raw/SingleChipROI/Data_master_0.json") as f:
|
||||||
headers, frames = f.read()
|
headers, frames = f.read()
|
||||||
|
|
||||||
assert headers.size == 10100
|
assert headers.size == 10100
|
||||||
assert frames.shape == (10100, 256, 256)
|
assert frames.shape == (10100, 256, 256)
|
||||||
|
|
||||||
|
@pytest.mark.files
|
||||||
|
def test_read_rawfile_quad_eiger_and_compare_to_numpy(test_data_path):
|
||||||
|
|
||||||
|
d0 = test_data_path/'raw/eiger_quad_data/W13_vrpreampscan_m21C_300V_800eV_vthre2000_d0_f0_0.raw'
|
||||||
|
d1 = test_data_path/'raw/eiger_quad_data/W13_vrpreampscan_m21C_300V_800eV_vthre2000_d1_f0_0.raw'
|
||||||
|
|
||||||
|
image = np.zeros((512,512), dtype=np.uint32)
|
||||||
|
|
||||||
|
with open(d0) as f:
|
||||||
|
raw = np.fromfile(f, dtype=np.uint32, count = 256*512, offset = 20*256*512*4 + 112*21).reshape(256,512)
|
||||||
|
|
||||||
|
image[256:,:] = raw
|
||||||
|
|
||||||
|
with open(d1) as f:
|
||||||
|
raw = np.fromfile(f, dtype=np.uint32, count = 256*512, offset = 20*256*512*4 + 112*21).reshape(256,512)
|
||||||
|
|
||||||
|
image[0:256,:] = raw[::-1,:]
|
||||||
|
|
||||||
|
with RawFile(test_data_path/'raw/eiger_quad_data/W13_vrpreampscan_m21C_300V_800eV_vthre2000_master_0.json') as f:
|
||||||
|
f.seek(20)
|
||||||
|
header, image1 = f.read_frame()
|
||||||
|
|
||||||
|
assert (image == image1).all()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.files
|
||||||
|
def test_read_rawfile_eiger_and_compare_to_numpy(test_data_path):
|
||||||
|
d0 = test_data_path/'raw/eiger/Lab6_20500eV_2deg_20240629_d0_f0_7.raw'
|
||||||
|
d1 = test_data_path/'raw/eiger/Lab6_20500eV_2deg_20240629_d1_f0_7.raw'
|
||||||
|
d2 = test_data_path/'raw/eiger/Lab6_20500eV_2deg_20240629_d2_f0_7.raw'
|
||||||
|
d3 = test_data_path/'raw/eiger/Lab6_20500eV_2deg_20240629_d3_f0_7.raw'
|
||||||
|
|
||||||
|
image = np.zeros((512,1024), dtype=np.uint32)
|
||||||
|
|
||||||
|
#TODO why is there no header offset?
|
||||||
|
with open(d0) as f:
|
||||||
|
raw = np.fromfile(f, dtype=np.uint32, count = 256*512, offset=112).reshape(256,512)
|
||||||
|
|
||||||
|
image[0:256,0:512] = raw[::-1]
|
||||||
|
|
||||||
|
with open(d1) as f:
|
||||||
|
raw = np.fromfile(f, dtype=np.uint32, count = 256*512, offset=112).reshape(256,512)
|
||||||
|
|
||||||
|
image[0:256,512:] = raw[::-1]
|
||||||
|
|
||||||
|
with open(d2) as f:
|
||||||
|
raw = np.fromfile(f, dtype=np.uint32, count = 256*512, offset=112).reshape(256,512)
|
||||||
|
|
||||||
|
image[256:,0:512] = raw
|
||||||
|
|
||||||
|
with open(d3) as f:
|
||||||
|
raw = np.fromfile(f, dtype=np.uint32, count = 256*512, offset=112).reshape(256,512)
|
||||||
|
|
||||||
|
image[256:,512:] = raw
|
||||||
|
|
||||||
|
|
||||||
|
with RawFile(test_data_path/'raw/eiger/Lab6_20500eV_2deg_20240629_master_7.json') as f:
|
||||||
|
header, image1 = f.read_frame()
|
||||||
|
|
||||||
|
assert (image == image1).all()
|
||||||
|
@ -56,7 +56,7 @@ void NumpyFile::write_impl(void *data, uint64_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Frame NumpyFile::get_frame(size_t frame_number) {
|
Frame NumpyFile::get_frame(size_t frame_number) {
|
||||||
Frame frame(m_header.shape[1], m_header.shape[2], m_header.dtype);
|
Frame frame(m_header.shape[0], m_header.shape[1], m_header.dtype);
|
||||||
get_frame_into(frame_number, frame.data());
|
get_frame_into(frame_number, frame.data());
|
||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
@ -67,7 +67,7 @@ void NumpyFile::get_frame_into(size_t frame_number, std::byte *image_buf) {
|
|||||||
if (frame_number > m_header.shape[0]) {
|
if (frame_number > m_header.shape[0]) {
|
||||||
throw std::invalid_argument("Frame number out of range");
|
throw std::invalid_argument("Frame number out of range");
|
||||||
}
|
}
|
||||||
if (fseek(fp, header_size + frame_number * m_bytes_per_frame,
|
if (fseek(fp, frame_number * m_bytes_per_frame,
|
||||||
SEEK_SET)) // NOLINT
|
SEEK_SET)) // NOLINT
|
||||||
throw std::runtime_error("Could not seek to frame");
|
throw std::runtime_error("Could not seek to frame");
|
||||||
|
|
||||||
|
@ -111,25 +111,65 @@ TEST_CASE("Read frame numbers from a raw file", "[.integration]") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Compare reading from a numpy file with a raw file", "[.files]") {
|
TEST_CASE("Compare reading from a numpy file with a raw file", "[.files]") {
|
||||||
auto fpath_raw =
|
|
||||||
test_data_path() / "raw/jungfrau" / "jungfrau_single_master_0.json";
|
|
||||||
REQUIRE(std::filesystem::exists(fpath_raw));
|
|
||||||
|
|
||||||
auto fpath_npy =
|
SECTION("jungfrau data") {
|
||||||
test_data_path() / "raw/jungfrau" / "jungfrau_single_0.npy";
|
auto fpath_raw =
|
||||||
REQUIRE(std::filesystem::exists(fpath_npy));
|
test_data_path() / "raw/jungfrau" / "jungfrau_single_master_0.json";
|
||||||
|
REQUIRE(std::filesystem::exists(fpath_raw));
|
||||||
|
|
||||||
File raw(fpath_raw, "r");
|
auto fpath_npy =
|
||||||
File npy(fpath_npy, "r");
|
test_data_path() / "raw/jungfrau" / "jungfrau_single_0.npy";
|
||||||
|
REQUIRE(std::filesystem::exists(fpath_npy));
|
||||||
|
|
||||||
CHECK(raw.total_frames() == 10);
|
File raw(fpath_raw, "r");
|
||||||
CHECK(npy.total_frames() == 10);
|
File npy(fpath_npy, "r");
|
||||||
|
|
||||||
for (size_t i = 0; i < 10; ++i) {
|
CHECK(raw.total_frames() == 10);
|
||||||
CHECK(raw.tell() == i);
|
CHECK(npy.total_frames() == 10);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < 10; ++i) {
|
||||||
|
CHECK(raw.tell() == i);
|
||||||
|
auto raw_frame = raw.read_frame();
|
||||||
|
auto npy_frame = npy.read_frame();
|
||||||
|
CHECK((raw_frame.view<uint16_t>() == npy_frame.view<uint16_t>()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("eiger quad data") {
|
||||||
|
auto fpath_raw =
|
||||||
|
test_data_path() / "raw/eiger_quad_data" /
|
||||||
|
"W13_vrpreampscan_m21C_300V_800eV_vthre2000_master_0.json";
|
||||||
|
REQUIRE(std::filesystem::exists(fpath_raw));
|
||||||
|
|
||||||
|
auto fpath_npy = test_data_path() / "raw/eiger_quad_data" /
|
||||||
|
"W13_vrpreampscan_m21C_300V_800eV_vthre2000.npy";
|
||||||
|
REQUIRE(std::filesystem::exists(fpath_npy));
|
||||||
|
|
||||||
|
File raw(fpath_raw, "r");
|
||||||
|
File npy(fpath_npy, "r");
|
||||||
|
|
||||||
|
raw.seek(20);
|
||||||
auto raw_frame = raw.read_frame();
|
auto raw_frame = raw.read_frame();
|
||||||
|
|
||||||
auto npy_frame = npy.read_frame();
|
auto npy_frame = npy.read_frame();
|
||||||
CHECK((raw_frame.view<uint16_t>() == npy_frame.view<uint16_t>()));
|
CHECK((raw_frame.view<uint32_t>() == npy_frame.view<uint32_t>()));
|
||||||
|
}
|
||||||
|
SECTION("eiger data") {
|
||||||
|
auto fpath_raw = test_data_path() / "raw/eiger" /
|
||||||
|
"Lab6_20500eV_2deg_20240629_master_7.json";
|
||||||
|
REQUIRE(std::filesystem::exists(fpath_raw));
|
||||||
|
|
||||||
|
auto fpath_npy =
|
||||||
|
test_data_path() / "raw/eiger" / "Lab6_20500eV_2deg_20240629_7.npy";
|
||||||
|
REQUIRE(std::filesystem::exists(fpath_npy));
|
||||||
|
|
||||||
|
File raw(fpath_raw, "r");
|
||||||
|
File npy(fpath_npy, "r");
|
||||||
|
|
||||||
|
auto raw_frame = raw.read_frame();
|
||||||
|
|
||||||
|
auto npy_frame = npy.read_frame();
|
||||||
|
CHECK((raw_frame.view<uint32_t>() == npy_frame.view<uint32_t>()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user