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_positionscippVariable()vector3m[0. 0. 6.45]
- frequencyscippVariable()float64Hz168.0
- beam_positionscippVariable()float64deg0.0
- phasescippVariable()float64deg299.983856971683
- slit_beginscippVariable(cutout: 1)float64deg0.0
- slit_endscippVariable(cutout: 1)float64deg144.0
- slit_heightNoneType()None
- radiusNoneType()None
PSC2
- axle_positionscippVariable()vector3m[0. 0. 6.85]
- frequencyscippVariable()float64Hz-168.0
- beam_positionscippVariable()float64deg0.0
- phasescippVariable()float64deg-299.983856971683
- slit_beginscippVariable(cutout: 1)float64deg0.0
- slit_endscippVariable(cutout: 1)float64deg144.0
- slit_heightNoneType()None
- radiusNoneType()None
FC1A
- axle_positionscippVariable()vector3m[0. 0. 8.283]
- frequencyscippVariable()float64Hz-14.0
- beam_positionscippVariable()float64deg0.0
- phasescippVariable()float64deg12.63240606395426
- slit_beginscippVariable(cutout: 1)float64deg0.0
- slit_endscippVariable(cutout: 1)float64deg72.0
- slit_heightNoneType()None
- radiusNoneType()None
FC2A
- axle_positionscippVariable()vector3m[ 0. 0. 79.975]
- frequencyscippVariable()float64Hz-14.0
- beam_positionscippVariable()float64deg0.0
- phasescippVariable()float64deg-133.67285314925246
- slit_beginscippVariable(cutout: 1)float64deg0.0
- slit_endscippVariable(cutout: 1)float64deg175.0
- slit_heightNoneType()None
- radiusNoneType()None
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>)
[5]:
res["detector"].plot()
[5]:
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]:
[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='Å'>)
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_positionscippVariable()vector3m[0. 0. 6.45]
- frequencyscippVariable()float64Hz168.0
- beam_positionscippVariable()float64deg0.0
- phasescippVariable()float64deg296.77336889692083
- slit_beginscippVariable(cutout: 1)float64deg0.0
- slit_endscippVariable(cutout: 1)float64deg144.0
- slit_heightNoneType()None
- radiusNoneType()None
PSC2
- axle_positionscippVariable()vector3m[0. 0. 6.65]
- frequencyscippVariable()float64Hz-168.0
- beam_positionscippVariable()float64deg0.0
- phasescippVariable()float64deg-296.77336889692083
- slit_beginscippVariable(cutout: 1)float64deg0.0
- slit_endscippVariable(cutout: 1)float64deg144.0
- slit_heightNoneType()None
- radiusNoneType()None
FC1A
- axle_positionscippVariable()vector3m[0. 0. 8.283]
- frequencyscippVariable()float64Hz-14.0
- beam_positionscippVariable()float64deg0.0
- phasescippVariable()float64deg12.63240606395426
- slit_beginscippVariable(cutout: 1)float64deg0.0
- slit_endscippVariable(cutout: 1)float64deg72.0
- slit_heightNoneType()None
- radiusNoneType()None
FC2A
- axle_positionscippVariable()vector3m[ 0. 0. 79.975]
- frequencyscippVariable()float64Hz-14.0
- beam_positionscippVariable()float64deg0.0
- phasescippVariable()float64deg-133.67285314925246
- slit_beginscippVariable(cutout: 1)float64deg0.0
- slit_endscippVariable(cutout: 1)float64deg175.0
- slit_heightNoneType()None
- radiusNoneType()None
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>)
[11]:
res["detector"].plot()
[11]:
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]:
[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='Å'>)
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_positionscippVariable()vector3m[0. 0. 8.283]
- frequencyscippVariable()float64Hz-14.0
- beam_positionscippVariable()float64deg0.0
- phasescippVariable()float64deg21.63240606395426
- slit_beginscippVariable(cutout: 1)float64deg0.0
- slit_endscippVariable(cutout: 1)float64deg72.0
- slit_heightNoneType()None
- radiusNoneType()None
MCA
- axle_positionscippVariable()vector3m[0. 0. 9.3]
- frequencyscippVariable()float64Hz-70.0
- beam_positionscippVariable()float64deg0.0
- phasescippVariable()float64deg-157.94241289703336
- slit_beginscippVariable(cutout: 8)float64deg0.0, 45.0, ..., 270.0, 315.0
- slit_endscippVariable(cutout: 8)float64deg5.0, 50.0, ..., 275.0, 320.0
- slit_heightNoneType()None
- radiusNoneType()None
FC2A
- axle_positionscippVariable()vector3m[ 0. 0. 79.975]
- frequencyscippVariable()float64Hz-14.0
- beam_positionscippVariable()float64deg0.0
- phasescippVariable()float64deg-133.67285314925246
- slit_beginscippVariable(cutout: 1)float64deg0.0
- slit_endscippVariable(cutout: 1)float64deg175.0
- slit_heightNoneType()None
- radiusNoneType()None
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>)
[17]:
res["detector"].plot()
[17]:
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]:
[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='Å'>)
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_positionscippVariable()vector3m[0. 0. 8.283]
- frequencyscippVariable()float64Hz-14.0
- beam_positionscippVariable()float64deg0.0
- phasescippVariable()float64deg21.63240606395426
- slit_beginscippVariable(cutout: 1)float64deg0.0
- slit_endscippVariable(cutout: 1)float64deg72.0
- slit_heightNoneType()None
- radiusNoneType()None
MCB
- axle_positionscippVariable()vector3m[0. 0. 9.35]
- frequencyscippVariable()float64Hz-140.0
- beam_positionscippVariable()float64deg0.0
- phasescippVariable()float64deg-319.72252915855086
- slit_beginscippVariable(cutout: 16)float64deg0.0, 22.5, ..., 315.0, 337.5
- slit_endscippVariable(cutout: 16)float64deg5.0, 27.5, ..., 320.0, 342.5
- slit_heightNoneType()None
- radiusNoneType()None
FC2A
- axle_positionscippVariable()vector3m[ 0. 0. 79.975]
- frequencyscippVariable()float64Hz-14.0
- beam_positionscippVariable()float64deg0.0
- phasescippVariable()float64deg-133.67285314925246
- slit_beginscippVariable(cutout: 1)float64deg0.0
- slit_endscippVariable(cutout: 1)float64deg175.0
- slit_heightNoneType()None
- radiusNoneType()None
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>)
[23]:
res["detector"].plot()
[23]:
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]:
[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='Å'>)
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_positionscippVariable()vector3m[0. 0. 8.283]
- frequencyscippVariable()float64Hz-14.0
- beam_positionscippVariable()float64deg0.0
- phasescippVariable()float64deg21.63240606395426
- slit_beginscippVariable(cutout: 1)float64deg0.0
- slit_endscippVariable(cutout: 1)float64deg72.0
- slit_heightNoneType()None
- radiusNoneType()None
MCB
- axle_positionscippVariable()vector3m[0. 0. 9.35]
- frequencyscippVariable()float64Hz-280.0
- beam_positionscippVariable()float64deg0.0
- phasescippVariable()float64deg-641.9450583171017
- slit_beginscippVariable(cutout: 16)float64deg0.0, 22.5, ..., 315.0, 337.5
- slit_endscippVariable(cutout: 16)float64deg5.0, 27.5, ..., 320.0, 342.5
- slit_heightNoneType()None
- radiusNoneType()None
FC2A
- axle_positionscippVariable()vector3m[ 0. 0. 79.975]
- frequencyscippVariable()float64Hz-14.0
- beam_positionscippVariable()float64deg0.0
- phasescippVariable()float64deg-133.67285314925246
- slit_beginscippVariable(cutout: 1)float64deg0.0
- slit_endscippVariable(cutout: 1)float64deg175.0
- slit_heightNoneType()None
- radiusNoneType()None
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>)
[29]:
res["detector"].plot()
[29]:
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]:
[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='Å'>)