77import scippnexus as snx
88
99from ..logging import get_logger
10- from ..types import Filename , RawData , RawEvents , Run
10+ from ..types import ChopperCorrectedTofEvents , Filename , RawData , RawEvents , Run
1111from .data import get_path
1212from .types import BeamlineParams
1313
1414
15- def _tof_correction (data : sc . DataArray , dim : str = 'tof' ) -> sc . DataArray :
15+ def chopper_tof_correction (data : RawEvents [ Run ] ) -> ChopperCorrectedTofEvents [ Run ] :
1616 """
1717 A correction for the presence of the chopper with respect to the "true" ToF.
1818 Also fold the two pulses.
@@ -22,17 +22,13 @@ def _tof_correction(data: sc.DataArray, dim: str = 'tof') -> sc.DataArray:
2222 ----------
2323 data:
2424 Input data array to correct.
25- dim:
26- Name of the time of flight dimension.
2725
2826 Returns
2927 -------
3028 :
3129 ToF corrected data array.
3230 """
33- # TODO
34- # if 'orso' in data.attrs:
35- # data.attrs['orso'].value.reduction.corrections += ['chopper ToF correction']
31+ dim = 'tof'
3632 tof_unit = data .bins .coords [dim ].bins .unit
3733 tau = sc .to_unit (
3834 1 / (2 * data .coords ['source_chopper_2' ].value ['frequency' ].data ),
@@ -48,7 +44,15 @@ def _tof_correction(data: sc.DataArray, dim: str = 'tof') -> sc.DataArray:
4844 # Apply the offset on both bins
4945 data .bins .coords [dim ] += offset
5046 # Rebin to exclude second (empty) pulse range
51- return data .bin ({dim : sc .concat ([0.0 * sc .units .us , tau ], dim )})
47+ data = data .bin ({dim : sc .concat ([0.0 * sc .units .us , tau ], dim )})
48+
49+ # Ad-hoc correction described in
50+ # https://scipp.github.io/ess/instruments/amor/amor_reduction.html
51+ data .coords ['position' ].fields .y += data .coords ['position' ].fields .z * sc .tan (
52+ 2.0 * data .coords ['sample_rotation' ] - (0.955 * sc .units .deg )
53+ )
54+
55+ return ChopperCorrectedTofEvents [Run ](data )
5256
5357
5458def _assemble_event_data (dg : sc .DataGroup ) -> sc .DataArray :
@@ -141,19 +145,7 @@ def extract_events(
141145 for key , value in beamline .items ():
142146 data .coords [key ] = value
143147
144- # if orso is not None:
145- # populate_orso(orso=orso, data=full_data, filename=filename)
146- # data.attrs['orso'] = sc.scalar(orso)
147-
148- # Perform tof correction and fold two pulses
149- data = _tof_correction (data )
150-
151- # Ad-hoc correction described in
152- # https://scipp.github.io/ess/instruments/amor/amor_reduction.html
153- data .coords ['position' ].fields .y += data .coords ['position' ].fields .z * sc .tan (
154- 2.0 * data .coords ['sample_rotation' ] - (0.955 * sc .units .deg )
155- )
156148 return RawEvents [Run ](data )
157149
158150
159- providers = (extract_events , load_raw_nexus )
151+ providers = (extract_events , load_raw_nexus , chopper_tof_correction )
0 commit comments