BIFROST#
[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 = {
"bandwidth_chopper_1": {
"frequency": {"value": 14.0, "unit": "Hz"},
"open": {"value": [-80.5], "unit": "deg"},
"close": {"value": [80.5], "unit": "deg"},
"distance": {"value": -84.01844459620825, "unit": "m"},
"phase": {"value": 341.5771484375, "unit": "deg"},
"type": "chopper",
"direction": "anticlockwise",
"name": "bandwidth_chopper_1",
},
"bandwidth_chopper_2": {
"frequency": {"value": 14.0, "unit": "Hz"},
"open": {"value": [-80.5], "unit": "deg"},
"close": {"value": [80.5], "unit": "deg"},
"distance": {"value": -83.98344464678199, "unit": "m"},
"phase": {"value": 341.5771484375, "unit": "deg"},
"type": "chopper",
"direction": "clockwise",
"name": "bandwidth_chopper_2",
},
"frame_overlap_chopper_1": {
"frequency": {"value": 14.0, "unit": "Hz"},
"open": {"value": [-19.13], "unit": "deg"},
"close": {"value": [19.13], "unit": "deg"},
"distance": {"value": -153.47749555228876, "unit": "m"},
"phase": {"value": 44.67131423950195, "unit": "deg"},
"type": "chopper",
"direction": "anticlockwise",
"name": "frame_overlap_chopper_1",
},
"frame_overlap_chopper_2": {
"frequency": {"value": 14.0, "unit": "Hz"},
"open": {"value": [-26.005], "unit": "deg"},
"close": {"value": [26.005], "unit": "deg"},
"distance": {"value": -147.02860013489428, "unit": "m"},
"phase": {"value": 72.2078628540039, "unit": "deg"},
"type": "chopper",
"direction": "anticlockwise",
"name": "frame_overlap_chopper_2",
},
"pulse_shaping_chopper_1": {
"frequency": {"value": 196.0, "unit": "Hz"},
"open": {"value": [-85.0], "unit": "deg"},
"close": {"value": [85.0], "unit": "deg"},
"distance": {"value": -155.67417487389721, "unit": "m"},
"phase": {"value": 413.00921630859375, "unit": "deg"},
"type": "chopper",
"direction": "anticlockwise",
"name": "pulse_shaping_chopper_1",
},
"pulse_shaping_chopper_2": {
"frequency": {"value": 196.0, "unit": "Hz"},
"open": {"value": [-85.0], "unit": "deg"},
"close": {"value": [85.0], "unit": "deg"},
"distance": {"value": -155.62517721431513, "unit": "m"},
"phase": {"value": 575.9532470703125, "unit": "deg"},
"type": "chopper",
"direction": "anticlockwise",
"name": "pulse_shaping_chopper_2",
},
}
[3]:
bifrost_choppers = {}
for key, ch in choppers.items():
bifrost_choppers[key] = tof.Chopper.from_json(name=key, params=ch).to_diskchopper()
for key, ch in bifrost_choppers.items():
print(key)
display(ch)
bandwidth_chopper_1
- axle_positionscippVariable()vector3m[ 0. 0. -84.0184446]
- frequencyscippVariable()float64Hz14.0
- beam_positionscippVariable()float64deg0.0
- phasescippVariable()float64deg341.5771484375
- slit_beginscippVariable(cutout: 1)float64deg-80.5
- slit_endscippVariable(cutout: 1)float64deg80.5
- slit_heightNoneType()None
- radiusNoneType()None
bandwidth_chopper_2
- axle_positionscippVariable()vector3m[ 0. 0. -83.98344465]
- frequencyscippVariable()float64Hz-14.0
- beam_positionscippVariable()float64deg0.0
- phasescippVariable()float64deg-341.5771484375
- slit_beginscippVariable(cutout: 1)float64deg-80.5
- slit_endscippVariable(cutout: 1)float64deg80.5
- slit_heightNoneType()None
- radiusNoneType()None
frame_overlap_chopper_1
- axle_positionscippVariable()vector3m[ 0. 0. -153.47749555]
- frequencyscippVariable()float64Hz14.0
- beam_positionscippVariable()float64deg0.0
- phasescippVariable()float64deg44.67131423950195
- slit_beginscippVariable(cutout: 1)float64deg-19.13
- slit_endscippVariable(cutout: 1)float64deg19.13
- slit_heightNoneType()None
- radiusNoneType()None
frame_overlap_chopper_2
- axle_positionscippVariable()vector3m[ 0. 0. -147.02860013]
- frequencyscippVariable()float64Hz14.0
- beam_positionscippVariable()float64deg0.0
- phasescippVariable()float64deg72.2078628540039
- slit_beginscippVariable(cutout: 1)float64deg-26.005
- slit_endscippVariable(cutout: 1)float64deg26.005
- slit_heightNoneType()None
- radiusNoneType()None
pulse_shaping_chopper_1
- axle_positionscippVariable()vector3m[ 0. 0. -155.67417487]
- frequencyscippVariable()float64Hz196.0
- beam_positionscippVariable()float64deg0.0
- phasescippVariable()float64deg413.00921630859375
- slit_beginscippVariable(cutout: 1)float64deg-85.0
- slit_endscippVariable(cutout: 1)float64deg85.0
- slit_heightNoneType()None
- radiusNoneType()None
pulse_shaping_chopper_2
- axle_positionscippVariable()vector3m[ 0. 0. -155.62517721]
- frequencyscippVariable()float64Hz196.0
- beam_positionscippVariable()float64deg0.0
- phasescippVariable()float64deg575.9532470703125
- slit_beginscippVariable(cutout: 1)float64deg-85.0
- slit_endscippVariable(cutout: 1)float64deg85.0
- slit_heightNoneType()None
- radiusNoneType()None
Tof model#
[4]:
source_position = sc.vector([0, 0, -1.61998772e02], unit="m")
source = tof.Source(facility="ess", neutrons=1_000_000, pulses=2)
source._distance = source_position.fields.z
detector = tof.Detector(distance=sc.scalar(0.0, unit="m"), name="detector")
params = [
tof.Chopper.from_diskchopper(ch, name=key) for key, ch in bifrost_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]] = bifrost_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]:
[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='Å'>)