-
Notifications
You must be signed in to change notification settings - Fork 1
Add load_field and load_group to allow loading custom entries using GenericNeXusWorkflow #278
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
681179c
50ad6a0
43df02f
ca661a1
b95ef2f
8fbb233
f5a448e
49b4b4c
e18cd6b
c43c1b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,11 +4,12 @@ | |
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| import sciline as sl | ||
| import scipp as sc | ||
| import scippnexus as snx | ||
| from scipp.testing import assert_identical | ||
|
|
||
| from ess.reduce.nexus import compute_component_position, workflow | ||
| from ess.reduce.nexus import compute_component_position, load_component, workflow | ||
| from ess.reduce.nexus.types import ( | ||
| BackgroundRun, | ||
| Beamline, | ||
|
|
@@ -776,3 +777,53 @@ def assert_not_contains_type_arg(node: object, excluded: set[type]) -> None: | |
| assert not any( | ||
| arg in excluded for arg in getattr(node, "__args__", ()) | ||
| ), f"Node {node} contains one of {excluded!r}" | ||
|
|
||
|
|
||
| def test_generic_nexus_workflow_load_custom_component_user_affiliation( | ||
| loki_tutorial_sample_run_60250: Path, | ||
| ) -> None: | ||
| # Load a component in one of the top-level entries | ||
|
|
||
| class UserAffiliation(sl.Scope[RunType, str], str): | ||
| """User affiliation.""" | ||
|
|
||
| def load_user_affiliation( | ||
| location: NeXusComponentLocationSpec[UserAffiliation, RunType], | ||
| ) -> UserAffiliation[RunType]: | ||
| return UserAffiliation[RunType]( | ||
| load_component(location, nx_class=snx.NXuser)['affiliation'] | ||
|
||
| ) | ||
|
|
||
| wf = GenericNeXusWorkflow( | ||
| run_types=[SampleRun], monitor_types=[], component_types=[UserAffiliation] | ||
| ) | ||
| wf.insert(load_user_affiliation) | ||
| wf[Filename[SampleRun]] = loki_tutorial_sample_run_60250 | ||
| wf[NeXusName[UserAffiliation]] = '/entry/user_0' | ||
| affiliation = wf.compute(UserAffiliation[SampleRun]) | ||
| assert affiliation == 'ESS' | ||
|
|
||
|
|
||
| def test_generic_nexus_workflow_load_custom_component_source_name( | ||
| loki_tutorial_sample_run_60250: Path, | ||
| ) -> None: | ||
| # Load a component inside the instrument entry | ||
|
|
||
| class SourceName(sl.Scope[RunType, str], str): | ||
| """Source name.""" | ||
|
|
||
| def load_source_name( | ||
| location: NeXusComponentLocationSpec[SourceName, RunType], | ||
| ) -> SourceName[RunType]: | ||
| return SourceName[RunType]( | ||
| load_component(location, nx_class=snx.NXsource)['name'] | ||
| ) | ||
|
|
||
| wf = GenericNeXusWorkflow( | ||
| run_types=[SampleRun], monitor_types=[], component_types=[SourceName] | ||
| ) | ||
| wf.insert(load_source_name) | ||
| wf[Filename[SampleRun]] = loki_tutorial_sample_run_60250 | ||
| wf[NeXusName[SourceName]] = '/entry/instrument/source' | ||
| source_name = wf.compute(SourceName[SampleRun]) | ||
| assert source_name == 'moderator' | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why we needed to have the monitor_types here, when we are loading detectors?
So I removed it.