Skip to content

Commit f9e669e

Browse files
Merge pull request #246 from scipp/remove-workflow-resample-step
Remove separate resampling step from TofWorkflow
2 parents 70f9261 + 0f26db8 commit f9e669e

File tree

5 files changed

+9
-81
lines changed

5 files changed

+9
-81
lines changed

src/ess/reduce/time_of_flight/__init__.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@
66
neutron time-of-arrival at the detectors.
77
"""
88

9-
from .eto_to_tof import (
10-
default_parameters,
11-
providers,
12-
resample_detector_time_of_flight_data,
13-
resample_monitor_time_of_flight_data,
14-
)
9+
from .eto_to_tof import default_parameters, providers
1510
from .simulation import simulate_beamline
1611
from .types import (
1712
DetectorLtotal,
@@ -24,8 +19,6 @@
2419
PulsePeriod,
2520
PulseStride,
2621
PulseStrideOffset,
27-
ResampledDetectorTofData,
28-
ResampledMonitorTofData,
2922
SimulationResults,
3023
TimeOfFlightLookupTable,
3124
TimeOfFlightLookupTableFilename,
@@ -36,25 +29,23 @@
3629
__all__ = [
3730
"DetectorLtotal",
3831
"DetectorTofData",
32+
"DetectorTofData",
3933
"DistanceResolution",
4034
"GenericTofWorkflow",
4135
"LookupTableRelativeErrorThreshold",
4236
"LtotalRange",
4337
"MonitorLtotal",
4438
"MonitorTofData",
39+
"MonitorTofData",
4540
"PulsePeriod",
4641
"PulseStride",
4742
"PulseStrideOffset",
48-
"ResampledDetectorTofData",
49-
"ResampledMonitorTofData",
5043
"SimulationResults",
5144
"TimeOfFlightLookupTable",
5245
"TimeOfFlightLookupTableFilename",
5346
"TimeResolution",
5447
"TofLutProvider",
5548
"default_parameters",
5649
"providers",
57-
"resample_detector_time_of_flight_data",
58-
"resample_monitor_time_of_flight_data",
5950
"simulate_beamline",
6051
]

src/ess/reduce/time_of_flight/eto_to_tof.py

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
PulsePeriod,
4040
PulseStride,
4141
PulseStrideOffset,
42-
ResampledDetectorTofData,
43-
ResampledMonitorTofData,
4442
SimulationResults,
4543
TimeOfFlightLookupTable,
4644
TimeResolution,
@@ -586,7 +584,8 @@ def _compute_tof_data(
586584
pulse_stride_offset: int,
587585
) -> sc.DataArray:
588586
if da.bins is None:
589-
return _time_of_flight_data_histogram(da=da, lookup=lookup, ltotal=ltotal)
587+
data = _time_of_flight_data_histogram(da=da, lookup=lookup, ltotal=ltotal)
588+
return rebin_strictly_increasing(data, dim='tof')
590589
else:
591590
return _time_of_flight_data_events(
592591
da=da,
@@ -664,26 +663,6 @@ def monitor_time_of_flight_data(
664663
)
665664

666665

667-
def resample_detector_time_of_flight_data(
668-
da: DetectorTofData[RunType],
669-
) -> ResampledDetectorTofData[RunType]:
670-
"""
671-
Resample the detector time-of-flight data to ensure that the bin edges are sorted.
672-
"""
673-
return ResampledDetectorTofData[RunType](rebin_strictly_increasing(da, dim='tof'))
674-
675-
676-
def resample_monitor_time_of_flight_data(
677-
da: MonitorTofData[RunType, MonitorType],
678-
) -> ResampledMonitorTofData[RunType, MonitorType]:
679-
"""
680-
Resample the monitor time-of-flight data to ensure that the bin edges are sorted.
681-
"""
682-
return ResampledMonitorTofData[RunType, MonitorType](
683-
rebin_strictly_increasing(da, dim='tof')
684-
)
685-
686-
687666
def default_parameters() -> dict:
688667
"""
689668
Default parameters of the time-of-flight workflow.

