Create a TOF lookup table for ESTIA#

This notebook recreates the TOF lookup table that is used to compute time-of-flight from time-of-arrival for the ESTIA instrument.

To reproduce the lookup table you will need to provide some instrument parameters like pulse stride and chopper position.

[1]:
#%pip install tof
[2]:
#%matplotlib ipympl
import scipp as sc
import scipp.constants
from ess.reduce import time_of_flight
from ess.reduce.nexus.types import AnyRun
from scippneutron.chopper import DiskChopper
[3]:
# Parameters from the ESTIA McStas file:
# https://git.esss.dk/dmsc-instrumentmodels/estia/-/blob/main/mcstas-master/simulation/Estia_baseline.instr
min_wavelength = sc.scalar(3.75, unit='angstrom')
chopper_position = sc.scalar(10.895, unit='m')
max_velocity = (sc.constants.h / sc.constants.m_n / min_wavelength).to(unit='m/s')
delay = chopper_position / max_velocity
pulse_stride = 1
frequency = -sc.scalar(14., unit='Hz') / pulse_stride

disk_choppers = {
    "fc": DiskChopper(
        frequency=frequency,
        beam_position=sc.scalar(0.0, unit="deg"),
        phase=delay * frequency * sc.scalar(360, unit="deg"),
        axle_position=sc.vector(value=[0, 0., chopper_position.value], unit=chopper_position.unit),
        slit_begin=sc.array(
            dims=["cutout"],
            values=[
                0.
            ],
            unit="deg",
        ),
        slit_end=sc.array(
            dims=["cutout"],
            values=[
                98.
            ],
            unit="deg",
        ),
    ),
}
disk_choppers['fc']
[3]:
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [ 0. 0. 10.895]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    -14.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    -52.05099341448456
  • slit_begin
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    0.0
  • slit_end
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    98.0
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 TDC beam position
[4]:
wf = time_of_flight.TofLookupTableWorkflow()

