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 exception when loading NXdata with NXlog signal #126

Merged
merged 6 commits into from
Apr 17, 2023
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
11 changes: 11 additions & 0 deletions docs/about/release-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ Release Notes
Neil Vaytet :sup:`a`\ ,
and Jan-Lukas Wynen :sup:`a`

v23.04.0
--------

Features
~~~~~~~~

* Added the future API of ``scippnexus`` as ``scippnexus.v2``.
For many users the API changes will be minor.
The old API will be deprecated soon and users should try to migrate to the new API.
Note that ``v2`` is not fully stable yet and in particular the behavior in edge cases is subject to change.

v23.03.0
--------

Expand Down
5 changes: 5 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ This is especially powerful since a number of concepts of Scipp map well to conc
News
----

- [April 2023] scippnexus-23.04.0 has been released.
This adds ``scippnexus.v2``, which provides the future API of ``scippnexus``.
The new API avoids performance bottlenecks when working with small files that contain many groups and datasets.
The new behavior is also more faithful to the file content.
``v2`` will become the default in the near future.
- [March 2023] scippnexus-23.03.0 has been released.
This brings a number of improvements, including handling of legacy files and loading of geometry information.
- [January 2023] scippnexus-23.01.0 has been released.
Expand Down
11 changes: 11 additions & 0 deletions src/scippnexus/v2/nxdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ def __init__(self,
self._valid = False

def _init_signal(self, name: Optional[str], children):
# There are multiple ways NeXus can define the "signal" dataset. The latest
# version uses `signal` attribute on the group (passed as `name`). However,
# we must give precedence to the `signal` attribute on the dataset, since
# older files may use that (and the `signal` group attribute is unrelated).
# Finally, NXlog and NXevent_data can take the role of the signal. In practice
# those may not be indicate by a `signal` attribute, but we support that
# anyway since otherwise we would not be able to find NXevent_data signals
# in many common files.
if name is not None and name in children:
self._signal_name = name
self._signal = children[name]
Expand All @@ -102,6 +110,9 @@ def _init_signal(self, name: Optional[str], children):
break
# NXlog or NXevent_data can take the role of the signal.
for name, field in children.items():
if name == self._signal_name:
# Avoid duplicate handling
continue
if isinstance(field,
EventField) or (isinstance(field, Group)
and field.nx_class in [NXlog, NXevent_data]):
Expand Down
17 changes: 17 additions & 0 deletions tests/nxdata_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,23 @@ def test_auxiliary_signal_causes_load_as_dataset(h5root):
assert_identical(data[...], sc.Dataset({'signal': da.data, 'xx': da.coords['xx']}))


def test_NXlog_data_is_loaded_as_time_dependent_data_array(nxroot):
da = sc.DataArray(data=sc.array(dims=['time'], unit='K', values=[1, 2, 3]),
coords={
'time':
sc.epoch(unit='s') +
sc.array(dims=['time'], unit='s', values=[1, 2, 3])
})
data = nxroot.create_class('data1', NXdata)
log = data.create_class('data', NXlog)
log['time'] = da.coords['time']
log['value'] = da.data
data._group.attrs['signal'] = 'data'

loaded = data[()]
assert_identical(loaded, da)


def test_field_dims_match_NXdata_dims(h5root):
da = sc.DataArray(
sc.array(dims=['xx', 'yy'], unit='m', values=[[1, 2, 3], [4, 5, 6]]))
Expand Down