Skip to content

Commit

Permalink
Add test for distinguishing raw & proc sources in components
Browse files Browse the repository at this point in the history
  • Loading branch information
takluyver committed Sep 26, 2024
1 parent 26fa54d commit 997ae1d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion extra_data/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def __init__(self, data: DataCollection, detector_name=None, modules=None,
raise ValueError("min_modules must be a positive integer, not "
f"{min_modules!r}")

source_to_modno = self._identify_sources(data, detector_name, modules)
source_to_modno = self._identify_sources(data, detector_name, modules, raw=raw)

data = data.select([(src, '*') for src in source_to_modno])
self.detector_name = detector_name
Expand Down
5 changes: 5 additions & 0 deletions extra_data/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ def mock_spb_raw_and_proc_run():

yield td, raw_run_dir, proc_run_dir

@pytest.fixture(scope='session')
def mock_spb_raw_run_fmt1():
with TemporaryDirectory() as td:
make_examples.make_spb_run(td, format_version="1.2")
yield td

@pytest.fixture(scope='session')
def mock_modern_spb_proc_run():
Expand Down
32 changes: 32 additions & 0 deletions extra_data/tests/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,38 @@ def test_iterate_jungfrau(mock_jungfrau_run):
assert d['data.adc'].dims == ('module', 'cell', 'slow_scan', 'fast_scan')


def test_modern_corr_sources(mock_modern_spb_proc_run, mock_spb_raw_run_fmt1):
run_raw = RunDirectory(mock_spb_raw_run_fmt1)
run_proc = RunDirectory(mock_modern_spb_proc_run)
combined = run_raw.union(run_proc.select("*/CORR/*:output"))

corr_sources = {f'SPB_DET_AGIPD1M-1/CORR/{i}CH0:output' for i in range(16)}
det_sources = {f'SPB_DET_AGIPD1M-1/DET/{i}CH0:xtdf' for i in range(16)}

# Specify that we want raw data
assert AGIPD1M(run_raw, raw=True).data.all_sources == det_sources
with pytest.raises(Exception):
AGIPD1M(run_proc, raw=True)
agipd_raw = AGIPD1M(combined, raw=True)
assert agipd_raw.data.all_sources == det_sources
assert 'image.mask' not in agipd_raw

# Specify that we want corrected data
with pytest.raises(Exception):
AGIPD1M(run_raw, raw=False)
assert AGIPD1M(run_proc, raw=False).data.all_sources == corr_sources
agipd_proc = AGIPD1M(combined, raw=False)
assert agipd_proc.data.all_sources == corr_sources
assert 'image.mask' in agipd_proc

# Legacy behaviour: prefer corrected, allow raw if only that is found
assert AGIPD1M(run_raw).data.all_sources == det_sources
assert AGIPD1M(run_proc).data.all_sources == corr_sources
agipd_dflt = AGIPD1M(combined)
assert agipd_dflt.data.all_sources == corr_sources
assert 'image.mask' in agipd_dflt


def test_write_virtual_cxi(mock_spb_proc_run, tmpdir):
run = RunDirectory(mock_spb_proc_run)
det = AGIPD1M(run)
Expand Down

0 comments on commit 997ae1d

Please sign in to comment.