Introduction to Wavelength Frame Multiplication
Contents
Introduction to Wavelength Frame Multiplication¶
This notebook aims to explain the concept of wavelength frame multiplication (WFM), why is it used, how it works, and what results can be expected from using WFM at a neutron beamline.
Much of the material presented here was inspired by / copied from the paper by Schmakat et al. (2020), which we highly recommend to the reader, for more details on how a WFM chopper system is designed.
[1]:
import numpy as np
import matplotlib.pyplot as plt
plt.ioff() # Turn of auto-showing of figures
import scipp as sc
from scipp import constants
import scippneutron as scn
import ess.wfm as wfm
import ess.choppers as ch
/usr/share/miniconda/envs/test/conda-bld/ess_1642525336443/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/lib/python3.9/site-packages/scipp/plotting/__init__.py:39: UserWarning: The ipympl backend, which is required for interactive plots in Jupyter, was not found. Falling back to a static backend. Use conda install -c conda-forge ipympl to install ipympl.
warnings.warn("The ipympl backend, which is required for "
Note
The source code used to create the figures below can be viewed by downloading this notebook (this is hidden from the documentation pages for the sake of clarity).
The long ESS pulse¶
Instruments at a pulsed neutron source, assuming an idealized rectangular source pulse in time of length \(t_{P}\), have a resolution given by
where \(\lambda\) is the neutron wavelength, \(t\) is time, \(\alpha = m_{\rm n}/h = 2.5278 \times 10^{-4}~{\rm s}\unicode{x212B}^{-1}{\rm m}^{-1}\) is the ratio of the neutron mass and the Planck constant, and \(z_{\rm det}\) is the distance from the source to the detector.
A natural consequence of this is that the wavelength resolution \(\Delta \lambda / \lambda\) becomes finer with increasing wavelength.
This also means that the resolution is poor for a long-pulsed source such as the ESS, compared to that of a short-pulse facility, such as ISIS. A good way to visualize this is using a time-distance diagram, which can represent the paths taken by the neutrons from the source to the detector.
[3]:
Figure1
[3]:
![../../_images/techniques_wfm_introduction-to-wfm_5_0.png](../../_images/techniques_wfm_introduction-to-wfm_5_0.png)
As illustrated in Fig. 1, with a long pulse, two neutrons with very different wavelengths (\(\lambda_{1} < \lambda_{2}\)) can reach the detector at the exact same time, if they originated from a different part of the pulse.
The problem cannot be resolved at the detector. According to the difference between time recorded at the detector and the measured start of the source pulse, both neutrons have the same wavelength. The detector recording system has no way of knowing that this is not the reality or adjusting for this. We instead look at the pulse generation to find ways to better measure the wavelength of our neutrons.
So what is WFM anyway?¶
Within the concept of wavelength frame multiplication (WFM), each source pulse is chopped into a number of sub pulses referred to as wavelength frames, where each wavelength frame \(N\) contains a subsequent part of the spectrum of the source pulse.
The main reason for using the WFM concept is to redefine the burst time \(t_{P} = \Delta t\) as implied by Eq. (1), in order to match the required wavelength resolution of the experiment. A secondary objective, or constraint of the first, is to utilise as much of the source pulse as possible.
[4]:
Figure2
[4]:
![../../_images/techniques_wfm_introduction-to-wfm_8_0.png](../../_images/techniques_wfm_introduction-to-wfm_8_0.png)
A closer look¶
The ESS pulse shape¶
At a real beamline, the pulse shape is not rectangular, but has rising and falling edges, as shown in Fig. 3.
[5]:
Figure3
[5]:
![../../_images/techniques_wfm_introduction-to-wfm_10_0.png](../../_images/techniques_wfm_introduction-to-wfm_10_0.png)
Here we define several important quantities:
The pulse \(t_0\) is defined as the point in time at which the pulse is bright enough for the purposes of the experiment.
\(t_{\rm A}\) is the time when the flux has fallen down to a level below the required brightness.
\(t_{\rm P} = t_{\rm A} - t_{0}\) is the portion of the pulse that is used for the measurements, the analog of the pulse length for the ideal rectangular pulse above.
\(t_{\rm B}\) marks the end of the pulse; i.e. the time when the flux is considered to be effectively zero.
Using a single WFM chopper¶
The effective burst time \(\Delta t\) is defined by a WFM chopper (WFMC), as illustrated in Fig. 3, for the two limiting wavelengths \(\lambda_{\rm min}\) and \(\lambda_{\rm max}\) of a single wavelength frame \(N\).
The wavelength frame is re-limited in a predefined time window by at least one frame overlap chopper (FOC) that inhibits the overlap of neutrons from various frames, as indicated by the dashed lines in Fig. 3. Their wavelength is labeled with \(\lambda_{\rm min}^{'}\) and \(\lambda_{\rm max}^{'}\). The FOC is also removes undesired neutrons with the wrong wavelength that arise from the rising and falling edges at the beginning and at the end of the source pulse. Although their intensity is small, neutrons with an undesired wavelength would lead to an increased background.
[6]:
Figure4
[6]:
![../../_images/techniques_wfm_introduction-to-wfm_12_0.png](../../_images/techniques_wfm_introduction-to-wfm_12_0.png)
The relative spectral resolution \(\Delta \lambda / \lambda\) at the detector position \(z_{\rm det}\) is defined by the burst time \(\Delta t\) and the time-of-flight \(t(\lambda)\) of the neutrons (see eq. (1)). Because \(\Delta t\) is independent of the wavelength for the case of a single WFM chopper disc, \(\Delta \lambda / \lambda\) depends on \(\lambda\), on the distance \(z_{\rm WFM}\) of the WFM chopper from the source, and on the detector position \(z_{\rm det}\) as depicted in Fig. 4.
The WFM chopper acts as a virtual source, reducing the effective burst time \(\Delta t\), while at the same time also reducing the effective time-of-flight to the detector from \(t(\lambda) = \alpha \lambda z_{\rm det}\) to \(t(\lambda) = \alpha \lambda (z_{\rm det} - z_{\rm WFM})\). Note that this assumes a straight line from WFM choppers to the detector. In the case of scattering from a sample, the first branch of the flight path (\(L_{1}\)) would be modified, while the secondary path (\(L_{2}\)) will remain unchanged.
A resolution that depends on \(\lambda\) is not suited for some applications (such as imaging, reflectometry, …) where a constant \(\Delta \lambda / \lambda\) is much more desirable.
Using a pair of optically blind choppers¶
A constant wavelength resolution \(\Delta \lambda / \lambda\) can be enforced by using a pair of optically blind WFM chopper discs, positioned at the positions \(z_{\rm WFM1}\) and \(z_{\rm WFM2} = z_{\rm WFM1} + \Delta z_{\rm WFM}\), as shown in Fig. 5.
In this context, ‘optically blind’ indicates that the choppers have the same opening angles, but the phase of the second chopper is shifted such that the second chopper opens exactly at the time when the first chopper closes. Such a setup introduces a wavelength dependence in the effective burst time \(\Delta t(\lambda) = \alpha \lambda \Delta z_{\rm WFM}\).
The time-of-flight to the detector remains the same as for the single WFM disc setup described above (\(t(\lambda) = \alpha \lambda (z_{\rm det} - z_{\rm WFM})\)) with \(z_{\rm WFM} = \frac{1}{2} (z_{\rm WFM1} + z_{\rm WFM2})\) now representing the center position of the WFM chopper pair from the source.
The resolution for an idealized instrument with infinitesimally small beam cross-section can again be calculated using Eq. (1):
Because the term on the right hand side of Eq. (2) is constant, the resolution becomes independent of the wavelength for an optically blind WFM chopper system.
[7]:
Figure5
[7]:
![../../_images/techniques_wfm_introduction-to-wfm_14_0.png](../../_images/techniques_wfm_introduction-to-wfm_14_0.png)
In a real WFM chopper system, more than one frame can be realized by equipping the chopper with additional windows such that the full band width that fits in the time period between two subsequent source pulses at the detector position is used. This is illustrated in Fig. 6.
The frame overlap chopper defines the bandwidth of the frame \(N\) in order to suppress cross-talk from neighboring wavelength frames, as illustrated in Fig. 6 for two subsequent wavelength frames \(N = 1\) and \(N = 2\). They are designed such that \(\lambda_{N, {\rm max}} = \lambda_{N+1, {\rm min}}\) yield a continuous spectrum at the detector. The concept of wavelength frame multiplication implies that no data can be recorded in the time window between two subsequent wavelength frames.
[8]:
Figure6
[8]:
![../../_images/techniques_wfm_introduction-to-wfm_16_0.png](../../_images/techniques_wfm_introduction-to-wfm_16_0.png)
An additional feature of the WFM concept is the possibility to adjust the wavelength resolution by simply changing the distance \(\Delta z_{\rm WFM}\) between the WFM chopper discs (e.g. by using a motorized linear stage). According to Eq. (2), reducing \(\Delta z_{\rm WFM}\) leads to a finer wavelength resolution at the cost of intensity by effectively reducing the time window in which the neutrons can pass.
A short example¶
We now proceed to illustrate data processing at a WFM beamline in the form of a short example.
Create a beamline¶
We first create a beamline with two WFM choppers and 6 wavelength frames, using the wfm.make_fake_beamline
helper utility. The detector is placed 60 m from the source.
[9]:
coords = wfm.make_fake_beamline(nframes=6)
ds = sc.Dataset(coords=coords)
wfm.plot.time_distance_diagram(ds)
[9]:
![../../_images/techniques_wfm_introduction-to-wfm_18_0.png](../../_images/techniques_wfm_introduction-to-wfm_18_0.png)
The properties of the frames (boundaries in time and wavelength) are computed using the wfm.get_frames
function
[10]:
frames = wfm.get_frames(ds)
frames
[10]:
- frame: 6
- delta_time_max(frame)float64µs284.797, 445.190, ..., 868.881, 992.895
Values:
array([284.79698092, 445.19024854, 595.59362407, 736.6293153 , 868.88077663, 992.89512272]) - delta_time_min(frame)float64µs113.750, 284.797, ..., 736.629, 868.881
Values:
array([113.75028592, 284.79698092, 445.19024854, 595.59362407, 736.6293153 , 868.88077663]) - delta_wavelength_max(frame)float64Å0.021, 0.033, ..., 0.065, 0.074
Values:
array([0.02125786, 0.03322996, 0.04445639, 0.0549836 , 0.06485513, 0.07411183]) - delta_wavelength_min(frame)float64Å0.008, 0.021, ..., 0.055, 0.065
Values:
array([0.00849057, 0.02125786, 0.03322996, 0.04445639, 0.0549836 , 0.06485513]) - time_correction(frame)float64µs4702.574, 7277.777, ..., 1.408e+04, 1.607e+04
Values:
array([ 4702.5737492 , 7277.77676828, 9692.58651973, 11956.99289567, 14080.36358037, 16071.48280373]) - time_max(frame)float64µs3.839e+04, 5.993e+04, ..., 1.168e+05, 1.335e+05
Values:
array([ 38387.72777009, 59933.89005431, 80138.07683293, 99083.87135545, 116849.65099421, 133508.91148592]) - time_min(frame)float64µs1.804e+04, 4.068e+04, ..., 1.005e+05, 1.180e+05
Values:
array([ 18042.954504 , 40678.13380825, 61903.50955722, 81806.8895848 , 100470.61272484, 117971.88944094]) - wavelength_max(frame)float64Å2.504, 3.914, ..., 7.638, 8.729
Values:
array([2.50370343, 3.91375059, 5.23597474, 6.47584583, 7.63849312, 8.72872639]) - wavelength_min(frame)float64Å1.000, 2.504, ..., 6.476, 7.638
Values:
array([1. , 2.50370343, 3.91375059, 5.23597474, 6.47584583, 7.63849312]) - wfm_chopper_mid_point()vector3m[0. 0. 7.]
Values:
array([0., 0., 7.])
Create some neutrons¶
We create 6 neutrons with known wavelengths, one for each frame. We choose the values for the wavelengths based on the limits given in the frames
information above.
[11]:
wavelengths = sc.array(dims=['wavelength'],
values=[1.5, 3.0, 4.5, 6.0, 7.0, 8.25],
unit='angstrom')
We assume that all 6 neutrons originated half-way through the source pulse, and we can thus calculate the times at which they hit the detector.
[12]:
# Neutron mass to Planck constant ratio
alpha = sc.to_unit(constants.m_n / constants.h, 's/m/angstrom')
# Distance between the detector pixel and the source
dz = sc.norm(coords['position'] - coords['source_position'])
# Compute arrival times, in microseconds
arrival_times = sc.to_unit(
alpha * dz * wavelengths,
'us') + coords['source_pulse_t_0'] + (0.5 * coords['source_pulse_length'])
arrival_times
[12]:
- (wavelength: 6)float64µs2.431e+04, 4.706e+04, ..., 1.077e+05, 1.267e+05
Values:
array([ 24310.05718489, 47060.11436978, 69810.17155467, 92560.22873956, 107726.93352949, 126685.3145169 ])
Wrap the neutron counts and the beamline into a DataArray¶
We make a data array that contains the beamline information and a histogram of the neutrons over the time dimension.
[13]:
tmin = sc.min(arrival_times)
tmax = sc.max(arrival_times)
dt = 0.1 * (tmax - tmin)
coords['time'] = sc.linspace(dim='time',
start=(tmin - dt).value,
stop=(tmax + dt).value,
num=2001,
unit=dt.unit)
counts, _ = np.histogram(arrival_times.values, bins=coords['time'].values)
da = sc.DataArray(coords=coords,
data=sc.array(dims=['time'], values=counts, unit='counts'))
da
[13]:
- time: 2000
- chopper_wfm_1()Dataset<scipp.Dataset> Dimensions: Sizes[frame:6, ] Data: cutout_angles_center float64 [rad] (frame) [1.60454, 2.48242, ..., 4.80143, 5.48021] cutout_angles_width float64 [rad] (frame) [0.100208, 0.156644, ..., 0.305723, 0.349358] frequency float64 [Hz] () [56] kind string [dimensionless] () ["wfm"] phase float64 [deg] () [0] position vector3 [m] () [(0, 0, 6.775)]
Values:
<scipp.Dataset> Dimensions: Sizes[frame:6, ] Data: cutout_angles_center float64 [rad] (frame) [1.60454, 2.48242, ..., 4.80143, 5.48021] cutout_angles_width float64 [rad] (frame) [0.100208, 0.156644, ..., 0.305723, 0.349358] frequency float64 [Hz] () [56] kind string [dimensionless] () ["wfm"] phase float64 [deg] () [0] position vector3 [m] () [(0, 0, 6.775)] - chopper_wfm_2()Dataset<scipp.Dataset> Dimensions: Sizes[frame:6, ] Data: cutout_angles_center float64 [rad] (frame) [1.70474, 2.63907, ..., 5.10716, 5.82957] cutout_angles_width float64 [rad] (frame) [0.100208, 0.156644, ..., 0.305723, 0.349358] frequency float64 [Hz] () [56] kind string [dimensionless] () ["wfm"] phase float64 [deg] () [0] position vector3 [m] () [(0, 0, 7.225)]
Values:
<scipp.Dataset> Dimensions: Sizes[frame:6, ] Data: cutout_angles_center float64 [rad] (frame) [1.70474, 2.63907, ..., 5.10716, 5.82957] cutout_angles_width float64 [rad] (frame) [0.100208, 0.156644, ..., 0.305723, 0.349358] frequency float64 [Hz] () [56] kind string [dimensionless] () ["wfm"] phase float64 [deg] () [0] position vector3 [m] () [(0, 0, 7.225)] - position()vector3m[ 0. 0. 60.]
Values:
array([ 0., 0., 60.]) - source_position()vector3m[0. 0. 0.]
Values:
array([0., 0., 0.]) - source_pulse_length()float64µs2860.0
Values:
array(2860.) - source_pulse_t_0()float64µs130.0
Values:
array(130.) - time(time [bin-edge])float64µs1.407e+04, 1.413e+04, ..., 1.369e+05, 1.369e+05
Values:
array([ 14072.53145169, 14133.95660609, 14195.38176049, ..., 136799.9899413 , 136861.4150957 , 136922.8402501 ])
- (time)int64counts0, 0, ..., 0, 0
Values:
array([0, 0, 0, ..., 0, 0, 0])
[14]:
da.plot()
Stitch the frames¶
The time
coordinate in our data represents the time between the source \(t_{0}\) and the time when the neutron hits the detector. However, the WFM choppers are now acting as the new source choppers. This means that the neutron time-of-flight, which will be used to compute the neutron wavelengths, is now defined as the time between when the neutron crossed the WFM choppers and when it hit the detector (see Fig. 5).
Because we only know the time at which the neutron arrived at the detector, not when it left the source, the most sensible value to use as time the neutron passed through the WFM choppers is the mid-point (in time) between the WFM chopper openings, in each frame. This is represented by \(t_{\rm WFM}(N)\) in Fig. 5.
By using the start and end detector arrival time for each frame contained in the frames
Dataset, we extract all the neutrons in a given frame \(N\) and subtract \(t_{\rm WFM}(N)\) (also found in frames
) from the time coordinate in that frame.
Finally, we then merge (or rebin) the neutrons from all the frames onto a common time-of-flight axis.
All this is performed in a single operation using the wfm.stitch
function:
[15]:
stitched = wfm.stitch(frames=frames, data=da, dim='time', bins=2001)
stitched.plot()
The resulting coordinate is now time-of-flight (tof
), and we can use scippneutron
to convert the time-of-flight to wavelength.
[16]:
from scippneutron.tof.conversions import beamline, elastic
graph = {**beamline(scatter=False), **elastic("tof")}
wav = stitched.transform_coords("wavelength", graph=graph)
wav
[16]:
- wavelength: 2001
- chopper_wfm_1()Dataset<scipp.Dataset> Dimensions: Sizes[frame:6, ] Data: cutout_angles_center float64 [rad] (frame) [1.60454, 2.48242, ..., 4.80143, 5.48021] cutout_angles_width float64 [rad] (frame) [0.100208, 0.156644, ..., 0.305723, 0.349358] frequency float64 [Hz] () [56] kind string [dimensionless] () ["wfm"] phase float64 [deg] () [0] position vector3 [m] () [(0, 0, 6.775)]
Values:
<scipp.Dataset> Dimensions: Sizes[frame:6, ] Data: cutout_angles_center float64 [rad] (frame) [1.60454, 2.48242, ..., 4.80143, 5.48021] cutout_angles_width float64 [rad] (frame) [0.100208, 0.156644, ..., 0.305723, 0.349358] frequency float64 [Hz] () [56] kind string [dimensionless] () ["wfm"] phase float64 [deg] () [0] position vector3 [m] () [(0, 0, 6.775)] - chopper_wfm_2()Dataset<scipp.Dataset> Dimensions: Sizes[frame:6, ] Data: cutout_angles_center float64 [rad] (frame) [1.70474, 2.63907, ..., 5.10716, 5.82957] cutout_angles_width float64 [rad] (frame) [0.100208, 0.156644, ..., 0.305723, 0.349358] frequency float64 [Hz] () [56] kind string [dimensionless] () ["wfm"] phase float64 [deg] () [0] position vector3 [m] () [(0, 0, 7.225)]
Values:
<scipp.Dataset> Dimensions: Sizes[frame:6, ] Data: cutout_angles_center float64 [rad] (frame) [1.70474, 2.63907, ..., 5.10716, 5.82957] cutout_angles_width float64 [rad] (frame) [0.100208, 0.156644, ..., 0.305723, 0.349358] frequency float64 [Hz] () [56] kind string [dimensionless] () ["wfm"] phase float64 [deg] () [0] position vector3 [m] () [(0, 0, 7.225)] - source_pulse_length()float64µs2860.0
Values:
array(2860.) - source_pulse_t_0()float64µs130.0
Values:
array(130.) - wavelength(wavelength [bin-edge])float64Å0.996, 1.000, ..., 8.762, 8.766
Values:
array([0.99575472, 0.99963779, 1.00352086, ..., 8.75801616, 8.76189923, 8.7657823 ])
- (wavelength)float64counts0.0, 0.0, ..., 0.0, 0.0
Values:
array([0., 0., 0., ..., 0., 0., 0.])
- Ltotal()float64m53.0
Values:
array(53.) - position()vector3m[ 0. 0. 60.]
Values:
array([ 0., 0., 60.]) - source_position()vector3m[0. 0. 7.]
Values:
array([0., 0., 7.]) - tof(wavelength [bin-edge])float64µs1.334e+04, 1.339e+04, ..., 1.174e+05, 1.174e+05
Values:
array([ 13340.38075481, 13392.40326751, 13444.42578022, ..., 117333.38365677, 117385.40616948, 117437.42868218])
[17]:
wav.plot()
Zooming in on the first spike, we notice that something is not quite right: the original wavelength was 1.5 Å but on the figure below is closer to 1.46 Å.
[18]:
wav["wavelength", (1.2*sc.units.angstrom):(1.7*sc.units.angstrom)].plot()
Now the WFM method guarantees a constant \(\Delta\lambda / \lambda\), and so it is not surprising to see the final reduced wavelength not exactly matching the original. The question is: is the error within \(\Delta\lambda / \lambda\)?
[19]:
# Distance between WFM choppers
dz_wfm = sc.norm(ds.coords["chopper_wfm_2"].value["position"].data - ds.coords["chopper_wfm_1"].value["position"].data)
# Delta_lambda / lambda
dlambda_over_lambda = dz_wfm / sc.norm(coords['position'] -
frames['wfm_chopper_mid_point'].data)
(1.5*sc.units.angstrom) * dlambda_over_lambda
[19]:
- ()float64Å0.012735849056603753
Values:
array(0.01273585)
At 1.5 Å, the resolution is 0.0127 Å, which is smaller than the offset we observe above. In fact, we can perform a quick check using Scipp’s label-based slicing, to verify that the sum of the counts in a region \(\Delta\lambda\) wide around the original wavelength should be equal to 1:
[20]:
for i in range(len(wavelengths)):
lam = wavelengths["wavelength", i]
half_dlam = 0.5 * dlambda_over_lambda * lam
print("Lambda:", lam, ", count in range:",
sc.sum(wav['wavelength', lam - half_dlam:lam + half_dlam]).value)
Lambda: <scipp.Variable> () float64 [Å] [1.5] , count in range: 0.0
Lambda: <scipp.Variable> () float64 [Å] [3] , count in range: 0.0
Lambda: <scipp.Variable> () float64 [Å] [4.5] , count in range: 1.0
Lambda: <scipp.Variable> () float64 [Å] [6] , count in range: 1.0
Lambda: <scipp.Variable> () float64 [Å] [7] , count in range: 1.0
Lambda: <scipp.Variable> () float64 [Å] [8.25] , count in range: 1.0
This reveals that the reduced wavelengths for the first two neutrons do not agree within the required precision. We go back to our time-distance diagram and look at the paths taken by our 6 neutrons (plotted in red).
[21]:
fig6 = wfm.plot.time_distance_diagram(da)
ax6 = fig6.get_axes()[0]
for i in range(len(wavelengths)):
ax6.plot([(coords['source_pulse_t_0'] + (0.5 * coords['source_pulse_length'])).value,
arrival_times['wavelength', i].value],
[0.0, sc.norm(coords['position']).value], color='r')
fig6
[21]:
![../../_images/techniques_wfm_introduction-to-wfm_40_0.png](../../_images/techniques_wfm_introduction-to-wfm_40_0.png)
Taking a closer look at the WFM choppers, we observe that the numbers we picked for the first two neutrons actually lead to unphysical paths: they do not make it through the chopper openings!
[22]:
del ax6.texts[3:]
ax6.set_xlim(-1.0e3, 2.0e4)
ax6.set_ylim(-1.5, 10.0)
fig6.canvas.draw_idle()
fig6
/tmp/ipykernel_2929/372091343.py:1: MatplotlibDeprecationWarning:
The modification of the Axes.texts property was deprecated in Matplotlib 3.5 and will be removed two minor releases later. Use Artist.remove() instead.
del ax6.texts[3:]
[22]:
![../../_images/techniques_wfm_introduction-to-wfm_42_1.png](../../_images/techniques_wfm_introduction-to-wfm_42_1.png)
So we modify our values so that neutrons 1 and 2 make it through:
[23]:
wavelengths = sc.array(dims=['wavelength'],
values=[1.75, 3.2, 4.5, 6.0, 7.0, 8.25],
unit='angstrom')
arrival_times = sc.to_unit(
alpha * dz * wavelengths,
'us') + coords['source_pulse_t_0'] + (0.5 * coords['source_pulse_length'])
[24]:
fig7 = wfm.plot.time_distance_diagram(da)
ax7 = fig7.get_axes()[0]
for i in range(len(wavelengths)):
ax7.plot([(coords['source_pulse_t_0'] + (0.5 * coords['source_pulse_length'])).value,
arrival_times['wavelength', i].value],
[0.0, sc.norm(coords['position']).value], color='r')
del ax7.texts[3:]
ax7.set_xlim(-1.0e3, 2.0e4)
ax7.set_ylim(-1.5, 10.0)
fig7
/tmp/ipykernel_2929/2252025501.py:8: MatplotlibDeprecationWarning:
The modification of the Axes.texts property was deprecated in Matplotlib 3.5 and will be removed two minor releases later. Use Artist.remove() instead.
del ax7.texts[3:]
[24]:
![../../_images/techniques_wfm_introduction-to-wfm_45_1.png](../../_images/techniques_wfm_introduction-to-wfm_45_1.png)
And repeat the stitching process:
[25]:
tmin = sc.min(arrival_times)
tmax = sc.max(arrival_times)
dt = 0.1 * (tmax - tmin)
coords['time'] = sc.linspace(dim='time',
start=(tmin - dt).value,
stop=(tmax + dt).value,
num=2001,
unit=dt.unit)
counts, _ = np.histogram(arrival_times.values, bins=coords['time'].values)
da = sc.DataArray(coords=coords,
data=sc.array(dims=['time'], values=counts, unit='counts'))
stitched = wfm.stitch(frames=frames, data=da, dim='time', bins=2001)
wav = stitched.transform_coords("wavelength", graph=graph)
[26]:
wav["wavelength", (1.55*sc.units.angstrom):(1.95*sc.units.angstrom)].plot()
This time, the peak is much closer to 1.75 Å, and we can make sure the sum within the \(\Delta\lambda\) range is 1 for all 6 neutrons:
[27]:
for i in range(len(wavelengths)):
lam = wavelengths["wavelength", i]
half_dlam = 0.5 * dlambda_over_lambda * lam
print("Lambda:", lam, ", count in range:",
sc.sum(wav['wavelength', lam - half_dlam:lam + half_dlam]).value)
Lambda: <scipp.Variable> () float64 [Å] [1.75] , count in range: 1.0
Lambda: <scipp.Variable> () float64 [Å] [3.2] , count in range: 1.0
Lambda: <scipp.Variable> () float64 [Å] [4.5] , count in range: 1.0
Lambda: <scipp.Variable> () float64 [Å] [6] , count in range: 1.0
Lambda: <scipp.Variable> () float64 [Å] [7] , count in range: 1.0
Lambda: <scipp.Variable> () float64 [Å] [8.25] , count in range: 1.0