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

Test JSON NeXus with ScippNexus #475

Merged
merged 12 commits into from
Dec 7, 2023
Merged

Test JSON NeXus with ScippNexus #475

merged 12 commits into from
Dec 7, 2023

Conversation

jl-wynen
Copy link
Member

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

Fixes #454

I only translated a small number of test cases because the majority of old tests are now covered by ScippNexus. The new tests only check that JSONGroup works as a replacement for h5.Group. Please check if I missed some case!

The type hints in ScippNexus need to be updated for this. Or we make JSONGroup inherit from h5.Group.

@SimonHeybrock
Copy link
Member

The type hints in ScippNexus need to be updated for this. Or we make JSONGroup inherit from h5.Group.

Why? What needs updating? I thought ScippNexus is using some Protocol classes for this?

Copy link
Member

@SimonHeybrock SimonHeybrock left a comment

Choose a reason for hiding this comment

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

I think this looks good overall, minor comments:

Comment on lines +48 to +62
@pytest.mark.skip("TODO Stream handling with log not implemented")
def test_stream_object_as_transformation_results_in_warning():
builder = NexusBuilder()
builder.add_component(Source("source"))
stream_path = "/entry/streamed_nxlog_transform"
builder.add_stream(Stream(stream_path))
builder.add_dataset_at_path("/entry/source/depends_on", stream_path, {})

with pytest.warns(UserWarning):
loaded_data, _ = load_nexus_json_str(builder.json_string)

# A 0 distance translation is used in place of the streamed transformation
default = [0, 0, 0]
assert np.allclose(loaded_data["source_position"].values, default)
assert loaded_data["source_position"].unit == sc.Unit("m")
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 explain? You are using NexusBuilder, which you mentioned you planned to remove. Was this just copied from some old test?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is an old test. I only moved the file which is why it shows up in the diff.

"string_size": 20,
"type": "string",
"name": "offset",
"values": "1970-01-01T00:00:00Z"
Copy link
Member

Choose a reason for hiding this comment

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

Since this is the default, maybe we should choose another value here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea!

Comment on lines 111 to 113
# Using `loaded == expected` could fail if the order of events in the
# bins is different.
# Since the order is arbitrary, check that the bins have equal weights instead.
Copy link
Member

Choose a reason for hiding this comment

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

The order is not arbitrary: bin and group essentially perform a stable sort, i.e., all events mapping to the same bin are in the same order as they were in the input table.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is this guaranteed by the API?

Copy link
Member

Choose a reason for hiding this comment

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

Yes.

Comment on lines 167 to 169
# Using `loaded == expected` could fail if the order of events in the
# bins is different.
# Since the order is arbitrary, check that the bins have equal weights instead.
Copy link
Member

Choose a reason for hiding this comment

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

See above

"string_size": 20,
"type": "string",
"name": "start",
"values": "1970-01-01T00:00:00Z"
Copy link
Member

Choose a reason for hiding this comment

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

This is the NeXus default, pick another start to ensure it works correctly.

Copy link
Member Author

Choose a reason for hiding this comment

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

It looks like it is not handled.
Is "start" the correct name for the attribute? In the even data, it is called "offset".

Copy link
Member

Choose a reason for hiding this comment

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

@jl-wynen
Copy link
Member Author

jl-wynen commented Dec 6, 2023

The type hints in ScippNexus need to be updated for this. Or we make JSONGroup inherit from h5.Group.

Why? What needs updating? I thought ScippNexus is using some Protocol classes for this?

You are right. JSONGroup does not implement the protocol. And doing so does not make much sense because we don't need methods for writing data. But I can create those methods and simply raise NotImplementedError.

@jl-wynen jl-wynen merged commit 2385b16 into main Dec 7, 2023
7 checks passed
@jl-wynen jl-wynen deleted the json-nexus branch December 7, 2023 08:26
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.

Refactor JSON NeXus tests to use ScippNexus
2 participants