Skip to content

Commit d2e5e1f

Browse files
Merge pull request #250 from scipp/fix/output-calibration-false-dependency
Fix false dependency of OutputCalibrationData on CorrectedDetector
2 parents ceec828 + e750b1d commit d2e5e1f

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

src/ess/powder/calibration.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@
99
import scipp as sc
1010
import 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

1522
class 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+
96123
def 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)

src/ess/powder/types.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
DetectorBankSizes = reduce_t.DetectorBankSizes
3838

39+
DetectorLtotal = tof_t.DetectorLtotal
3940
TofDetector = tof_t.TofDetector
4041
TofMonitor = tof_t.TofMonitor
4142
PulseStrideOffset = tof_t.PulseStrideOffset
@@ -104,6 +105,10 @@ class WavelengthDetector(sciline.Scope[RunType, sc.DataArray], sc.DataArray):
104105
"""Histogrammed intensity vs d-spacing."""
105106

106107

108+
class DetectorTwoTheta(sciline.Scope[RunType, sc.Variable], sc.Variable):
109+
"""Scattering angle (two-theta) for each detector pixel."""
110+
111+
107112
class ElasticCoordTransformGraph(sciline.Scope[RunType, dict], dict):
108113
"""Graph for transforming coordinates in elastic scattering."""
109114

0 commit comments

Comments
 (0)