Skip to content

Commit d0bafe0

Browse files
committed
feat: add gravity toggle
1 parent 0a03844 commit d0bafe0

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

src/ess/amor/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
AngularResolution,
3131
ChopperFrequency,
3232
ChopperPhase,
33+
GravityToggle,
3334
QThetaFigure,
3435
ReflectivityDiagnosticsView,
3536
SampleSizeResolution,
@@ -76,6 +77,7 @@ def default_parameters() -> dict:
7677
sc.scalar(-0.75, unit='deg'),
7778
sc.scalar(0.75, unit='deg'),
7879
),
80+
GravityToggle: True,
7981
}
8082

8183

src/ess/amor/conversions.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
ZIndexLimits,
1212
)
1313
from .geometry import Detector
14-
from .types import CoordTransformationGraph
14+
from .types import CoordTransformationGraph, GravityToggle
1515

1616

1717
def theta(wavelength, divergence_angle, L2, sample_rotation, detector_rotation):
@@ -68,6 +68,24 @@ def theta(wavelength, divergence_angle, L2, sample_rotation, detector_rotation):
6868
return out
6969

7070

71+
def theta_no_gravity(wavelength, divergence_angle, sample_rotation, detector_rotation):
72+
'''
73+
Angle of reflection.
74+
75+
Computes the angle between the scattering direction of
76+
the neutron and the sample surface while disregarding the
77+
effect of gravity.
78+
'''
79+
theta = (
80+
divergence_angle.to(unit='rad', copy=False)
81+
+ detector_rotation.to(unit='rad')
82+
- sample_rotation.to(unit='rad')
83+
)
84+
if wavelength.bins:
85+
return sc.bins_like(wavelength, theta)
86+
return theta
87+
88+
7189
def angle_of_divergence(theta, sample_rotation, angle_to_center_of_beam):
7290
"""
7391
Difference between the incident angle and the center of the incident beam.
@@ -113,11 +131,11 @@ def wavelength(
113131
return out.to(unit='angstrom', copy=False)
114132

115133

116-
def coordinate_transformation_graph() -> CoordTransformationGraph:
134+
def coordinate_transformation_graph(gravity: GravityToggle) -> CoordTransformationGraph:
117135
return {
118136
"divergence_angle": "pixel_divergence_angle",
119137
"wavelength": wavelength,
120-
"theta": theta,
138+
"theta": theta if gravity else theta_no_gravity,
121139
"angle_of_divergence": angle_of_divergence,
122140
"Q": reflectometry_q,
123141
"L1": lambda chopper_distance: sc.abs(chopper_distance),

src/ess/amor/types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,5 @@ class AngleCenterOfIncomingToHorizon(
4747
WavelengthZIndexFigure = NewType("WavelengthZIndexFigure", Any)
4848
QThetaFigure = NewType("QThetaFigure", Any)
4949
ReflectivityDiagnosticsView = NewType("ReflectivityDiagnosticsView", Any)
50+
51+
GravityToggle = NewType("GravityToggle", bool)

tests/amor/pipeline_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ def test_has_expected_coordinates(amor_pipeline: sciline.Pipeline):
7171
assert "Q_resolution" in reflectivity_over_q.coords
7272

7373

74+
@pytest.mark.filterwarnings("ignore:Failed to convert .* into a transformation")
75+
@pytest.mark.filterwarnings("ignore:Invalid transformation, missing attribute")
76+
def test_pipeline_no_gravity_correction(amor_pipeline: sciline.Pipeline):
77+
# The sample rotation value in the file is slightly off, so we set it manually
78+
amor_pipeline[SampleRotation[SampleRun]] = sc.scalar(0.85, unit="deg")
79+
amor_pipeline[Filename[SampleRun]] = amor.data.amor_sample_run(608)
80+
amor_pipeline[amor.types.GravityToggle] = False
81+
reflectivity_over_q = amor_pipeline.compute(ReflectivityOverQ)
82+
assert "Q" in reflectivity_over_q.coords
83+
assert "Q_resolution" in reflectivity_over_q.coords
84+
85+
7486
@pytest.mark.filterwarnings("ignore:Failed to convert .* into a transformation")
7587
@pytest.mark.filterwarnings("ignore:Invalid transformation, missing attribute")
7688
def test_orso_pipeline(amor_pipeline: sciline.Pipeline):

0 commit comments

Comments
 (0)