mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-12 23:37:13 +02:00
Developer (#164)
- State before merging the new cluster vector API --------- Co-authored-by: Patrick <patrick.sieberer@psi.ch> Co-authored-by: JulianHeymes <julian.heymes@psi.ch> Co-authored-by: Dhanya Thattil <dhanya.thattil@psi.ch> Co-authored-by: Xiangyu Xie <45243914+xiangyuxie@users.noreply.github.com> Co-authored-by: xiangyu.xie <xiangyu.xie@psi.ch> Co-authored-by: siebsi <sieb.patr@gmail.com>
This commit is contained in:
29
python/tests/conftest.py
Normal file
29
python/tests/conftest.py
Normal file
@ -0,0 +1,29 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import pytest
|
||||
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
parser.addoption(
|
||||
"--files", action="store_true", default=False, help="run slow tests"
|
||||
)
|
||||
|
||||
|
||||
def pytest_configure(config):
|
||||
config.addinivalue_line("markers", "files: mark test as needing image files to run")
|
||||
|
||||
|
||||
def pytest_collection_modifyitems(config, items):
|
||||
if config.getoption("--files"):
|
||||
return
|
||||
skip = pytest.mark.skip(reason="need --files option to run")
|
||||
for item in items:
|
||||
if "files" in item.keywords:
|
||||
item.add_marker(skip)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_data_path():
|
||||
return Path(os.environ["AARE_TEST_DATA"])
|
||||
|
36
python/tests/test_RawSubFile.py
Normal file
36
python/tests/test_RawSubFile.py
Normal file
@ -0,0 +1,36 @@
|
||||
import pytest
|
||||
import numpy as np
|
||||
from aare import RawSubFile, DetectorType
|
||||
|
||||
|
||||
@pytest.mark.files
|
||||
def test_read_a_jungfrau_RawSubFile(test_data_path):
|
||||
with RawSubFile(test_data_path / "raw/jungfrau/jungfrau_single_d0_f1_0.raw", DetectorType.Jungfrau, 512, 1024, 16) as f:
|
||||
assert f.frames_in_file == 3
|
||||
|
||||
headers, frames = f.read()
|
||||
|
||||
assert headers.size == 3
|
||||
assert frames.shape == (3, 512, 1024)
|
||||
|
||||
# Frame numbers in this file should be 4, 5, 6
|
||||
for i,h in zip(range(4,7,1), headers):
|
||||
assert h["frameNumber"] == i
|
||||
|
||||
# Compare to canned data using numpy
|
||||
data = np.load(test_data_path / "raw/jungfrau/jungfrau_single_0.npy")
|
||||
assert np.all(data[3:6] == frames)
|
||||
|
||||
@pytest.mark.files
|
||||
def test_iterate_over_a_jungfrau_RawSubFile(test_data_path):
|
||||
|
||||
data = np.load(test_data_path / "raw/jungfrau/jungfrau_single_0.npy")
|
||||
|
||||
with RawSubFile(test_data_path / "raw/jungfrau/jungfrau_single_d0_f0_0.raw", DetectorType.Jungfrau, 512, 1024, 16) as f:
|
||||
i = 0
|
||||
for header, frame in f:
|
||||
assert header["frameNumber"] == i+1
|
||||
assert np.all(frame == data[i])
|
||||
i += 1
|
||||
assert i == 3
|
||||
assert header["frameNumber"] == 3
|
92
python/tests/test_jungfrau_dat_files.py
Normal file
92
python/tests/test_jungfrau_dat_files.py
Normal file
@ -0,0 +1,92 @@
|
||||
import pytest
|
||||
import numpy as np
|
||||
from aare import JungfrauDataFile
|
||||
|
||||
@pytest.mark.files
|
||||
def test_jfungfrau_dat_read_number_of_frames(test_data_path):
|
||||
with JungfrauDataFile(test_data_path / "dat/AldoJF500k_000000.dat") as dat_file:
|
||||
assert dat_file.total_frames == 24
|
||||
|
||||
with JungfrauDataFile(test_data_path / "dat/AldoJF250k_000000.dat") as dat_file:
|
||||
assert dat_file.total_frames == 53
|
||||
|
||||
with JungfrauDataFile(test_data_path / "dat/AldoJF65k_000000.dat") as dat_file:
|
||||
assert dat_file.total_frames == 113
|
||||
|
||||
|
||||
@pytest.mark.files
|
||||
def test_jfungfrau_dat_read_number_of_file(test_data_path):
|
||||
with JungfrauDataFile(test_data_path / "dat/AldoJF500k_000000.dat") as dat_file:
|
||||
assert dat_file.n_files == 4
|
||||
|
||||
with JungfrauDataFile(test_data_path / "dat/AldoJF250k_000000.dat") as dat_file:
|
||||
assert dat_file.n_files == 7
|
||||
|
||||
with JungfrauDataFile(test_data_path / "dat/AldoJF65k_000000.dat") as dat_file:
|
||||
assert dat_file.n_files == 7
|
||||
|
||||
|
||||
@pytest.mark.files
|
||||
def test_read_module(test_data_path):
|
||||
"""
|
||||
Read all frames from the series of .dat files. Compare to canned data in npz format.
|
||||
"""
|
||||
|
||||
# Read all frames from the .dat file
|
||||
with JungfrauDataFile(test_data_path / "dat/AldoJF500k_000000.dat") as f:
|
||||
header, data = f.read()
|
||||
|
||||
#Sanity check
|
||||
n_frames = 24
|
||||
assert header.size == n_frames
|
||||
assert data.shape == (n_frames, 512, 1024)
|
||||
|
||||
# Read reference data using numpy
|
||||
with np.load(test_data_path / "dat/AldoJF500k.npz") as f:
|
||||
ref_header = f["headers"]
|
||||
ref_data = f["frames"]
|
||||
|
||||
# Check that the data is the same
|
||||
assert np.all(ref_header == header)
|
||||
assert np.all(ref_data == data)
|
||||
|
||||
@pytest.mark.files
|
||||
def test_read_half_module(test_data_path):
|
||||
|
||||
# Read all frames from the .dat file
|
||||
with JungfrauDataFile(test_data_path / "dat/AldoJF250k_000000.dat") as f:
|
||||
header, data = f.read()
|
||||
|
||||
n_frames = 53
|
||||
assert header.size == n_frames
|
||||
assert data.shape == (n_frames, 256, 1024)
|
||||
|
||||
# Read reference data using numpy
|
||||
with np.load(test_data_path / "dat/AldoJF250k.npz") as f:
|
||||
ref_header = f["headers"]
|
||||
ref_data = f["frames"]
|
||||
|
||||
# Check that the data is the same
|
||||
assert np.all(ref_header == header)
|
||||
assert np.all(ref_data == data)
|
||||
|
||||
|
||||
@pytest.mark.files
|
||||
def test_read_single_chip(test_data_path):
|
||||
|
||||
# Read all frames from the .dat file
|
||||
with JungfrauDataFile(test_data_path / "dat/AldoJF65k_000000.dat") as f:
|
||||
header, data = f.read()
|
||||
|
||||
n_frames = 113
|
||||
assert header.size == n_frames
|
||||
assert data.shape == (n_frames, 256, 256)
|
||||
|
||||
# Read reference data using numpy
|
||||
with np.load(test_data_path / "dat/AldoJF65k.npz") as f:
|
||||
ref_header = f["headers"]
|
||||
ref_data = f["frames"]
|
||||
|
||||
# Check that the data is the same
|
||||
assert np.all(ref_header == header)
|
||||
assert np.all(ref_data == data)
|
Reference in New Issue
Block a user