Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NXdetector for 0-D detector_number field. #16

Merged
merged 4 commits into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/scippnexus/nxdetector.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def __getitem__(self, select: ScippIndex) -> sc.DataArray:
dtype=id_min.dtype)
else:
detector_number = self._detector_number[select]
event_id = detector_number.flatten(to='event_id')
# copy since sc.bin cannot deal with a non-contiguous view
event_id = detector_number.flatten(to='event_id').copy()
event_data.bins.coords['event_time_zero'] = sc.bins_like(
event_data, fill_value=event_data.coords['event_time_zero'])
# After loading raw NXevent_data it is guaranteed that the event table
Expand Down
10 changes: 10 additions & 0 deletions tests/nxdetector_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ def test_loads_event_data_mapped_to_detector_numbers_based_on_their_event_id(nxr
assert 'event_time_zero' in loaded.bins.coords


def test_loads_event_data_with_0d_detector_numbers(nxroot):
detector = nxroot.create_class('detector0', NX_class.NXdetector)
detector.create_field('detector_number', sc.index(1, dtype='int64'))
create_event_data_ids_1234(detector.create_class('events', NX_class.NXevent_data))
assert detector.dims == []
assert detector.shape == []
loaded = detector[...]
assert sc.identical(loaded.bins.size().data, sc.index(2, dtype='int64'))


def test_loads_event_data_with_2d_detector_numbers(nxroot):
detector = nxroot.create_class('detector0', NX_class.NXdetector)
detector.create_field('detector_number', detector_numbers_xx_yy_1234())
Expand Down