7
7
event_time_offset coordinates to data with a time-of-flight coordinate.
8
8
"""
9
9
10
- from __future__ import annotations
11
-
12
10
from collections .abc import Callable
13
- from typing import Any
14
11
15
12
import numpy as np
16
13
import scipp as sc
@@ -461,8 +458,8 @@ def providers() -> tuple[Callable]:
461
458
462
459
class TofWorkflow :
463
460
"""
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.
466
463
467
464
Parameters
468
465
----------
@@ -472,16 +469,17 @@ class TofWorkflow:
472
469
wavelength, and weight.
473
470
ltotal_range:
474
471
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.
476
474
Note that the resulting table will extend slightly beyond this range, as the
477
475
supplied range is not necessarily a multiple of the distance resolution.
478
476
pulse_stride:
479
477
Stride of used pulses. Usually 1, but may be a small integer when
480
478
pulse-skipping.
481
479
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).
485
483
distance_resolution:
486
484
Resolution of the distance axis in the lookup table.
487
485
Should be a single scalar value with a unit of length.
@@ -490,8 +488,8 @@ class TofWorkflow:
490
488
Resolution of the time of arrival axis in the lookup table.
491
489
Can be an integer (number of bins) or a sc.Variable (bin width).
492
490
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.
495
493
"""
496
494
497
495
def __init__ (
@@ -526,23 +524,18 @@ def __init__(
526
524
error_threshold or params [LookupTableRelativeErrorThreshold ]
527
525
)
528
526
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 :
537
541
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