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: nxlog use time field as signal if missing #244

Merged
merged 1 commit into from
Oct 15, 2024
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
2 changes: 1 addition & 1 deletion src/scippnexus/nxdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def __init__(self, attrs: dict[str, Any], children: dict[str, Field | Group]):
attrs=attrs,
children=children,
fallback_dims=('time',),
fallback_signal_name='value',
fallback_signal_name='value' if 'value' in children else 'time',
)

def read_children(self, sel: ScippIndex) -> sc.DataGroup:
Expand Down
6 changes: 2 additions & 4 deletions tests/nxlog_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,14 @@ def test_nxobject_log(h5root):
assert sc.identical(log[...], da)


@pytest.mark.filterwarnings("ignore:Failed to load /entry/log:UserWarning")
def test_nxlog_with_missing_value_triggers_fallback(nxroot):
def test_nxlog_with_missing_value_uses_time_as_value(nxroot):
time = sc.epoch(unit='ns') + sc.array(
dims=['time'], unit='s', values=[4.4, 5.5, 6.6]
).to(unit='ns', dtype='int64')
log = nxroot['entry'].create_class('log', NXlog)
log['time'] = time - sc.epoch(unit='ns')
loaded = log[()]
# Fallback to DataGroup, but we still have partial info from NXlog: dim is time
assert_identical(loaded, sc.DataGroup(time=time))
assert_identical(loaded, sc.DataArray(data=time))


def test_nxlog_length_1(h5root):
Expand Down