ODIN#

[1]:
import scipp as sc
import tof

import scippnexus as snx
from ess.reduce.unwrap import GenericUnwrapWorkflow
from ess.reduce.nexus.types import *
from ess.reduce.unwrap.types import *
from ess.reduce.unwrap.lut import LtotalRange, ChopperFrameSequence

Chopper parameters#

[2]:
choppers = {
    "WFMC_1": {
        "frequency": {"value": 56.0, "unit": "Hz"},
        "open": {
            "value": [-1.9419, 49.5756, 98.9315, 146.2165, 191.5176, 234.9179],
            "unit": "deg",
        },
        "close": {
            "value": [1.9419, 55.7157, 107.2332, 156.5891, 203.8741, 249.1752],
            "unit": "deg",
        },
        "distance": {"value": 6.85, "unit": "m"},
        "phase": {"value": 93.244, "unit": "deg"},
        "type": "chopper",
        "direction": "clockwise",
        "name": "WFMC_1",
    },
    "WFMC_2": {
        "frequency": {"value": 56.0, "unit": "Hz"},
        "open": {
            "value": [-1.9419, 51.8318, 103.3493, 152.7052, 199.9903, 245.2914],
            "unit": "deg",
        },
        "close": {
            "value": [1.9419, 57.9719, 111.651, 163.0778, 212.3468, 259.5486],
            "unit": "deg",
        },
        "distance": {"value": 7.15, "unit": "m"},
        "phase": {"value": 97.128, "unit": "deg"},
        "type": "chopper",
        "direction": "clockwise",
        "name": "WFMC_2",
    },
    "FOC_1": {
        "frequency": {"value": 42.0, "unit": "Hz"},
        "open": {
            "value": [-5.1362, 42.5536, 88.2425, 132.0144, 173.9497, 216.7867],
            "unit": "deg",
        },
        "close": {
            "value": [5.1362, 54.2095, 101.2237, 146.2653, 189.417, 230.7582],
            "unit": "deg",
        },
        "distance": {"value": 8.4, "unit": "m"},
        "phase": {"value": 81.303297, "unit": "deg"},
        "type": "chopper",
        "direction": "clockwise",
        "name": "FOC_1",
    },
    "BP_1": {
        "frequency": {"value": 7.0, "unit": "Hz"},
        "open": {"value": [-23.6029], "unit": "deg"},
        "close": {"value": [23.6029], "unit": "deg"},
        "distance": {"value": 8.45, "unit": "m"},
        "phase": {"value": 31.08, "unit": "deg"},
        "type": "chopper",
        "direction": "clockwise",
        "name": "BP_1",
    },
    "FOC_2": {
        "frequency": {"value": 42.0, "unit": "Hz"},
        "open": {
            "value": [-16.3227, 53.7401, 120.8633, 185.1701, 246.7787, 307.0165],
            "unit": "deg",
        },
        "close": {
            "value": [16.3227, 86.8303, 154.3794, 218.7551, 280.7508, 340.3188],
            "unit": "deg",
        },
        "distance": {"value": 12.2, "unit": "m"},
        "phase": {"value": 107.013442, "unit": "deg"},
        "type": "chopper",
        "direction": "clockwise",
        "name": "FOC_2",
    },
    "BP_2": {
        "frequency": {"value": 7.0, "unit": "Hz"},
        "open": {"value": [-34.4663], "unit": "deg"},
        "close": {"value": [34.4663], "unit": "deg"},
        "distance": {"value": 12.25, "unit": "m"},
        "phase": {"value": 44.224, "unit": "deg"},
        "type": "chopper",
        "direction": "clockwise",
        "name": "BP_2",
    },
    "T0_alpha": {
        "frequency": {"value": 14.0, "unit": "Hz"},
        "open": {"value": [-167.8986], "unit": "deg"},
        "close": {"value": [167.8986], "unit": "deg"},
        "distance": {"value": 13.5, "unit": "m"},
        "phase": {"value": 179.672, "unit": "deg"},
        "type": "chopper",
        "direction": "clockwise",
        "name": "T0_alpha",
    },
    "T0_beta": {
        "frequency": {"value": 14.0, "unit": "Hz"},
        "open": {"value": [-167.8986], "unit": "deg"},
        "close": {"value": [167.8986], "unit": "deg"},
        "distance": {"value": 13.7, "unit": "m"},
        "phase": {"value": 179.672, "unit": "deg"},
        "type": "chopper",
        "direction": "clockwise",
        "name": "T0_beta",
    },
    "FOC_3": {
        "frequency": {"value": 28.0, "unit": "Hz"},
        "open": {
            "value": [-20.302, 45.247, 108.0457, 168.2095, 225.8489, 282.2199],
            "unit": "deg",
        },
        "close": {
            "value": [20.302, 85.357, 147.6824, 207.3927, 264.5977, 319.4024],
            "unit": "deg",
        },
        "distance": {"value": 17.0, "unit": "m"},
        "phase": {"value": 92.993, "unit": "deg"},
        "type": "chopper",
        "direction": "clockwise",
        "name": "FOC_3",
    },
    "FOC_4": {
        "frequency": {"value": 14.0, "unit": "Hz"},
        "open": {
            "value": [-16.7157, 29.1882, 73.1661, 115.2988, 155.6636, 195.5254],
            "unit": "deg",
        },
        "close": {
            "value": [16.7157, 61.8217, 105.0352, 146.4355, 186.0987, 224.0978],
            "unit": "deg",
        },
        "distance": {"value": 23.69, "unit": "m"},
        "phase": {"value": 61.584, "unit": "deg"},
        "type": "chopper",
        "direction": "clockwise",
        "name": "FOC_4",
    },
    "FOC_5": {
        "frequency": {"value": 14.0, "unit": "Hz"},
        "open": {
            "value": [-25.8514, 38.3239, 99.8064, 160.1254, 217.4321, 272.5426],
            "unit": "deg",
        },
        "close": {
            "value": [25.8514, 88.4621, 147.4729, 204.0245, 257.7603, 313.7139],
            "unit": "deg",
        },
        "distance": {"value": 33.0, "unit": "m"},
        "phase": {"value": 82.581, "unit": "deg"},
        "type": "chopper",
        "direction": "clockwise",
        "name": "FOC_5",
    },
}
[3]:
odin_choppers = {}
for key, ch in choppers.items():
    odin_choppers[key] = tof.Chopper.from_json(name=key, params=ch).to_diskchopper()