wf[time_of_flight.LtotalRange] = sc.scalar(35., unit="m"), sc.scalar(45.0, unit="m")
wf[time_of_flight.NumberOfSimulatedNeutrons] = 5000_000
wf[time_of_flight.SourcePosition] = sc.vector([0, 0, 0], unit='m')
wf[time_of_flight.DiskChoppers[AnyRun]] = disk_choppers
wf[time_of_flight.DistanceResolution] = sc.scalar(0.05, unit="m")
wf[time_of_flight.TimeResolution] = sc.scalar(250.0, unit='us')
wf[time_of_flight.LookupTableRelativeErrorThreshold] = 0.06
wf[time_of_flight.PulsePeriod] = 1.0 / sc.scalar(14.0, unit="Hz")
wf[time_of_flight.PulseStride] = pulse_stride
wf[time_of_flight.PulseStrideOffset] = 0
[5]:
%%time
table = wf.compute(time_of_flight.TimeOfFlightLookupTable)
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'.
CPU times: user 29.7 s, sys: 6.36 s, total: 36.1 s
Wall time: 14.8 s
[5]:
Show/Hide data repr Show/Hide attributes
scipp.DataArray (921.06 KB)
    • distance: 204
    • event_time_offset: 287
    • distance
      (distance)
      float64
      m
      34.925, 34.975, ..., 45.025, 45.075
      Values:
      array([34.925, 34.975, 35.025, 35.075, 35.125, 35.175, 35.225, 35.275, 35.325, 35.375, 35.425, 35.475, 35.525, 35.575, 35.625, 35.675, 35.725, 35.775, 35.825, 35.875, 35.925, 35.975, 36.025, 36.075, 36.125, 36.175, 36.225, 36.275, 36.325, 36.375, 36.425, 36.475, 36.525, 36.575, 36.625, 36.675, 36.725, 36.775, 36.825, 36.875, 36.925, 36.975, 37.025, 37.075, 37.125, 37.175, 37.225, 37.275, 37.325, 37.375, 37.425, 37.475, 37.525, 37.575, 37.625, 37.675, 37.725, 37.775, 37.825, 37.875, 37.925, 37.975, 38.025, 38.075, 38.125, 38.175, 38.225, 38.275, 38.325, 38.375, 38.425, 38.475, 38.525, 38.575, 38.625, 38.675, 38.725, 38.775, 38.825, 38.875, 38.925, 38.975, 39.025, 39.075, 39.125, 39.175, 39.225, 39.275, 39.325, 39.375, 39.425, 39.475, 39.525, 39.575, 39.625, 39.675, 39.725, 39.775, 39.825, 39.875, 39.925, 39.975, 40.025, 40.075, 40.125, 40.175, 40.225, 40.275, 40.325, 40.375, 40.425, 40.475, 40.525, 40.575, 40.625, 40.675, 40.725, 40.775, 40.825, 40.875, 40.925, 40.975, 41.025, 41.075, 41.125, 41.175, 41.225, 41.275, 41.325, 41.375, 41.425, 41.475, 41.525, 41.575, 41.625, 41.675, 41.725, 41.775, 41.825, 41.875, 41.925, 41.975, 42.025, 42.075, 42.125, 42.175, 42.225, 42.275, 42.325, 42.375, 42.425, 42.475, 42.525, 42.575, 42.625, 42.675, 42.725, 42.775, 42.825, 42.875, 42.925, 42.975, 43.025, 43.075, 43.125, 43.175, 43.225, 43.275, 43.325, 43.375, 43.425, 43.475, 43.525, 43.575, 43.625, 43.675, 43.725, 43.775, 43.825, 43.875, 43.925, 43.975, 44.025, 44.075, 44.125, 44.175, 44.225, 44.275, 44.325, 44.375, 44.425, 44.475, 44.525, 44.575, 44.625, 44.675, 44.725, 44.775, 44.825, 44.875, 44.925, 44.975, 45.025, 45.075])
    • distance_resolution
      ()
      float64
      m
      0.05000000000000426
      Values:
      array(0.05)
    • error_threshold
      ()
      float64
      𝟙
      0.06
      Values:
      array(0.06)
    • event_time_offset
      (event_time_offset)
      float64
      µs
      0.0, 249.750, ..., 7.118e+04, 7.143e+04
      Values:
      array([ 0. , 249.75024975, 499.5004995 , 749.25074925, 999.000999 , 1248.75124875, 1498.5014985 , 1748.25174825, 1998.001998 , 2247.75224775, 2497.5024975 , 2747.25274725, 2997.002997 , 3246.75324675, 3496.5034965 , 3746.25374625, 3996.003996 , 4245.75424575, 4495.5044955 , 4745.25474525, 4995.004995 , 5244.75524476, 5494.50549451, 5744.25574426, 5994.00599401, 6243.75624376, 6493.50649351, 6743.25674326, 6993.00699301, 7242.75724276, 7492.50749251, 7742.25774226, 7992.00799201, 8241.75824176, 8491.50849151, 8741.25874126, 8991.00899101, 9240.75924076, 9490.50949051, 9740.25974026, 9990.00999001, 10239.76023976, 10489.51048951, 10739.26073926, 10989.01098901, 11238.76123876, 11488.51148851, 11738.26173826, 11988.01198801, 12237.76223776, 12487.51248751, 12737.26273726, 12987.01298701, 13236.76323676, 13486.51348651, 13736.26373626, 13986.01398601, 14235.76423576, 14485.51448551, 14735.26473526, 14985.01498501, 15234.76523477, 15484.51548452, 15734.26573427, 15984.01598402, 16233.76623377, 16483.51648352, 16733.26673327, 16983.01698302, 17232.76723277, 17482.51748252, 17732.26773227, 17982.01798202, 18231.76823177, 18481.51848152, 18731.26873127, 18981.01898102, 19230.76923077, 19480.51948052, 19730.26973027, 19980.01998002, 20229.77022977, 20479.52047952, 20729.27072927, 20979.02097902, 21228.77122877, 21478.52147852, 21728.27172827, 21978.02197802, 22227.77222777, 22477.52247752, 22727.27272727, 22977.02297702, 23226.77322677, 23476.52347652, 23726.27372627, 23976.02397602, 24225.77422577, 24475.52447552, 24725.27472527, 24975.02497502, 25224.77522478, 25474.52547453, 25724.27572428, 25974.02597403, 26223.77622378, 26473.52647353, 26723.27672328, 26973.02697303, 27222.77722278, 27472.52747253, 27722.27772228, 27972.02797203, 28221.77822178, 28471.52847153, 28721.27872128, 28971.02897103, 29220.77922078, 29470.52947053, 29720.27972028, 29970.02997003, 30219.78021978, 30469.53046953, 30719.28071928, 30969.03096903, 31218.78121878, 31468.53146853, 31718.28171828, 31968.03196803, 32217.78221778, 32467.53246753, 32717.28271728, 32967.03296703, 33216.78321678, 33466.53346653, 33716.28371628, 33966.03396603, 34215.78421578, 34465.53446553, 34715.28471528, 34965.03496503, 35214.78521479, 35464.53546454, 35714.28571429, 35964.03596404, 36213.78621379, 36463.53646354, 36713.28671329, 36963.03696304, 37212.78721279, 37462.53746254, 37712.28771229, 37962.03796204, 38211.78821179, 38461.53846154, 38711.28871129, 38961.03896104, 39210.78921079, 39460.53946054, 39710.28971029, 39960.03996004, 40209.79020979, 40459.54045954, 40709.29070929, 40959.04095904, 41208.79120879, 41458.54145854, 41708.29170829, 41958.04195804, 42207.79220779, 42457.54245754, 42707.29270729, 42957.04295704, 43206.79320679, 43456.54345654, 43706.29370629, 43956.04395604, 44205.79420579, 44455.54445554, 44705.29470529, 44955.04495504, 45204.7952048 , 45454.54545455, 45704.2957043 , 45954.04595405, 46203.7962038 , 46453.54645355, 46703.2967033 , 46953.04695305, 47202.7972028 , 47452.54745255, 47702.2977023 , 47952.04795205, 48201.7982018 , 48451.54845155, 48701.2987013 , 48951.04895105, 49200.7992008 , 49450.54945055, 49700.2997003 , 49950.04995005, 50199.8001998 , 50449.55044955, 50699.3006993 , 50949.05094905, 51198.8011988 , 51448.55144855, 51698.3016983 , 51948.05194805, 52197.8021978 , 52447.55244755, 52697.3026973 , 52947.05294705, 53196.8031968 , 53446.55344655, 53696.3036963 , 53946.05394605, 54195.8041958 , 54445.55444555, 54695.3046953 , 54945.05494505, 55194.80519481, 55444.55544456, 55694.30569431, 55944.05594406, 56193.80619381, 56443.55644356, 56693.30669331, 56943.05694306, 57192.80719281, 57442.55744256, 57692.30769231, 57942.05794206, 58191.80819181, 58441.55844156, 58691.30869131, 58941.05894106, 59190.80919081, 59440.55944056, 59690.30969031, 59940.05994006, 60189.81018981, 60439.56043956, 60689.31068931, 60939.06093906, 61188.81118881, 61438.56143856, 61688.31168831, 61938.06193806, 62187.81218781, 62437.56243756, 62687.31268731, 62937.06293706, 63186.81318681, 63436.56343656, 63686.31368631, 63936.06393606, 64185.81418581, 64435.56443556, 64685.31468531, 64935.06493506, 65184.81518482, 65434.56543457, 65684.31568432, 65934.06593407, 66183.81618382, 66433.56643357, 66683.31668332, 66933.06693307, 67182.81718282, 67432.56743257, 67682.31768232, 67932.06793207, 68181.81818182, 68431.56843157, 68681.31868132, 68931.06893107, 69180.81918082, 69430.56943057, 69680.31968032, 69930.06993007, 70179.82017982, 70429.57042957, 70679.32067932, 70929.07092907, 71178.82117882, 71428.57142857])
    • pulse_period
      ()
      float64
      µs
      71428.57142857142
      Values:
      array(71428.57142857)
    • pulse_stride
      ()
      int64
      1
      Values:
      array(1)
    • time_resolution
      ()
      float64
      µs
      249.7502497502497
      Values:
      array(249.75024975)
    • (distance, event_time_offset)
      float64
      µs
      6.964e+04, 6.989e+04, ..., 6.940e+04, 6.965e+04
      σ = 915.023, 892.781, ..., 872.097, 888.696
      Values:
      array([[69638.23285721, 69887.72225035, 70169.27129747, ..., 69121.42528001, 69388.60557154, 69638.23285721], [69622.76685692, 69891.61999751, 70180.84517954, ..., 69135.80491875, 69404.84711203, 69622.76685692], [69635.06543179, 69897.73635576, 70137.98337023, ..., 69162.80477032, 69392.53892325, 69635.06543179], ..., [69607.8439458 , 69894.88469886, 70143.25858538, ..., 69149.52257852, 69397.30466499, 69607.8439458 ], [69624.22986895, 69878.71161611, 70139.44200696, ..., 69141.29531162, 69398.81940537, 69624.22986895], [69651.23324715, 69848.84369042, 70153.70910563, ..., 69139.91165684, 69398.45304886, 69651.23324715]], shape=(204, 287))

      Variances (σ²):
      array([[837267.59309524, 797057.47905766, 790564.20486503, ..., 769569.19320774, 775436.66420721, 837267.59309524], [840209.51127257, 777361.42839559, 814831.10723519, ..., 762291.71155885, 775876.28463856, 840209.51127257], [805148.90819044, 823927.39782563, 796894.53537645, ..., 770269.24283265, 765041.67249943, 805148.90819044], ..., [810235.07904269, 806317.64134135, 790367.51476227, ..., 763821.24634818, 770134.70157748, 810235.07904269], [810380.52151186, 798030.26390586, 795467.22089071, ..., 789634.629494 , 765412.08308885, 810380.52151186], [789780.36543822, 812501.53848979, 788567.60506206, ..., 786053.90863969, 760552.50844325, 789780.36543822]], shape=(204, 287))
[6]:
# This is what the relationship between time-of-arrival and time-of-flight looks like at 40m (at the detector).
table['distance', 100].plot()
[6]:
../../_images/user-guide_estia_create-estia-tof-lookup-table_6_0.svg
[7]:
table.plot()
[7]:
../../_images/user-guide_estia_create-estia-tof-lookup-table_7_0.svg
[8]:
table.save_hdf5(f'estia-tof-lookup-table-pulse-stride-{pulse_stride}.h5')