99import scipp as sc
1010import scipp .constants
1111
12- from .types import CorrectedDetector , SampleRun
12+ from .types import (
13+ DetectorLtotal ,
14+ DetectorTwoTheta ,
15+ ElasticCoordTransformGraph ,
16+ EmptyDetector ,
17+ RunType ,
18+ SampleRun ,
19+ )
1320
1421
1522class OutputCalibrationData (Mapping [int , sc .Variable ]):
@@ -93,13 +100,34 @@ def to_cif_format(self) -> sc.DataArray:
93100 )
94101
95102
103+ def detector_two_theta (
104+ detector : EmptyDetector [RunType ],
105+ graph : ElasticCoordTransformGraph [RunType ],
106+ ) -> DetectorTwoTheta [RunType ]:
107+ """Compute the scattering angle (two-theta) for each detector pixel.
108+
109+ Parameters
110+ ----------
111+ detector:
112+ Data array with detector positions.
113+ graph:
114+ Coordinate transformation graph for elastic scattering.
115+ """
116+ return DetectorTwoTheta [RunType ](
117+ detector .transform_coords (
118+ "two_theta" , graph = graph , keep_intermediate = False
119+ ).coords ["two_theta" ]
120+ )
121+
122+
96123def assemble_output_calibration (
97- data : CorrectedDetector [SampleRun ],
124+ ltotal : DetectorLtotal [SampleRun ],
125+ two_theta : DetectorTwoTheta [SampleRun ],
98126) -> OutputCalibrationData :
99127 """Construct output calibration data from average pixel positions."""
100128 # Use nanmean because pixels without events have position=NaN.
101- average_l = sc .nanmean (data . coords [ "Ltotal" ] )
102- average_two_theta = sc .nanmean (data . coords [ " two_theta" ] )
129+ average_l = sc .nanmean (ltotal )
130+ average_two_theta = sc .nanmean (two_theta )
103131 difc = sc .to_unit (
104132 2
105133 * sc .constants .m_n
@@ -111,4 +139,4 @@ def assemble_output_calibration(
111139 return OutputCalibrationData ({1 : difc })
112140
113141
114- providers = (assemble_output_calibration , )
142+ providers = (detector_two_theta , assemble_output_calibration )
0 commit comments