Skip to content

Commit

Permalink
Merge pull request #17 from scipp/fix-nxlog-length-1
Browse files Browse the repository at this point in the history
Avoid squeezing in NXlog of length 1
  • Loading branch information
SimonHeybrock authored Apr 11, 2022
2 parents 625ee32 + b0a40c8 commit ab256ae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/scippnexus/nxlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ def _nxbase(self) -> NXdata:
# The outermost axis in NXlog is pre-defined to 'time' (if present). Note
# that this may be overriden by an `axes` attribute, if defined for the group.
if 'time' in self:
axes[0] = 'time'
if len(axes) == 0: # shape=(1,) was squeezed, log has only a single value
axes = ['time']
else:
axes[0] = 'time'
# NXdata uses the 'signal' attribute to define the field name of the signal.
# NXlog uses a "hard-coded" signal name 'value', without specifying the
# attribute in the file, so we pass this explicitly to NXdata.
Expand Down
15 changes: 15 additions & 0 deletions tests/nexus_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ def test_nxobject_log(nxroot):
assert sc.identical(log[...], da)


def test_nxobject_log_length_1(nxroot):
da = sc.DataArray(
sc.array(dims=['time'], values=[1.1]),
coords={
'time':
sc.epoch(unit='ns') +
sc.array(dims=['time'], unit='s', values=[4.4]).to(unit='ns', dtype='int64')
})
log = nxroot['entry'].create_class('log', NX_class.NXlog)
log['value'] = da.data
log['time'] = da.coords['time'] - sc.epoch(unit='ns')
assert log.nx_class == NX_class.NXlog
assert sc.identical(log[...], da)


def test_nxobject_event_data(nxroot):
event_data = nxroot['entry'].create_class('events_0', NX_class.NXevent_data)
assert event_data.nx_class == NX_class.NXevent_data
Expand Down

0 comments on commit ab256ae

Please sign in to comment.