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

Save errors in create_field #167

Merged
merged 4 commits into from
Oct 10, 2023
Merged

Save errors in create_field #167

merged 4 commits into from
Oct 10, 2023

Conversation

jl-wynen
Copy link
Member

@jl-wynen jl-wynen commented Oct 5, 2023

Fixes #105

values_dataset.attrs.update(attrs)
if errors is not None:
errors_dataset = group.create_dataset(name + '_errors', data=errors, **kwargs)
errors_dataset.attrs.update(attrs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure the units attribute (or any others) should we written here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the other hand... I can't see any harm, even if the standard does not require it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the standard is silent on this. I did it just in case they are useful. But I'm fine with not writing them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check with Tobias? If the standard does not specify them, maybe we should not write them either. Otherwise we may end up in situations where our reading code (which uses this for testing) only works with files that where written using ScippNexus.

@@ -235,13 +235,14 @@ def _make_child(obj: Union[H5Dataset, H5Group]) -> Union[Field, Group]:
items = {k: v for k, v in items.items() if not k.startswith('cue_')}
for suffix in ('_errors', '_error'):
field_with_errors = [name for name in items if f'{name}{suffix}' in items]
print(suffix, field_with_errors)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print(suffix, field_with_errors)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -434,6 +434,24 @@ def test_errors_read_as_variances(h5root):
assert np.array_equal(dg['time'].variances, np.arange(5.0) ** 2)


def test_does_not_require_unit_of_errors(h5root):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the latest change, is there a test that checks behavior for mismatching error units?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes:

def test_field_errors_with_different_unit_handles_them_individually(nxroot):

@jl-wynen jl-wynen merged commit d007479 into main Oct 10, 2023
@jl-wynen jl-wynen deleted the save-variances branch October 10, 2023 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NXobject.create_field and __setitem__ ignoring variances when passing scipp.Variable?
2 participants