BEER#

[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

Mode 3 pulse shaping (MR) - PS2#

Chopper parameters#

[2]:
choppers = {
    "PSC1": {
        "frequency": {"value": 168.0, "unit": "Hz"},
        "open": {"value": [0.0], "unit": "deg"},
        "close": {"value": [144.0], "unit": "deg"},
        "distance": {"value": 6.45, "unit": "m"},
        "phase": {"value": 299.983856971683, "unit": "deg"},
        "type": "chopper",
        "direction": "anticlockwise",
        "name": "PSC1",
    },
    "PSC2": {
        "frequency": {"value": 168.0, "unit": "Hz"},
        "open": {"value": [0.0], "unit": "deg"},
        "close": {"value": [144.0], "unit": "deg"},
        "distance": {"value": 6.85, "unit": "m"},
        "phase": {"value": 299.983856971683, "unit": "deg"},
        "type": "chopper",
        "direction": "clockwise",
        "name": "PSC2",
    },
    "FC1A": {
        "frequency": {"value": 14.0, "unit": "Hz"},
        "open": {"value": [0.0], "unit": "deg"},
        "close": {"value": [72.0], "unit": "deg"},
        "distance": {"value": 8.283, "unit": "m"},
        "phase": {"value": -12.63240606395426, "unit": "deg"},
        "type": "chopper",
        "direction": "clockwise",
        "name": "FC1A",
    },
    "FC2A": {
        "frequency": {"value": 14.0, "unit": "Hz"},
        "open": {"value": [0.0], "unit": "deg"},
        "close": {"value": [175.0], "unit": "deg"},
        "distance": {"value": 79.975, "unit": "m"},
        "phase": {"value": 133.67285314925246, "unit": "deg"},
        "type": "chopper",
        "direction": "clockwise",
        "name": "FC2A",
    },
}
[3]:
beer_choppers = {}
for key, ch in choppers.items():
    beer_choppers[key] = tof.Chopper.from_json(name=key, params=ch).to_diskchopper()

for key, ch in beer_choppers.items():
    print(key)
    display(ch)
PSC1
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [0. 0. 6.45]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    168.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    299.983856971683
  • slit_begin
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    0.0
  • slit_end
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    144.0
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 TDC beam position
PSC2
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [0. 0. 6.85]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    -168.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    -299.983856971683
  • slit_begin
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    0.0
  • slit_end
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    144.0
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 TDC beam position
FC1A
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [0. 0. 8.283]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    -14.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    12.63240606395426
  • slit_begin
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    0.0
  • slit_end
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    72.0
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 TDC beam position
FC2A
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [ 0. 0. 79.975]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    -14.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    -133.67285314925246
  • slit_begin
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    0.0
  • slit_end
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    175.0
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 TDC beam position

Tof model#

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

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

model = tof.Model(source=source, components=params)
res = model.run()
res.plot()
Downloading file 'ess/ess.h5' from 'https://public.esss.dk/groups/scipp/tof/2/ess/ess.h5' to '/home/runner/.cache/tof'.
[4]:
Plot(ax=<Axes: xlabel='Time [μs]', ylabel='Distance [m]'>, fig=<Figure size 1200x480 with 2 Axes>)
_images/beer_6_2.png
[5]:
res["detector"].plot()
[5]:
_images/beer_7_0.svg

Wavelength lookup table#

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

wf[DiskChoppers[SampleRun]] = beer_choppers
wf[LtotalRange[SampleRun, snx.NXdetector]] = (
    sc.scalar(5.0, unit="m"),
    detector.distance - source_position.fields.z,
)
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/beer_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/beer_10_1.png

Mode 4 pulse shaping (HR) - PS3#

Chopper parameters#

[8]:
choppers = {
    "PSC1": {
        "frequency": {"value": 168.0, "unit": "Hz"},
        "open": {"value": [0.0], "unit": "deg"},
        "close": {"value": [144.0], "unit": "deg"},
        "distance": {"value": 6.45, "unit": "m"},
        "phase": {"value": 296.77336889692083, "unit": "deg"},
        "type": "chopper",
        "direction": "anticlockwise",
        "name": "PSC1",
    },
    "PSC2": {
        "frequency": {"value": 168.0, "unit": "Hz"},
        "open": {"value": [0.0], "unit": "deg"},
        "close": {"value": [144.0], "unit": "deg"},
        "distance": {"value": 6.65, "unit": "m"},
        "phase": {"value": 296.77336889692083, "unit": "deg"},
        "type": "chopper",
        "direction": "clockwise",
        "name": "PSC2",
    },
    "FC1A": {
        "frequency": {"value": 14.0, "unit": "Hz"},
        "open": {"value": [0.0], "unit": "deg"},
        "close": {"value": [72.0], "unit": "deg"},
        "distance": {"value": 8.283, "unit": "m"},
        "phase": {"value": -12.63240606395426, "unit": "deg"},
        "type": "chopper",
        "direction": "clockwise",
        "name": "FC1A",
    },
    "FC2A": {
        "frequency": {"value": 14.0, "unit": "Hz"},
        "open": {"value": [0.0], "unit": "deg"},
        "close": {"value": [175.0], "unit": "deg"},
        "distance": {"value": 79.975, "unit": "m"},
        "phase": {"value": 133.67285314925246, "unit": "deg"},
        "type": "chopper",
        "direction": "clockwise",
        "name": "FC2A",
    },
}
[9]:
beer_choppers = {}
for key, ch in choppers.items():
    beer_choppers[key] = tof.Chopper.from_json(name=key, params=ch).to_diskchopper()

for key, ch in beer_choppers.items():
    print(key)
    display(ch)
PSC1
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [0. 0. 6.45]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    168.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    296.77336889692083
  • slit_begin
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    0.0
  • slit_end
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    144.0
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 TDC beam position
PSC2
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [0. 0. 6.65]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    -168.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    -296.77336889692083
  • slit_begin
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    0.0
  • slit_end
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    144.0
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 TDC beam position
FC1A
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [0. 0. 8.283]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    -14.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    12.63240606395426
  • slit_begin
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    0.0
  • slit_end
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    72.0
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 TDC beam position
FC2A
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [ 0. 0. 79.975]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    -14.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    -133.67285314925246
  • slit_begin
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    0.0
  • slit_end
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    175.0
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 TDC beam position

Tof model#

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

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

Wavelength lookup table#

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

wf[DiskChoppers[SampleRun]] = beer_choppers
wf[LtotalRange[SampleRun, snx.NXdetector]] = (
    sc.scalar(5.0, unit="m"),
    detector.distance - source_position.fields.z,
)
wf[Position[snx.NXsource, SampleRun]] = source_position

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

Mode 5 modulation (HF) 8X - M0+M1#

Chopper parameters#

[14]:
choppers = {
    "FC1A": {
        "frequency": {"value": 14.0, "unit": "Hz"},
        "open": {"value": [0.0], "unit": "deg"},
        "close": {"value": [72.0], "unit": "deg"},
        "distance": {"value": 8.283, "unit": "m"},
        "phase": {"value": -21.63240606395426, "unit": "deg"},
        "type": "chopper",
        "direction": "clockwise",
        "name": "FC1A",
    },
    "MCA": {
        "frequency": {"value": 70.0, "unit": "Hz"},
        "open": {
            "value": [0.0, 45.0, 90.0, 135.0, 180.0, 225.0, 270.0, 315.0],
            "unit": "deg",
        },
        "close": {
            "value": [5.0, 50.0, 95.0, 140.0, 185.0, 230.0, 275.0, 320.0],
            "unit": "deg",
        },
        "distance": {"value": 9.3, "unit": "m"},
        "phase": {"value": 157.94241289703336, "unit": "deg"},
        "type": "chopper",
        "direction": "clockwise",
        "name": "MCA",
    },
    "FC2A": {
        "frequency": {"value": 14.0, "unit": "Hz"},
        "open": {"value": [0.0], "unit": "deg"},
        "close": {"value": [175.0], "unit": "deg"},
        "distance": {"value": 79.975, "unit": "m"},
        "phase": {"value": 133.67285314925246, "unit": "deg"},
        "type": "chopper",
        "direction": "clockwise",
        "name": "FC2A",
    },
}
[15]:
beer_choppers = {}
for key, ch in choppers.items():
    beer_choppers[key] = tof.Chopper.from_json(name=key, params=ch).to_diskchopper()

for key, ch in beer_choppers.items():
    print(key)
    display(ch)
FC1A
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [0. 0. 8.283]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    -14.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    21.63240606395426
  • slit_begin
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    0.0
  • slit_end
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    72.0
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 TDC beam position
MCA
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [0. 0. 9.3]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    -70.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    -157.94241289703336
  • slit_begin
    scipp
    Variable
    (cutout: 8)
    float64
    deg
    0.0, 45.0, ..., 270.0, 315.0
  • slit_end
    scipp
    Variable
    (cutout: 8)
    float64
    deg
    5.0, 50.0, ..., 275.0, 320.0
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 begin1 end1 begin2 end2 begin3 end3 begin4 end4 begin5 end5 begin6 end6 begin7 end7 TDC beam position
FC2A
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [ 0. 0. 79.975]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    -14.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    -133.67285314925246
  • slit_begin
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    0.0
  • slit_end
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    175.0
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 TDC beam position

Tof model#

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

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

Wavelength lookup table#

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

wf[DiskChoppers[SampleRun]] = beer_choppers
wf[LtotalRange[SampleRun, snx.NXdetector]] = (
    sc.scalar(5.0, unit="m"),
    detector.distance - source_position.fields.z,
)
wf[Position[snx.NXsource, SampleRun]] = source_position

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

Mode 10 modulation (MR) 16X - M2#

Chopper parameters#

[20]:
choppers = {
    "FC1A": {
        "frequency": {"value": 14.0, "unit": "Hz"},
        "open": {"value": [0.0], "unit": "deg"},
        "close": {"value": [72.0], "unit": "deg"},
        "distance": {"value": 8.283, "unit": "m"},
        "phase": {"value": -21.63240606395426, "unit": "deg"},
        "type": "chopper",
        "direction": "clockwise",
        "name": "FC1A",
    },
    "MCB": {
        "frequency": {"value": 140.0, "unit": "Hz"},
        "open": {
            "value": [
                0.0,
                22.5,
                45.0,
                67.5,
                90.0,
                112.5,
                135.0,
                157.5,
                180.0,
                202.5,
                225.0,
                247.5,
                270.0,
                292.5,
                315.0,
                337.5,
            ],
            "unit": "deg",
        },
        "close": {
            "value": [
                5.0,
                27.5,
                50.0,
                72.5,
                95.0,
                117.5,
                140.0,
                162.5,
                185.0,
                207.5,
                230.0,
                252.5,
                275.0,
                297.5,
                320.0,
                342.5,
            ],
            "unit": "deg",
        },
        "distance": {"value": 9.35, "unit": "m"},
        "phase": {"value": 319.72252915855086, "unit": "deg"},
        "type": "chopper",
        "direction": "clockwise",
        "name": "MCB",
    },
    "FC2A": {
        "frequency": {"value": 14.0, "unit": "Hz"},
        "open": {"value": [0.0], "unit": "deg"},
        "close": {"value": [175.0], "unit": "deg"},
        "distance": {"value": 79.975, "unit": "m"},
        "phase": {"value": 133.67285314925246, "unit": "deg"},
        "type": "chopper",
        "direction": "clockwise",
        "name": "FC2A",
    },
}
[21]:
beer_choppers = {}
for key, ch in choppers.items():
    beer_choppers[key] = tof.Chopper.from_json(name=key, params=ch).to_diskchopper()

for key, ch in beer_choppers.items():
    print(key)
    display(ch)
FC1A
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [0. 0. 8.283]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    -14.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    21.63240606395426
  • slit_begin
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    0.0
  • slit_end
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    72.0
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 TDC beam position
MCB
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [0. 0. 9.35]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    -140.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    -319.72252915855086
  • slit_begin
    scipp
    Variable
    (cutout: 16)
    float64
    deg
    0.0, 22.5, ..., 315.0, 337.5
  • slit_end
    scipp
    Variable
    (cutout: 16)
    float64
    deg
    5.0, 27.5, ..., 320.0, 342.5
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 begin1 end1 begin2 end2 begin3 end3 begin4 end4 begin5 end5 begin6 end6 begin7 end7 begin8 end8 begin9 end9 begin10 end10 begin11 end11 begin12 end12 begin13 end13 begin14 end14 begin15 end15 TDC beam position
FC2A
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [ 0. 0. 79.975]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    -14.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    -133.67285314925246
  • slit_begin
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    0.0
  • slit_end
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    175.0
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 TDC beam position

Tof model#

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

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

Wavelength lookup table#

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

wf[DiskChoppers[SampleRun]] = beer_choppers
wf[LtotalRange[SampleRun, snx.NXdetector]] = (
    sc.scalar(5.0, unit="m"),
    detector.distance - source_position.fields.z,
)
wf[Position[snx.NXsource, SampleRun]] = source_position

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

Mode 11 modulation (HR) 16X - M3#

Chopper parameters#

[26]:
choppers = {
    "FC1A": {
        "frequency": {"value": 14.0, "unit": "Hz"},
        "open": {"value": [0.0], "unit": "deg"},
        "close": {"value": [72.0], "unit": "deg"},
        "distance": {"value": 8.283, "unit": "m"},
        "phase": {"value": -21.63240606395426, "unit": "deg"},
        "type": "chopper",
        "direction": "clockwise",
        "name": "FC1A",
    },
    "MCB": {
        "frequency": {"value": 280.0, "unit": "Hz"},
        "open": {
            "value": [
                0.0,
                22.5,
                45.0,
                67.5,
                90.0,
                112.5,
                135.0,
                157.5,
                180.0,
                202.5,
                225.0,
                247.5,
                270.0,
                292.5,
                315.0,
                337.5,
            ],
            "unit": "deg",
        },
        "close": {
            "value": [
                5.0,
                27.5,
                50.0,
                72.5,
                95.0,
                117.5,
                140.0,
                162.5,
                185.0,
                207.5,
                230.0,
                252.5,
                275.0,
                297.5,
                320.0,
                342.5,
            ],
            "unit": "deg",
        },
        "distance": {"value": 9.35, "unit": "m"},
        "phase": {"value": 641.9450583171017, "unit": "deg"},
        "type": "chopper",
        "direction": "clockwise",
        "name": "MCB",
    },
    "FC2A": {
        "frequency": {"value": 14.0, "unit": "Hz"},
        "open": {"value": [0.0], "unit": "deg"},
        "close": {"value": [175.0], "unit": "deg"},
        "distance": {"value": 79.975, "unit": "m"},
        "phase": {"value": 133.67285314925246, "unit": "deg"},
        "type": "chopper",
        "direction": "clockwise",
        "name": "FC2A",
    },
}
[27]:
beer_choppers = {}
for key, ch in choppers.items():
    beer_choppers[key] = tof.Chopper.from_json(name=key, params=ch).to_diskchopper()

for key, ch in beer_choppers.items():
    print(key)
    display(ch)
FC1A
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [0. 0. 8.283]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    -14.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    21.63240606395426
  • slit_begin
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    0.0
  • slit_end
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    72.0
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 TDC beam position
MCB
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [0. 0. 9.35]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    -280.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    -641.9450583171017
  • slit_begin
    scipp
    Variable
    (cutout: 16)
    float64
    deg
    0.0, 22.5, ..., 315.0, 337.5
  • slit_end
    scipp
    Variable
    (cutout: 16)
    float64
    deg
    5.0, 27.5, ..., 320.0, 342.5
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 begin1 end1 begin2 end2 begin3 end3 begin4 end4 begin5 end5 begin6 end6 begin7 end7 begin8 end8 begin9 end9 begin10 end10 begin11 end11 begin12 end12 begin13 end13 begin14 end14 begin15 end15 TDC beam position
FC2A
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [ 0. 0. 79.975]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    -14.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    -133.67285314925246
  • slit_begin
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    0.0
  • slit_end
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    175.0
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 TDC beam position

Tof model#

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

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

Wavelength lookup table#

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

wf[DiskChoppers[SampleRun]] = beer_choppers
wf[LtotalRange[SampleRun, snx.NXdetector]] = (
    sc.scalar(5.0, unit="m"),
    detector.distance - source_position.fields.z,
)
wf[Position[snx.NXsource, SampleRun]] = source_position

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