|
| 1 | +# SPDX-License-Identifier: BSD-3-Clause |
| 2 | +# Copyright (c) 2023 Scipp contributors (https://github.com/scipp) |
| 3 | +import pytest |
| 4 | + |
| 5 | +from ess import dream |
| 6 | + |
| 7 | + |
| 8 | +@pytest.fixture |
| 9 | +def filename(): |
| 10 | + return dream.data.get_path('DREAM_nexus_sorted-2023-12-07.nxs') |
| 11 | + |
| 12 | + |
| 13 | +@pytest.mark.filterwarnings("ignore:Failed to load /entry/instrument/monitor_bunker") |
| 14 | +@pytest.mark.filterwarnings("ignore:Failed to load /entry/instrument/monitor_cave") |
| 15 | +@pytest.mark.filterwarnings("ignore:Failed to load /entry/instrument/polarizer/rate") |
| 16 | +@pytest.mark.filterwarnings("ignore:Failed to load /entry/instrument/sans_detector") |
| 17 | +def test_load_nexus_loads_file(filename): |
| 18 | + dg = dream.load_nexus(filename) |
| 19 | + assert 'instrument' in dg |
| 20 | + instr = dg['instrument'] |
| 21 | + for name in ( |
| 22 | + 'mantle', |
| 23 | + 'endcap_backward', |
| 24 | + 'endcap_forward', |
| 25 | + 'high_resolution', |
| 26 | + 'sans', |
| 27 | + ): |
| 28 | + assert f'{name}_detector' in instr |
| 29 | + det = instr[f'{name}_detector'] |
| 30 | + assert 'pixel_shape' not in det |
| 31 | + |
| 32 | + |
| 33 | +def test_load_nexus_fails_if_entry_not_found(filename): |
| 34 | + with pytest.raises(KeyError): |
| 35 | + dream.load_nexus(filename, entry='foo') |
| 36 | + |
| 37 | + |
| 38 | +@pytest.mark.filterwarnings("ignore:Failed to load /entry/instrument/monitor_bunker") |
| 39 | +@pytest.mark.filterwarnings("ignore:Failed to load /entry/instrument/monitor_cave") |
| 40 | +@pytest.mark.filterwarnings("ignore:Failed to load /entry/instrument/polarizer/rate") |
| 41 | +@pytest.mark.filterwarnings("ignore:Failed to load /entry/instrument/sans_detector") |
| 42 | +def test_load_nexus_folds_detectors_by_default(filename): |
| 43 | + dg = dream.load_nexus(filename) |
| 44 | + instr = dg['instrument'] |
| 45 | + # sans_detector is not populated in the current files |
| 46 | + for name in ('mantle', 'endcap_backward', 'endcap_forward', 'high_resolution'): |
| 47 | + det = instr[f'{name}_detector'] |
| 48 | + # There may be other dims, but some are irregular and this may be subject to |
| 49 | + # change |
| 50 | + assert 'strip' in det.dims |
| 51 | + |
| 52 | + |
| 53 | +@pytest.mark.filterwarnings("ignore:Failed to load /entry/instrument/monitor_bunker") |
| 54 | +@pytest.mark.filterwarnings("ignore:Failed to load /entry/instrument/monitor_cave") |
| 55 | +@pytest.mark.filterwarnings("ignore:Failed to load /entry/instrument/polarizer/rate") |
| 56 | +@pytest.mark.filterwarnings("ignore:Failed to load /entry/instrument/sans_detector") |
| 57 | +def test_load_nexus_with_disabled_fold(filename): |
| 58 | + dg = dream.load_nexus(filename, fold_detectors=False) |
| 59 | + instr = dg['instrument'] |
| 60 | + for name in ('mantle', 'endcap_backward', 'endcap_forward', 'high_resolution'): |
| 61 | + det = instr[f'{name}_detector'] |
| 62 | + assert det.dims == ('detector_number',) |
| 63 | + |
| 64 | + |
| 65 | +@pytest.mark.filterwarnings("ignore:Failed to load /entry/instrument/monitor_bunker") |
| 66 | +@pytest.mark.filterwarnings("ignore:Failed to load /entry/instrument/monitor_cave") |
| 67 | +@pytest.mark.filterwarnings("ignore:Failed to load /entry/instrument/polarizer/rate") |
| 68 | +@pytest.mark.filterwarnings("ignore:Failed to load /entry/instrument/sans_detector") |
| 69 | +def test_load_nexus_with_pixel_shape(filename): |
| 70 | + dg = dream.load_nexus(filename, load_pixel_shape=True) |
| 71 | + assert 'instrument' in dg |
| 72 | + instr = dg['instrument'] |
| 73 | + # sans_detector is not populated in the current files |
| 74 | + for name in ('mantle', 'endcap_backward', 'endcap_forward', 'high_resolution'): |
| 75 | + assert f'{name}_detector' in instr |
| 76 | + det = instr[f'{name}_detector'] |
| 77 | + assert 'pixel_shape' in det |
0 commit comments