for key, ch in odin_choppers.items():
    print(key)
    display(ch)
WFMC_1
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [0. 0. 6.85]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    -56.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    -93.244
  • slit_begin
    scipp
    Variable
    (cutout: 6)
    float64
    deg
    -1.942, 49.576, ..., 191.518, 234.918
  • slit_end
    scipp
    Variable
    (cutout: 6)
    float64
    deg
    1.942, 55.716, ..., 203.874, 249.175
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 begin1 end1 begin2 end2 begin3 end3 begin4 end4 begin5 end5 TDC beam position
WFMC_2
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [0. 0. 7.15]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    -56.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    -97.128
  • slit_begin
    scipp
    Variable
    (cutout: 6)
    float64
    deg
    -1.942, 51.832, ..., 199.990, 245.291
  • slit_end
    scipp
    Variable
    (cutout: 6)
    float64
    deg
    1.942, 57.972, ..., 212.347, 259.549
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 begin1 end1 begin2 end2 begin3 end3 begin4 end4 begin5 end5 TDC beam position
FOC_1
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [0. 0. 8.4]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    -42.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    -81.303297
  • slit_begin
    scipp
    Variable
    (cutout: 6)
    float64
    deg
    -5.136, 42.554, ..., 173.950, 216.787
  • slit_end
    scipp
    Variable
    (cutout: 6)
    float64
    deg
    5.136, 54.209, ..., 189.417, 230.758
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 begin1 end1 begin2 end2 begin3 end3 begin4 end4 begin5 end5 TDC beam position
BP_1
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [0. 0. 8.45]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    -7.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    -31.08
  • slit_begin
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    -23.603
  • slit_end
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    23.603
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 TDC beam position
FOC_2
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [ 0. 0. 12.2]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    -42.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    -107.013442
  • slit_begin
    scipp
    Variable
    (cutout: 6)
    float64
    deg
    -16.323, 53.740, ..., 246.779, 307.017
  • slit_end
    scipp
    Variable
    (cutout: 6)
    float64
    deg
    16.323, 86.830, ..., 280.751, 340.319
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 begin1 end1 begin2 end2 begin3 end3 begin4 end4 begin5 end5 TDC beam position
BP_2
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [ 0. 0. 12.25]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    -7.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    -44.224
  • slit_begin
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    -34.466
  • slit_end
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    34.466
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 TDC beam position
T0_alpha
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [ 0. 0. 13.5]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    -14.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    -179.672
  • slit_begin
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    -167.899
  • slit_end
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    167.899
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 TDC beam position
T0_beta
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [ 0. 0. 13.7]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    -14.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    -179.672
  • slit_begin
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    -167.899
  • slit_end
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    167.899
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 TDC beam position
FOC_3
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [ 0. 0. 17.]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    -28.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    -92.993
  • slit_begin
    scipp
    Variable
    (cutout: 6)
    float64
    deg
    -20.302, 45.247, ..., 225.849, 282.220
  • slit_end
    scipp
    Variable
    (cutout: 6)
    float64
    deg
    20.302, 85.357, ..., 264.598, 319.402
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 begin1 end1 begin2 end2 begin3 end3 begin4 end4 begin5 end5 TDC beam position
FOC_4
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [ 0. 0. 23.69]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    -14.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    -61.584
  • slit_begin
    scipp
    Variable
    (cutout: 6)
    float64
    deg
    -16.716, 29.188, ..., 155.664, 195.525
  • slit_end
    scipp
    Variable
    (cutout: 6)
    float64
    deg
    16.716, 61.822, ..., 186.099, 224.098
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 begin1 end1 begin2 end2 begin3 end3 begin4 end4 begin5 end5 TDC beam position
FOC_5
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [ 0. 0. 33.]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    -14.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    -82.581
  • slit_begin
    scipp
    Variable
    (cutout: 6)
    float64
    deg
    -25.851, 38.324, ..., 217.432, 272.543
  • slit_end
    scipp
    Variable
    (cutout: 6)
    float64
    deg
    25.851, 88.462, ..., 257.760, 313.714
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 begin1 end1 begin2 end2 begin3 end3 begin4 end4 begin5 end5 TDC beam position

