-
Notifications
You must be signed in to change notification settings - Fork 3
Use ess.reduce.nexus NeXus workflows as basis for all workflows
#160
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
ffff74e
6a9beac
f290fb5
385cad1
627a50b
077bd86
067a935
e169cef
4a497e9
87d9d9c
0a8fac2
721212b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,45 +4,68 @@ | |
| Providers for the ISIS instruments. | ||
| """ | ||
|
|
||
| from typing import NewType | ||
|
|
||
| import sciline | ||
| import scipp as sc | ||
|
|
||
| from ..sans.types import ( | ||
| from ess.sans.types import ( | ||
| BeamCenter, | ||
| CalibratedDetector, | ||
| CalibratedMonitor, | ||
| CorrectForGravity, | ||
| DetectorData, | ||
| DetectorIDs, | ||
| DetectorPixelShape, | ||
| DetectorPositionOffset, | ||
| DimsToKeep, | ||
| Incident, | ||
| LabFrameTransform, | ||
| MonitorData, | ||
| MonitorPositionOffset, | ||
| MonitorType, | ||
| NeXusDetector, | ||
| NeXusMonitor, | ||
| NeXusMonitorName, | ||
| NonBackgroundWavelengthRange, | ||
| RawDetector, | ||
| RawMonitor, | ||
| RawMonitorData, | ||
| RunNumber, | ||
| RunTitle, | ||
| RunType, | ||
| SamplePosition, | ||
| SampleRun, | ||
| ScatteringRunType, | ||
| SourcePosition, | ||
| TofData, | ||
| TofMonitor, | ||
| Transmission, | ||
| WavelengthBands, | ||
| WavelengthMask, | ||
| ) | ||
| from .components import DetectorBankOffset, MonitorOffset, SampleOffset | ||
|
|
||
| from .io import LoadedFileContents | ||
| from .mantidio import Period | ||
|
|
||
|
|
||
| class MonitorOffset(sciline.Scope[MonitorType, sc.Variable], sc.Variable): | ||
| """ | ||
| Offset for monitor position for all runs. | ||
| """ | ||
|
|
||
|
|
||
| DetectorBankOffset = NewType('DetectorBankOffset', sc.Variable) | ||
| SampleOffset = NewType('SampleOffset', sc.Variable) | ||
|
|
||
|
|
||
| def default_parameters() -> dict: | ||
| return { | ||
| CorrectForGravity: False, | ||
| DimsToKeep: (), | ||
| MonitorOffset[Incident]: MonitorOffset(sc.vector([0, 0, 0], unit='m')), | ||
| MonitorOffset[Transmission]: MonitorOffset(sc.vector([0, 0, 0], unit='m')), | ||
| MonitorOffset[Incident]: MonitorOffset[Incident]( | ||
| sc.vector([0, 0, 0], unit='m') | ||
| ), | ||
| MonitorOffset[Transmission]: MonitorOffset[Transmission]( | ||
| sc.vector([0, 0, 0], unit='m') | ||
| ), | ||
| DetectorBankOffset: DetectorBankOffset(sc.vector([0, 0, 0], unit='m')), | ||
| SampleOffset: SampleOffset(sc.vector([0, 0, 0], unit='m')), | ||
| NonBackgroundWavelengthRange: None, | ||
|
|
@@ -52,45 +75,70 @@ def default_parameters() -> dict: | |
| } | ||
|
|
||
|
|
||
| def get_detector_data( | ||
| dg: LoadedFileContents[RunType], | ||
| sample_offset: SampleOffset, | ||
| detector_bank_offset: DetectorBankOffset, | ||
| ) -> RawDetector[RunType]: | ||
| def to_detector_position_offset( | ||
| global_offset: DetectorBankOffset, beam_center: BeamCenter | ||
| ) -> DetectorPositionOffset[RunType]: | ||
| return DetectorPositionOffset[RunType](global_offset - beam_center) | ||
|
|
||
|
|
||
| def to_monitor_position_offset( | ||
| global_offset: MonitorOffset[MonitorType], | ||
| ) -> MonitorPositionOffset[RunType, MonitorType]: | ||
| return MonitorPositionOffset[RunType, MonitorType](global_offset) | ||
|
|
||
|
|
||
| def get_source_position(dg: LoadedFileContents[RunType]) -> SourcePosition[RunType]: | ||
| """Get source position from raw data.""" | ||
| return SourcePosition[RunType](dg['data'].coords['source_position']) | ||
|
|
||
|
|
||
| def get_sample_position( | ||
| dg: LoadedFileContents[RunType], offset: SampleOffset | ||
| ) -> SamplePosition[RunType]: | ||
| """Get sample position from raw data and apply user offset.""" | ||
| return SamplePosition[RunType]( | ||
| dg['data'].coords['sample_position'] + offset.to(unit='m') | ||
| ) | ||
|
|
||
|
|
||
| def get_detector_data(dg: LoadedFileContents[RunType]) -> NeXusDetector[RunType]: | ||
| """Get detector data and apply user offsets to raw data. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| dg: | ||
| Data loaded with Mantid and converted to Scipp. | ||
| sample_offset: | ||
| Sample offset. | ||
| detector_bank_offset: | ||
| Detector bank offset. | ||
| """ | ||
| data = dg['data'] | ||
| sample_pos = data.coords['sample_position'] | ||
| sample_pos = sample_pos + sample_offset.to(unit=sample_pos.unit, copy=False) | ||
| pos = data.coords['position'] | ||
| pos = pos + detector_bank_offset.to(unit=pos.unit, copy=False) | ||
| return RawDetector[RunType]( | ||
| dg['data'].assign_coords(position=pos, sample_position=sample_pos) | ||
| # The generic NeXus workflow will try to extract 'data' from this, which is exactly | ||
| # what we also have in the Mantid data. We use the generic workflow since it also | ||
| # applies offsets, etc. | ||
| return NeXusDetector[RunType](dg) | ||
|
|
||
|
|
||
| def get_monitor_data( | ||
| dg: LoadedFileContents[RunType], nexus_name: NeXusMonitorName[MonitorType] | ||
| ) -> NeXusMonitor[RunType, MonitorType]: | ||
| # The generic NeXus workflow will try to extract 'data' from this, which is exactly | ||
| # what we also have in the Mantid data. We use the generic workflow since it also | ||
| # applies offsets, etc. | ||
| monitor = dg['monitors'][nexus_name]['data'] | ||
| return NeXusMonitor[RunType, MonitorType]( | ||
| sc.DataGroup(data=monitor, position=monitor.coords['position']) | ||
| ) | ||
|
|
||
|
|
||
| def assemble_detector_data( | ||
| def dummy_assemble_detector_data( | ||
| detector: CalibratedDetector[RunType], | ||
| ) -> DetectorData[RunType]: | ||
| """Dummy assembly of detector data, detector already contains neutron data.""" | ||
| return DetectorData[RunType](detector) | ||
|
|
||
|
|
||
| def get_monitor_data( | ||
| dg: LoadedFileContents[RunType], nexus_name: NeXusMonitorName[MonitorType] | ||
| ) -> RawMonitor[RunType, MonitorType]: | ||
| # See https://github.com/scipp/sciline/issues/52 why copy needed | ||
| mon = dg['monitors'][nexus_name]['data'].copy() | ||
|
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. Is the need for this copy now gone? The issue is still open...
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. I think we are not actually accessing a |
||
| return RawMonitor[RunType, MonitorType](mon) | ||
| def dummy_assemble_monitor_data( | ||
| monitor: CalibratedMonitor[RunType, MonitorType], | ||
| ) -> MonitorData[RunType, MonitorType]: | ||
| """Dummy assembly of monitor data, monitor already contains neutron data.""" | ||
| return MonitorData[RunType, MonitorType](monitor) | ||
|
|
||
|
|
||
| def data_to_tof( | ||
|
|
@@ -102,7 +150,7 @@ def data_to_tof( | |
|
|
||
|
|
||
| def monitor_to_tof( | ||
| da: RawMonitorData[RunType, MonitorType], | ||
| da: MonitorData[RunType, MonitorType], | ||
| ) -> TofMonitor[RunType, MonitorType]: | ||
| """Dummy conversion of monitor data to time-of-flight data. | ||
| The monitor data already has a time-of-flight coordinate.""" | ||
|
|
@@ -166,7 +214,12 @@ def get_detector_ids_from_sample_run(data: TofData[SampleRun]) -> DetectorIDs: | |
|
|
||
|
|
||
| providers = ( | ||
| assemble_detector_data, | ||
| dummy_assemble_detector_data, | ||
| dummy_assemble_monitor_data, | ||
| to_detector_position_offset, | ||
| to_monitor_position_offset, | ||
| get_source_position, | ||
| get_sample_position, | ||
| get_detector_data, | ||
| get_detector_ids_from_sample_run, | ||
| get_monitor_data, | ||
|
|
||
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.
These two helpers replace logic in the removed
components.py, which was mostly duplicating more generic code.