Skip to content

Commit

Permalink
Merge pull request #16 from scipp/fix-0d-detector
Browse files Browse the repository at this point in the history
Fix NXdetector for 0-D detector_number field.
  • Loading branch information
SimonHeybrock authored Apr 11, 2022
2 parents ab256ae + 4e90e4c commit c994c5f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
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

0 comments on commit c994c5f

Please sign in to comment.