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_positionscippVariable()vector3m[ 0. 0. 28.4]
- frequencyscippVariable()float64Hz-14.0
- beam_positionscippVariable()float64deg0.0
- phasescippVariable()float64deg-111.2
- slit_beginscippVariable(cutout: 1)float64deg-38.5
- slit_endscippVariable(cutout: 1)float64deg38.5
- slit_heightNoneType()None
- radiusNoneType()None
chopper2a
- axle_positionscippVariable()vector3m[ 0. 0. 50.9774]
- frequencyscippVariable()float64Hz-14.0
- beam_positionscippVariable()float64deg0.0
- phasescippVariable()float64deg-194.1
- slit_beginscippVariable(cutout: 1)float64deg-70.0
- slit_endscippVariable(cutout: 1)float64deg70.0
- slit_heightNoneType()None
- radiusNoneType()None
chopper2b
- axle_positionscippVariable()vector3m[ 0. 0. 51.0024]
- frequencyscippVariable()float64Hz-14.0
- beam_positionscippVariable()float64deg0.0
- phasescippVariable()float64deg-168.0
- slit_beginscippVariable(cutout: 1)float64deg-70.0
- slit_endscippVariable(cutout: 1)float64deg70.0
- slit_heightNoneType()None
- radiusNoneType()None
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>)
[5]:
res["detector"].plot()
[5]:
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]:
[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='Å'>)