NMX#

[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, SourceBounds

Chopper parameters#

[2]:
choppers = {
    "chopper1": {
        "frequency": {"value": 14.0, "unit": "Hz"},
        "open": {"value": [-38.5], "unit": "deg"},
        "close": {"value": [38.5], "unit": "deg"},
        "distance": {"value": 28.4, "unit": "m"},
        "phase": {"value": 111.2, "unit": "deg"},
        "type": "chopper",
        "direction": "clockwise",
        "name": "chopper1",
    },
    "chopper2a": {
        "frequency": {"value": 14.0, "unit": "Hz"},
        "open": {"value": [-70.0], "unit": "deg"},
        "close": {"value": [70.0], "unit": "deg"},
        "distance": {"value": 50.9774, "unit": "m"},
        "phase": {"value": 194.1, "unit": "deg"},
        "type": "chopper",
        "direction": "clockwise",
        "name": "chopper2a",
    },
    "chopper2b": {
        "frequency": {"value": 14.0, "unit": "Hz"},
        "open": {"value": [-70.0], "unit": "deg"},
        "close": {"value": [70.0], "unit": "deg"},
        "distance": {"value": 51.0024, "unit": "m"},
        "phase": {"value": 168.0, "unit": "deg"},
        "type": "chopper",
        "direction": "clockwise",
        "name": "chopper2b",
    },
}
[3]:
nmx_choppers = {}
for key, ch in choppers.items():
    nmx_choppers[key] = tof.Chopper.from_json(name=key, params=ch).to_diskchopper()

for key, ch in nmx_choppers.items():
    print(key)
    display(ch)
chopper1
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [ 0. 0. 28.4]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    -14.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    -111.2
  • slit_begin
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    -38.5
  • slit_end
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    38.5
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 TDC beam position
chopper2a
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [ 0. 0. 50.9774]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    -14.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    -194.1
  • slit_begin
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    -70.0
  • slit_end
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    70.0
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 TDC beam position
chopper2b
  • axle_position
    scipp
    Variable
    ()
    vector3
    m
    [ 0. 0. 51.0024]
  • frequency
    scipp
    Variable
    ()
    float64
    Hz
    -14.0
  • beam_position
    scipp
    Variable
    ()
    float64
    deg
    0.0
  • phase
    scipp
    Variable
    ()
    float64
    deg
    -168.0
  • slit_begin
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    -70.0
  • slit_end
    scipp
    Variable
    (cutout: 1)
    float64
    deg
    70.0
  • slit_height
    NoneType
    ()
    None
  • radius
    NoneType
    ()
    None
begin0 end0 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(157.5, unit="m"), name="detector")

params = [
    tof.Chopper.from_diskchopper(ch, name=key) for key, ch in nmx_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/nmx_6_1.png
[5]:
res["detector"].plot()
[5]:
_images/nmx_7_0.svg

Wavelength lookup table#

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

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

wf[SourceBounds] = SourceBounds(
    # The ESS pulse lasts 2.86 ms, but has a long tail, so we take a wider
    # time range to be safe.
    time=(sc.scalar(0.0, unit='ms'), sc.scalar(5.0, unit='ms')),
    # We cap the wavelength range at 12Å to avoid contamination from slow neutrons.
    wavelength=(
        sc.scalar(0.001, unit='angstrom'),
        sc.scalar(12.0, unit='angstrom'),
    ),
)

table = wf.compute(LookupTable[SampleRun, snx.NXdetector])
table.plot() + table.array['distance', -1].plot(errorbars='band')
[6]:
_images/nmx_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/nmx_10_1.png