tof.Source#

class tof.Source(facility, neutrons=1000000, pulses=1, sampling=1000, wmin=None, wmax=None, seed=None)[source]#

A class that represents a source of neutrons. It is defined by the number of neutrons, a wavelength range, and a time range. The default way of creating a pulse is to supply the name of a facility (e.g. 'ess') and the number of neutrons. This will create a pulse with the default time and wavelength ranges for that facility.

Parameters:
  • facility (str) – Name of a pre-defined pulse shape from a neutron facility.

  • neutrons (int, default: 1000000) – Number of neutrons per pulse.

  • pulses (int, default: 1) – Number of pulses.

  • sampling (int, default: 1000) – Number of points used to interpolate the probability distributions.

  • wmin (Optional[Variable], default: None) – Minimum neutron wavelength.

  • wmax (Optional[Variable], default: None) – Maximum neutron wavelength.

  • seed (Optional[int], default: None) – Seed for the random number generator.

__init__(facility, neutrons=1000000, pulses=1, sampling=1000, wmin=None, wmax=None, seed=None)[source]#

Methods

__init__(facility[, neutrons, pulses, ...])

as_readonly()

from_distribution(p_time, p_wav[, neutrons, ...])

Create source pulses from time a wavelength probability distributions.

from_neutrons(birth_times, wavelengths[, ...])

Create source pulses from a list of neutrons.

plot([bins])

Plot the pulses of the source.

classmethod from_distribution(p_time, p_wav, neutrons=1000000, pulses=1, frequency=None, sampling=1000, seed=None)[source]#

Create source pulses from time a wavelength probability distributions. The distributions should be supplied as DataArrays where the coordinates are the values of the distribution, and the values are the probability. Note that the time and wavelength distributions are independent. A neutron with a randomly selected birth time from p_time can adopt any wavelength in p_wav (in other words, the two distributions are simply broadcast into a square 2D parameter space).

Parameters:
  • p_time (DataArray) – Time probability distribution.

  • p_wav (DataArray) – Wavelength probability distribution.

  • neutrons (int, default: 1000000) – Number of neutrons in the pulse.

  • pulses (int, default: 1) – Number of pulses.

  • frequency (Optional[Variable], default: None) – Frequency of the pulse.

  • sampling (int, default: 1000) – Number of points used to interpolate the probability distributions.

  • seed (Optional[int], default: None) – Seed for the random number generator.

classmethod from_neutrons(birth_times, wavelengths, frequency=None, pulses=1)[source]#

Create source pulses from a list of neutrons. Both birth times and wavelengths should be one-dimensional and have the same length. They represent the neutrons inside one pulse. If pulses is greater than one, the neutrons will be repeated pulses times.

Parameters:
  • birth_times (Variable) – Birth times of neutrons in the pulse.

  • wavelengths (Variable) – Wavelengths of neutrons in the pulse.

  • frequency (Optional[Variable], default: None) – Frequency of the pulse.

  • pulses (int, default: 1) – Number of pulses.

plot(bins=300)[source]#

Plot the pulses of the source.

Parameters:

bins (int, default: 300) – Number of bins to use for histogramming the neutrons.

Return type:

tuple