Skip to content

Commit 861eb73

Browse files
authored
Merge pull request #169 from scipp/tofworkflow-bug
Change TofWorkflow API to not mirror the Pipeline api
2 parents 23cb90b + fa405ba commit 861eb73

File tree

2 files changed

+24
-36
lines changed

2 files changed

+24
-36
lines changed

src/ess/reduce/time_of_flight/__init__.py

Lines changed: 1 addition & 6 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 .toa_to_tof import (
10-
default_parameters,
11-
resample_tof_data,
12-
providers,
13-
TofWorkflow,
14-
)
9+
from .toa_to_tof import default_parameters, resample_tof_data, providers, TofWorkflow
1510
from .simulation import simulate_beamline
1611
from .types import (
1712
DistanceResolution,

src/ess/reduce/time_of_flight/toa_to_tof.py

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
event_time_offset coordinates to data with a time-of-flight coordinate.
88
"""
99

10-
from __future__ import annotations
11-
1210
from collections.abc import Callable
13-
from typing import Any
1411

1512
import numpy as np
1613
import scipp as sc
@@ -461,8 +458,8 @@ def providers() -> tuple[Callable]:
461458

462459
class TofWorkflow:
463460
"""
464-
Helper class to build a time-of-flight workflow and cache the expensive part of
465-
the computation: running the simulation and building the lookup table.
461+
Helper class to build a time-of-flight workflow and cache the expensive part of the
462+
computation: running the simulation and building the lookup table.
466463
467464
Parameters
468465
----------
@@ -472,16 +469,17 @@ class TofWorkflow:
472469
wavelength, and weight.
473470
ltotal_range:
474471
Range of total flight path lengths from the source to the detector.
475-
This is used to create the lookup table to compute the neutron time-of-flight.
472+
This is used to create the lookup table to compute the neutron
473+
time-of-flight.
476474
Note that the resulting table will extend slightly beyond this range, as the
477475
supplied range is not necessarily a multiple of the distance resolution.
478476
pulse_stride:
479477
Stride of used pulses. Usually 1, but may be a small integer when
480478
pulse-skipping.
481479
pulse_stride_offset:
482-
Integer offset of the first pulse in the stride (typically zero unless we are
483-
using pulse-skipping and the events do not begin with the first pulse in the
484-
stride).
480+
Integer offset of the first pulse in the stride (typically zero unless we
481+
are using pulse-skipping and the events do not begin with the first pulse in
482+
the stride).
485483
distance_resolution:
486484
Resolution of the distance axis in the lookup table.
487485
Should be a single scalar value with a unit of length.
@@ -490,8 +488,8 @@ class TofWorkflow:
490488
Resolution of the time of arrival axis in the lookup table.
491489
Can be an integer (number of bins) or a sc.Variable (bin width).
492490
error_threshold:
493-
Threshold for the variance of the projected time-of-flight above which regions
494-
are masked.
491+
Threshold for the variance of the projected time-of-flight above which
492+
regions are masked.
495493
"""
496494

497495
def __init__(
@@ -526,23 +524,18 @@ def __init__(
526524
error_threshold or params[LookupTableRelativeErrorThreshold]
527525
)
528526

529-
def __getitem__(self, key):
530-
return self.pipeline[key]
531-
532-
def __setitem__(self, key, value):
533-
self.pipeline[key] = value
534-
535-
def persist(self) -> None:
536-
for t in (SimulationResults, MaskedTimeOfFlightLookupTable, FastestNeutron):
527+
def cache_results(
528+
self,
529+
results=(SimulationResults, MaskedTimeOfFlightLookupTable, FastestNeutron),
530+
) -> None:
531+
"""
532+
Cache a list of (usually expensive to compute) intermediate results of the
533+
time-of-flight workflow.
534+
535+
Parameters
536+
----------
537+
results:
538+
List of results to cache.
539+
"""
540+
for t in results:
537541
self.pipeline[t] = self.pipeline.compute(t)
538-
539-
def compute(self, *args, **kwargs) -> Any:
540-
return self.pipeline.compute(*args, **kwargs)
541-
542-
def visualize(self, *args, **kwargs) -> Any:
543-
return self.pipeline.visualize(*args, **kwargs)
544-
545-
def copy(self) -> TofWorkflow:
546-
out = self.__class__(choppers=None, facility=None, ltotal_range=None)
547-
out.pipeline = self.pipeline.copy()
548-
return out

0 commit comments

Comments
 (0)