import numpy as np
import matplotlib.pyplot as plt
Recovering ToF¶
Time-of-flight (ToF) is an important concept in neutron scattering, enabling faster and more flexible measurements. However, in order to complete a ToF measurement, it is important that we keep a track of the pulses from the neutron source. In this exercise, we will look at recovering the ToF from a series of neutron pulses, where the pulse start points have been lost. Note, this is a slightly contrived exercise, but hopefully it will help with your understanding of clustering methods.
The file tof.txt
contains a numpy array consisting of absolute ToF and θ.
Let’s have a look at this data.
tof, theta = np.loadtxt('tof.txt')
plt.plot(tof, theta, 'o')
plt.xlabel(r'Absolute ToF/$\mu s$')
plt.ylabel(r'$\theta$/rad')
plt.show()
Exercise¶
In this exercise, you should use k-means clustering to identify the different pulses from this data where the pulse data has been lost. You will need to try and determine how many pulses there are in the data. Once you have the cluster centers, you can normalise the data with respect to these (is you are stuggling with this there is some help here, but try and work it out with this first!), note we should also offset to account for the position of the first centre.
Once you have normalised the data, it should look something like this.