src/ess/reduce/time_of_flight/types.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -130,43 +130,3 @@ class DetectorTofData(sl.Scope[RunType, sc.DataArray], sc.DataArray):
130130

131131
class MonitorTofData(sl.Scope[RunType, MonitorType, sc.DataArray], sc.DataArray):
132132
"""Monitor data with time-of-flight coordinate."""
133-
134-
135-
class ResampledDetectorTofData(sl.Scope[RunType, sc.DataArray], sc.DataArray):
136-
"""
137-
Histogrammed detector data with time-of-flight coordinate, that has been resampled.
138-
139-
Histogrammed data that has been converted to `tof` will typically have
140-
unsorted bin edges (due to either wrapping of `time_of_flight` or wavelength
141-
overlap between subframes).
142-
We thus resample the data to ensure that the bin edges are sorted.
143-
It makes use of the ``to_events`` helper which generates a number of events in each
144-
bin with a uniform distribution. The new events are then histogrammed using a set of
145-
sorted bin edges to yield a new histogram with sorted bin edges.
146-
147-
WARNING:
148-
This function is highly experimental, has limitations and should be used with
149-
caution. It is a workaround to the issue that rebinning data with unsorted bin
150-
edges is not supported in scipp.
151-
"""
152-
153-
154-
class ResampledMonitorTofData(
155-
sl.Scope[RunType, MonitorType, sc.DataArray], sc.DataArray
156-
):
157-
"""
158-
Histogrammed monitor data with time-of-flight coordinate, that has been resampled.
159-
160-
Histogrammed data that has been converted to `tof` will typically have
161-
unsorted bin edges (due to either wrapping of `time_of_flight` or wavelength
162-
overlap between subframes).
163-
We thus resample the data to ensure that the bin edges are sorted.
164-
It makes use of the ``to_events`` helper which generates a number of events in each
165-
bin with a uniform distribution. The new events are then histogrammed using a set of
166-
sorted bin edges to yield a new histogram with sorted bin edges.
167-
168-
WARNING:
169-
This function is highly experimental, has limitations and should be used with
170-
caution. It is a workaround to the issue that rebinning data with unsorted bin
171-
edges is not supported in scipp.
172-
"""

src/ess/reduce/time_of_flight/workflow.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def GenericTofWorkflow(
3434
"""
3535
Generic workflow for computing the neutron time-of-flight for detector and monitor
3636
data.
37+
3738
This workflow builds on the ``GenericNeXusWorkflow`` and computes time-of-flight
3839
from a lookup table that is created from the chopper settings, detector Ltotal and
3940
the neutron time-of-arrival.

tests/time_of_flight/unwrap_test.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,7 @@ def _make_workflow_histogram_mode(
8888
).rename(event_time_offset=dim)
8989

9090
pl = sl.Pipeline(
91-
(
92-
*time_of_flight.providers(),
93-
time_of_flight.resample_detector_time_of_flight_data,
94-
),
91+
time_of_flight.providers(),
9592
params=time_of_flight.default_parameters(),
9693
constraints={RunType: [SampleRun], MonitorType: []},
9794
)
@@ -203,7 +200,7 @@ def test_standard_unwrap_histogram_mode(dist, dim, simulation_psc_choppers) -> N
203200
pulse_stride=1,
204201
)
205202

206-
tofs = pl.compute(time_of_flight.ResampledDetectorTofData[SampleRun])
203+
tofs = pl.compute(time_of_flight.DetectorTofData[SampleRun])
207204

208205
_validate_result_histogram_mode(
209206
tofs=tofs, ref=ref, percentile=96, diff_threshold=0.4, rtol=0.05
@@ -432,7 +429,7 @@ def test_pulse_skipping_unwrap_histogram_mode(simulation_pulse_skipping) -> None
432429
pulse_stride=2,
433430
)
434431

435-
tofs = pl.compute(time_of_flight.ResampledDetectorTofData[SampleRun])
432+
tofs = pl.compute(time_of_flight.DetectorTofData[SampleRun])
436433

437434
_validate_result_histogram_mode(
438435
tofs=tofs, ref=ref, percentile=96, diff_threshold=0.4, rtol=0.05

0 commit comments

Comments
 (0)