-
Notifications
You must be signed in to change notification settings - Fork 2
[ESSSPECTROSCOPY] Update BIFROST NeXus loader for angles #671
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -25,33 +25,57 @@ | |
| from ess.reduce.nexus.types import NeXusLocationSpec, TransformationTimeFilter | ||
|
|
||
|
|
||
| # See https://github.com/scipp/essreduce/issues/98 | ||
| def moderator_class_for_source() -> NeXusClass[snx.NXsource]: | ||
| """Select NXmoderator as the source.""" | ||
| return NeXusClass[snx.NXsource](snx.NXmoderator) | ||
|
|
||
|
|
||
| def load_sample_angle( | ||
| file_spec: NeXusFileSpec[RunType], | ||
| ) -> SampleAngle[RunType]: | ||
| return SampleAngle[RunType](_load_experiment_parameter(file_spec, "a3")) | ||
| """Load the rotation angle of a sample from a BIFROST NeXus file.""" | ||
| return SampleAngle[RunType]( | ||
| _load_rotation_angle( | ||
| file_spec, | ||
| "114_sample_stack/rotation_stage", | ||
| ) | ||
| ) | ||
|
|
||
|
|
||
| def load_instrument_angle( | ||
| file_spec: NeXusFileSpec[RunType], | ||
| ) -> InstrumentAngle[RunType]: | ||
| return InstrumentAngle[RunType](_load_experiment_parameter(file_spec, "a4")) | ||
| """Load the rotation angle for the BIFROST detector from a NeXus file.""" | ||
| return InstrumentAngle[RunType]( | ||
| _load_rotation_angle( | ||
| file_spec, | ||
| "detector_tank_angle/transformations/detector_tank_angle_r0", | ||
| ) | ||
| ) | ||
|
|
||
|
|
||
| def _load_experiment_parameter( | ||
| file_spec: NeXusFileSpec[RunType], param_name: str | ||
| ) -> sc.DataArray: | ||
| def _load_rotation_angle(file_spec: NeXusFileSpec[RunType], path: str) -> sc.DataArray: | ||
| with open_component_group( | ||
| NeXusLocationSpec(filename=file_spec.value), | ||
| nx_class=snx.NXparameters, | ||
| nx_class=snx.NXinstrument, | ||
| parent_class=snx.NXentry, | ||
| ) as group: | ||
| return group[param_name][()]['value'] | ||
| ) as instrument: | ||
| log: snx.Group = instrument[path] # type: ignore[assignment] | ||
| if isinstance(log['value'], snx.Group): | ||
| # The NXlog is nested in this group, e.g., the group can be an NXpositioner | ||
| # with children 'value', 'target_value', etc. | ||
| transform: snx.nxtransformations.Transform = log['value'][()] # type: ignore[assignment] | ||
|
Comment on lines
+59
to
+62
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still trying to understand whether this kind of nesting is a bug/bad and should be reported. Have had issues with this elsewhere. But no action here, as I presume it is necessary to make it work now.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it wouldn't work otherwise. |
||
| else: | ||
| # `log` is the NXlog we are looking for without further nesting. | ||
| transform: snx.nxtransformations.Transform = log[()] # type: ignore[assignment] | ||
|
|
||
| if transform.transformation_type != 'rotation': | ||
| raise ValueError( | ||
| "Expected the instrument angle at detector_tank_angle to be a rotation," | ||
| f" got '{transform.transformation_type}' instead.'" | ||
| ) | ||
| return transform.value # type: ignore[return-value] | ||
|
|
||
|
|
||
| # See https://github.com/scipp/ess/issues/120 | ||
| def moderator_class_for_source() -> NeXusClass[snx.NXsource]: | ||
| """Select NXmoderator as the source.""" | ||
| return NeXusClass[snx.NXsource](snx.NXmoderator) | ||
|
|
||
|
|
||
| def load_analyzer_for_detector( | ||
|
|
||
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.
So McStas stores this differently than PROD?
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.
The McStas files that Greg made have an
NXparametersgroup which doesn't exist in prod because it holds simulation params. The handling of nested value groups in the prod loader can load those data from mcstas files. Unfortunately, the sample stack does not exist in mcstas files. But the instrument angle can be loaded. So I could remove its special handler for mcstas. Should I?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.
Maybe?