6
6
from ..reflectometry .conversions import reflectometry_q
7
7
from ..reflectometry .types import (
8
8
BeamDivergenceLimits ,
9
+ CoordTransformationGraph ,
9
10
WavelengthBins ,
10
11
YIndexLimits ,
11
12
ZIndexLimits ,
12
13
)
13
14
from .geometry import Detector
14
- from .types import CoordTransformationGraph
15
15
16
16
17
- def theta (wavelength , divergence_angle , L2 , sample_rotation , detector_rotation ):
17
+ def theta (wavelength , pixel_divergence_angle , L2 , sample_rotation , detector_rotation ):
18
18
'''
19
19
Angle of reflection.
20
20
@@ -61,14 +61,15 @@ def theta(wavelength, divergence_angle, L2, sample_rotation, detector_rotation):
61
61
'''
62
62
c = sc .constants .g * sc .constants .m_n ** 2 / sc .constants .h ** 2
63
63
out = (c * L2 * wavelength ** 2 ).to (unit = 'dimensionless' ) + sc .sin (
64
- divergence_angle .to (unit = 'rad' , copy = False ) + detector_rotation .to (unit = 'rad' )
64
+ pixel_divergence_angle .to (unit = 'rad' , copy = False )
65
+ + detector_rotation .to (unit = 'rad' )
65
66
)
66
67
out = sc .asin (out , out = out )
67
68
out -= sample_rotation .to (unit = 'rad' )
68
69
return out
69
70
70
71
71
- def angle_of_divergence (theta , sample_rotation , angle_to_center_of_beam ):
72
+ def divergence_angle (theta , sample_rotation , angle_to_center_of_beam ):
72
73
"""
73
74
Difference between the incident angle and the center of the incident beam.
74
75
Useful for filtering parts of the beam that have too high divergence.
@@ -84,7 +85,7 @@ def angle_of_divergence(theta, sample_rotation, angle_to_center_of_beam):
84
85
85
86
86
87
def wavelength (
87
- event_time_offset , divergence_angle , L1 , L2 , chopper_phase , chopper_frequency
88
+ event_time_offset , pixel_divergence_angle , L1 , L2 , chopper_phase , chopper_frequency
88
89
):
89
90
"Converts event_time_offset to wavelength using the chopper settings."
90
91
out = event_time_offset .to (unit = "ns" , dtype = "float64" , copy = True )
@@ -108,37 +109,22 @@ def wavelength(
108
109
)
109
110
# Correction for path length through guides being different
110
111
# depending on incident angle.
111
- out -= (divergence_angle .to (unit = "rad" ) / (np .pi * sc .units .rad )) * tau
112
+ out -= (pixel_divergence_angle .to (unit = "rad" ) / (np .pi * sc .units .rad )) * tau
112
113
out *= (sc .constants .h / sc .constants .m_n ) / (L1 + L2 )
113
114
return out .to (unit = 'angstrom' , copy = False )
114
115
115
116
116
117
def coordinate_transformation_graph () -> CoordTransformationGraph :
117
118
return {
118
- "divergence_angle" : "pixel_divergence_angle" ,
119
119
"wavelength" : wavelength ,
120
120
"theta" : theta ,
121
- "angle_of_divergence " : angle_of_divergence ,
121
+ "divergence_angle " : divergence_angle ,
122
122
"Q" : reflectometry_q ,
123
123
"L1" : lambda chopper_distance : sc .abs (chopper_distance ),
124
124
"L2" : lambda distance_in_detector : distance_in_detector + Detector .distance ,
125
125
}
126
126
127
127
128
- def add_coords (
129
- da : sc .DataArray ,
130
- graph : dict ,
131
- ) -> sc .DataArray :
132
- "Adds scattering coordinates to the raw detector data."
133
- return da .transform_coords (
134
- ("wavelength" , "theta" , "angle_of_divergence" , "Q" , "L1" , "L2" ),
135
- graph ,
136
- rename_dims = False ,
137
- keep_intermediate = False ,
138
- keep_aliases = False ,
139
- )
140
-
141
-
142
128
def _not_between (v , a , b ):
143
129
return (v < a ) | (v > b )
144
130
@@ -161,9 +147,9 @@ def add_masks(
161
147
)
162
148
da = da .bins .assign_masks (
163
149
divergence_too_large = _not_between (
164
- da .bins .coords ["angle_of_divergence " ],
165
- bdlim [0 ].to (unit = da .bins .coords ["angle_of_divergence " ].bins .unit ),
166
- bdlim [1 ].to (unit = da .bins .coords ["angle_of_divergence " ].bins .unit ),
150
+ da .bins .coords ["divergence_angle " ],
151
+ bdlim [0 ].to (unit = da .bins .coords ["divergence_angle " ].bins .unit ),
152
+ bdlim [1 ].to (unit = da .bins .coords ["divergence_angle " ].bins .unit ),
167
153
),
168
154
wavelength = _not_between (
169
155
da .bins .coords ['wavelength' ],
0 commit comments