Skip to content

Commit af5d136

Browse files
committed
Make chopper_tof_correction part of pipeline
1 parent fcad9a1 commit af5d136

File tree

3 files changed

+19
-23
lines changed

3 files changed

+19
-23
lines changed

src/essreflectometry/amor/load.py

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
import scippnexus as snx
88

99
from ..logging import get_logger
10-
from ..types import Filename, RawData, RawEvents, Run
10+
from ..types import Filename, RawData, RawEvents, Run, ChopperCorrectedTofEvents
1111
from .data import get_path
1212
from .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

5458
def _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)

src/essreflectometry/conversions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
HistogrammedQData,
1414
QBins,
1515
QData,
16-
RawEvents,
1716
Run,
1817
SpecularReflectionCoordTransformGraph,
1918
ThetaData,
2019
WavelengthData,
2120
WavelengthEdges,
21+
ChopperCorrectedTofEvents,
2222
)
2323

2424

@@ -119,7 +119,7 @@ def specular_reflection() -> SpecularReflectionCoordTransformGraph:
119119

120120

121121
def tof_to_wavelength(
122-
data_array: RawEvents[Run],
122+
data_array: ChopperCorrectedTofEvents[Run],
123123
graph: SpecularReflectionCoordTransformGraph,
124124
wavelength_edges: Optional[WavelengthEdges],
125125
) -> WavelengthData[Run]:

src/essreflectometry/types.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ class RawEvents(sciline.Scope[Run, sc.DataArray], sc.DataArray):
1717
binned by `detector_number` (pixel of the detector frame)."""
1818

1919

20+
class ChopperCorrectedTofEvents(sciline.Scope[Run, sc.DataArray], sc.DataArray):
21+
"""Event time data after correcting tof for choppers."""
22+
23+
2024
class WavelengthData(sciline.Scope[Run, sc.DataArray], sc.DataArray):
2125
"""Event data with wavelengths computed for every event,
2226
binned by `detector_number` (pixel of the detector frame)"""

0 commit comments

Comments
 (0)