Tof model#

[4]:
source = tof.Source(facility="ess", neutrons=1_000_000, pulses=2)
source_position = sc.vector([0, 0, 0], unit="m")
detector = tof.Detector(distance=sc.scalar(60.5, unit="m"), name="detector")

params = [
    tof.Chopper.from_diskchopper(ch, name=key) for key, ch in odin_choppers.items()
] + [detector]

model = tof.Model(source=source, components=params)
res = model.run()
res.plot()
[4]:
Plot(ax=<Axes: xlabel='Time [μs]', ylabel='Distance [m]'>, fig=<Figure size 1200x480 with 2 Axes>)
_images/odin_6_1.png
[5]:
res["detector"].plot()
[5]:
_images/odin_7_0.svg

Wavelength lookup table#

[6]:
wf = GenericUnwrapWorkflow(
    run_types=[SampleRun], monitor_types=[], wavelength_from="analytical"
)

wf[DiskChoppers[SampleRun]] = odin_choppers
wf[LtotalRange[SampleRun, snx.NXdetector]] = sc.scalar(5, unit="m"), detector.distance
wf[Position[snx.NXsource, SampleRun]] = source_position

table = wf.compute(LookupTable[SampleRun, snx.NXdetector])

table.plot() + table.array['distance', -1].plot(errorbars='band')
[6]:
_images/odin_9_0.svg
[7]:
frames = wf.compute(ChopperFrameSequence[SampleRun])
at_sample = frames.propagate_to(detector.distance)
at_sample.draw()
[7]:
(<Figure size 640x480 with 1 Axes>,
 <Axes: title={'center': 'Frame propagation through chopper cascade'}, xlabel='ms', ylabel='Å'>)
_images/odin_10_1.png