mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2026-11-04 23:03:12 +01:00
stuff needed for JungfrauCalibration: - added fit boundaries to fit function (needed to only fit a certain range, faster than iterating over it in python) - added Jungfrau Geometry definitions - added mean_over_dataset (takes the mean over some aqcuisitions in a file - added read_current_source (reads current_source data from Jungfrau and averages) - added configurable option to fit elastic scattering in fit modules - added bad channel mask to PedestalTrackingHistogram
62 lines
1.9 KiB
Python
62 lines
1.9 KiB
Python
# SPDX-License-Identifier: MPL-2.0
|
|
import os
|
|
from pathlib import Path
|
|
import pytest
|
|
import numpy as np
|
|
|
|
|
|
|
|
def pytest_addoption(parser):
|
|
parser.addoption(
|
|
"--with-data", action="store_true", default=False, help="Run tests that require additional data"
|
|
)
|
|
|
|
|
|
def pytest_configure(config):
|
|
config.addinivalue_line("markers", "withdata: mark test as needing image files to run")
|
|
|
|
|
|
def pytest_collection_modifyitems(config, items):
|
|
if config.getoption("--with-data"):
|
|
return
|
|
skip = pytest.mark.skip(reason="need --with-data option to run")
|
|
for item in items:
|
|
if "withdata" in item.keywords:
|
|
item.add_marker(skip)
|
|
|
|
|
|
@pytest.fixture
|
|
def test_data_path():
|
|
env_value = os.environ.get("AARE_TEST_DATA")
|
|
if not env_value:
|
|
raise RuntimeError("Environment variable AARE_TEST_DATA is not set or is empty")
|
|
|
|
return Path(env_value)
|
|
|
|
|
|
@pytest.fixture
|
|
def create_temporary_jungfrau_files(tmp_path):
|
|
"""Factory fixture: writes a Jungfrau raw file set into tmp_path and returns the path of the first file."""
|
|
|
|
JungfrauDataHeader = np.dtype([("framenum", np.uint64), ("bunchid", np.uint64)])
|
|
|
|
def _create(num_frames, frame_generator, num_files=1):
|
|
master_path = tmp_path / "aare-raw"
|
|
master_path.mkdir(exist_ok=True)
|
|
|
|
frames_per_file = num_frames // num_files
|
|
|
|
for file_index in range(num_files):
|
|
start_frame = file_index * frames_per_file
|
|
end_frame = num_frames if file_index == num_files - 1 else start_frame + frames_per_file
|
|
|
|
with open(master_path / f"JungfrauTest_{file_index:06}.dat", "wb") as f:
|
|
for frame in range(start_frame, end_frame):
|
|
# header
|
|
f.write(np.array([(frame, 0)], dtype=JungfrauDataHeader).tobytes())
|
|
f.write(np.ascontiguousarray(frame_generator(frame), dtype=np.uint16).tobytes())
|
|
|
|
return master_path / "JungfrauTest_000000.dat"
|
|
|
|
return _create
|