Skip to content

Commit 7769223

Browse files
committed
feat: add sample rotation
1 parent f0a93b2 commit 7769223

File tree

7 files changed

+32
-2
lines changed

7 files changed

+32
-2
lines changed

src/ess/amor/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
NeXusDetectorName,
1515
RunType,
1616
SamplePosition,
17+
SampleRotationOffset,
1718
)
1819
from . import (
1920
conversions,
@@ -71,6 +72,7 @@ def default_parameters() -> dict:
7172
sc.scalar(0.75, unit='deg'),
7273
),
7374
GravityToggle: True,
75+
SampleRotationOffset[RunType]: sc.scalar(0.0, unit='deg'),
7476
}
7577

7678

src/ess/amor/load.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
NeXusDetectorName,
1212
ProtonCurrent,
1313
RawDetectorData,
14+
RawSampleRotation,
1415
RunType,
1516
SampleRotation,
1617
SampleSize,
@@ -100,7 +101,7 @@ def load_amor_ch_frequency(ch: RawChopper[RunType]) -> ChopperFrequency[RunType]
100101
raise ValueError("No unit was found for the chopper frequency")
101102

102103

103-
def load_amor_sample_rotation(fp: Filename[RunType]) -> SampleRotation[RunType]:
104+
def load_amor_sample_rotation(fp: Filename[RunType]) -> RawSampleRotation[RunType]:
104105
(mu,) = load_nx(fp, "NXentry/NXinstrument/master_parameters/mu")
105106
# Jochens Amor code reads the first value of this log
106107
# see https://github.com/jochenstahn/amor/blob/140e3192ddb7e7f28acee87e2acaee65ce1332aa/libeos/file_reader.py#L272 # noqa: E501

src/ess/estia/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
NeXusDetectorName,
1515
RunType,
1616
SamplePosition,
17+
SampleRotationOffset,
1718
)
1819
from . import conversions, load, maskings, normalization, orso, resolution, workflow
1920
from .types import (
@@ -57,6 +58,7 @@ def default_parameters() -> dict:
5758
sc.scalar(-0.75, unit='deg'),
5859
sc.scalar(0.75, unit='deg'),
5960
),
61+
SampleRotationOffset[RunType]: sc.scalar(0.0, unit='deg'),
6062
}
6163

6264

src/ess/estia/load.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
Filename,
77
RawDetectorData,
88
RunType,
9+
SampleRotationOffset,
910
)
1011
from .mcstas import parse_events_ascii, parse_events_h5
1112

1213

1314
def load_mcstas_events(
1415
filename: Filename[RunType],
16+
sample_rotation_offset: SampleRotationOffset[RunType],
1517
) -> RawDetectorData[RunType]:
1618
"""
1719
Load event data from a McStas run and reshape it
@@ -31,6 +33,9 @@ def load_mcstas_events(
3133
da.coords['detector_rotation'] = 2 * da.coords['sample_rotation'] + sc.scalar(
3234
1.65, unit='deg'
3335
)
36+
da.coords['sample_rotation'] += sample_rotation_offset.to(
37+
unit=da.coords['sample_rotation'].unit
38+
)
3439

3540
xbins = sc.linspace('x', -0.25, 0.25, 14 * 32 + 1)
3641
ybins = sc.linspace('y', -0.25, 0.25, 65)

src/ess/reflectometry/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
__version__ = "0.0.0"
1111

1212

13-
from . import conversions, figures, normalization, orso
13+
from . import conversions, corrections, figures, normalization, orso
1414
from .load import load_reference, save_reference
1515

1616
providers = (
17+
*corrections.providers,
1718
*conversions.providers,
1819
*orso.providers,
1920
*normalization.providers,

src/ess/reflectometry/corrections.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import scipp as sc
33

44
from .tools import fwhm_to_std
5+
from .types import RawSampleRotation, RunType, SampleRotation, SampleRotationOffset
56

67

78
def footprint_on_sample(
@@ -45,3 +46,12 @@ def correct_by_footprint(da: sc.DataArray) -> sc.DataArray:
4546
def correct_by_proton_current(da: sc.DataArray) -> sc.DataArray:
4647
"Corrects the data by the proton current during the time of data collection"
4748
return da / da.bins.coords['proton_current']
49+
50+
51+
def correct_sample_rotation(
52+
mu: RawSampleRotation[RunType], mu_offset: SampleRotationOffset[RunType]
53+
) -> SampleRotation[RunType]:
54+
return mu + mu_offset.to(unit=mu.unit)
55+
56+
57+
providers = (correct_sample_rotation,)

src/ess/reflectometry/types.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,19 @@ class Filename(sciline.Scope[RunType, str], str):
7979
"""Filename of an event data nexus file."""
8080

8181

82+
class RawSampleRotation(sciline.Scope[RunType, sc.Variable], sc.Variable):
83+
"""The rotation of the sample registered in the NeXus file."""
84+
85+
8286
class SampleRotation(sciline.Scope[RunType, sc.Variable], sc.Variable):
8387
"""The rotation of the sample relative to the center of the incoming beam."""
8488

8589

90+
class SampleRotationOffset(sciline.Scope[RunType, sc.Variable], sc.Variable):
91+
"""The difference between the true slope of the sample surface
92+
and the sample rotation value in the file."""
93+
94+
8695
class DetectorRotation(sciline.Scope[RunType, sc.Variable], sc.Variable):
8796
"""The rotation of the detector relative to the horizon"""
8897

0 commit comments

Comments
 (0)