-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from scipp/user-position-config
Add mechanism for setting sample and detector bank offset in Zoom workflow
- Loading branch information
Showing
4 changed files
with
66 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# Copyright (c) 2024 Scipp contributors (https://github.com/scipp) | ||
from typing import NewType | ||
|
||
import sciline | ||
import scipp as sc | ||
|
||
from ..types import RawData, RunType | ||
|
||
|
||
class RawDataWithComponentUserOffsets( | ||
sciline.Scope[RunType, sc.DataArray], sc.DataArray | ||
): | ||
"""Raw data with applied user configuration for component positions.""" | ||
|
||
|
||
SampleOffset = NewType('SampleOffset', sc.Variable) | ||
DetectorBankOffset = NewType('DetectorBankOffset', sc.Variable) | ||
|
||
|
||
def apply_component_user_offsets_to_raw_data( | ||
data: RawData[RunType], | ||
sample_offset: SampleOffset, | ||
detector_bank_offset: DetectorBankOffset, | ||
) -> RawDataWithComponentUserOffsets[RunType]: | ||
"""Apply user configuration to raw data. | ||
Parameters | ||
---------- | ||
data: | ||
Raw data. | ||
sample_offset: | ||
Sample offset. | ||
detector_bank_offset: | ||
Detector bank offset. | ||
""" | ||
data = data.copy(deep=False) | ||
sample_pos = data.coords['sample_position'] | ||
data.coords['sample_position'] = sample_pos + sample_offset.to( | ||
unit=sample_pos.unit, copy=False | ||
) | ||
pos = data.coords['position'] | ||
data.coords['position'] = pos + detector_bank_offset.to(unit=pos.unit, copy=False) | ||
return RawDataWithComponentUserOffsets[RunType](data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters