Create a time-of-flight lookup table for LoKI#
[1]:
import scipp as sc
from ess.reduce import time_of_flight
from ess.reduce.nexus.types import AnyRun
Setting up the workflow#
Note here that for now, we have no chopper in the beamline. This should be added in the next iteration.
[2]:
source_position = sc.vector([0, 0, 0], unit='m')
wf = time_of_flight.TofLookupTableWorkflow()
wf[time_of_flight.DiskChoppers[AnyRun]] = {}
wf[time_of_flight.SourcePosition] = source_position
wf[time_of_flight.NumberOfSimulatedNeutrons] = 200_000 # Increase this number for more reliable results
wf[time_of_flight.SimulationSeed] = 1234
wf[time_of_flight.PulseStride] = 1
wf[time_of_flight.LtotalRange] = sc.scalar(9.0, unit="m"), sc.scalar(35.0, unit="m")
wf[time_of_flight.DistanceResolution] = sc.scalar(0.1, unit="m")
wf[time_of_flight.TimeResolution] = sc.scalar(250.0, unit='us')
Compute the table#
[3]:
table = wf.compute(time_of_flight.TofLookupTable)
table
Downloading file 'ess/ess.h5' from 'https://github.com/scipp/tof-sources/raw/refs/heads/main/1/ess/ess.h5' to '/home/runner/.cache/tof'.
[3]:
TofLookupTable(array=<scipp.DataArray>
Dimensions: Sizes[distance:264, event_time_offset:287, ]
Coordinates:
* distance float64 [m] (distance) [8.8, 8.9, ..., 35, 35.1]
* event_time_offset float64 [µs] (event_time_offset) [0, 249.75, ..., 71178.8, 71428.6]
Data:
float64 [µs] (distance, event_time_offset) [-nan, -nan, ..., 71633.6, 73716] [-nan, -nan, ..., 1.68181e+08, 2.70255e+08]
, pulse_period=<scipp.Variable> () float64 [µs] 71428.6, pulse_stride=1, distance_resolution=<scipp.Variable> () float64 [m] 0.1, time_resolution=<scipp.Variable> () float64 [µs] 249.75, choppers=None)
[4]:
table.plot()
[4]:
Save to file#
[5]:
# Write to file
table.save_hdf5('loki-tof-lookup-table-no-choppers.h5')
Writing type '<class 'NoneType'>' to HDF5 not implemented, skipping.