Skip to content

Commit e469f80

Browse files
committed
use one workflow name and an input argument
1 parent b236075 commit e469f80

1 file changed

Lines changed: 45 additions & 40 deletions

File tree

  • packages/essreduce/src/ess/reduce/unwrap

packages/essreduce/src/ess/reduce/unwrap/lut.py

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -465,26 +465,6 @@ def simulate_chopper_cascade_using_tof(
465465
return SimulationResults(readings=sim_readings, choppers=choppers)
466466

467467

468-
def LookupTableWorkflow():
469-
"""
470-
Create a workflow for computing a wavelength lookup table from a
471-
simulation of neutrons propagating through a chopper cascade.
472-
"""
473-
wf = sl.Pipeline(
474-
(make_wavelength_lookup_table, simulate_chopper_cascade_using_tof),
475-
params={
476-
PulsePeriod: 1.0 / sc.scalar(14.0, unit="Hz"),
477-
PulseStride: 1,
478-
DistanceResolution: sc.scalar(0.1, unit="m"),
479-
TimeResolution: sc.scalar(250.0, unit='us'),
480-
NumberOfSimulatedNeutrons: 1_000_000,
481-
SimulationSeed: None,
482-
SimulationFacility: 'ess',
483-
},
484-
)
485-
return wf
486-
487-
488468
def _polygon_intersections(polygons: list[np.ndarray], x: np.ndarray) -> np.ndarray:
489469
# Decompose the polygons into two 1D lines: the upper and lower bounds
490470
bounds = []
@@ -764,25 +744,50 @@ def make_wavelength_lut_from_polygons(
764744
)
765745

766746

767-
def FastLookupTableWorkflow():
747+
def LookupTableWorkflow(use_simulation: bool = True):
768748
"""
769-
Create a workflow for computing a wavelength lookup table from computing an
770-
acceptance diagram for a pulse propagating through a chopper cascade.
749+
Create a workflow for computing a wavelength lookup table.
750+
If ``use_simulation`` is True, the workflow will compute the lookup table from a
751+
simulation of neutrons propagating through a chopper cascade using the ``tof``
752+
package.
753+
If ``use_simulation`` is False, the workflow will compute the lookup table from
754+
the acceptance diagram polygons generated by the ``chopper_cascade`` module.
755+
756+
Parameters
757+
----------
758+
use_simulation:
759+
Whether to compute the lookup table from a simulation of neutrons propagating
760+
through a chopper cascade using the ``tof`` package, or from the acceptance
761+
diagram polygons generated by the ``chopper_cascade`` module.
771762
"""
772-
wf = sl.Pipeline(
773-
(make_wavelength_lut_from_polygons, compute_frame_sequence),
774-
params={
775-
PulsePeriod: 1.0 / sc.scalar(14.0, unit="Hz"),
776-
PulseStride: 1,
777-
DistanceResolution: sc.scalar(0.1, unit="m"),
778-
TimeResolution: sc.scalar(250.0, unit='us'),
779-
SourceBounds: SourceBounds(
780-
time=(sc.scalar(0.0, unit='ms'), sc.scalar(5.0, unit='ms')),
781-
wavelength=(
782-
sc.scalar(0.0, unit='angstrom'),
783-
sc.scalar(15.0, unit='angstrom'),
784-
),
785-
),
786-
},
787-
)
788-
return wf
763+
default_params = {
764+
PulsePeriod: 1.0 / sc.scalar(14.0, unit="Hz"),
765+
PulseStride: 1,
766+
DistanceResolution: sc.scalar(0.1, unit="m"),
767+
TimeResolution: sc.scalar(250.0, unit='us'),
768+
}
769+
770+
if use_simulation:
771+
providers = (make_wavelength_lookup_table, simulate_chopper_cascade_using_tof)
772+
default_params.update(
773+
{
774+
NumberOfSimulatedNeutrons: 1_000_000,
775+
SimulationSeed: None,
776+
SimulationFacility: 'ess',
777+
}
778+
)
779+
else:
780+
providers = (make_wavelength_lut_from_polygons, compute_frame_sequence)
781+
default_params.update(
782+
{
783+
SourceBounds: SourceBounds(
784+
time=(sc.scalar(0.0, unit='ms'), sc.scalar(5.0, unit='ms')),
785+
wavelength=(
786+
sc.scalar(0.0, unit='angstrom'),
787+
sc.scalar(15.0, unit='angstrom'),
788+
),
789+
)
790+
}
791+
)
792+
793+
return sl.Pipeline(providers, params=default_params)

0 commit comments

Comments
 (0)