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 | None) – 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 (Variable | None, default: None) – Minimum neutron wavelength.

  • wmax (Variable | None, default: None) – Maximum neutron wavelength.

  • seed (int | None, 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_json()

Return the source as a JSON-serializable dictionary.

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.

Attributes

data

The data array containing the neutrons in the pulse.

facility

The name of the facility used to create the source.

frequency

The frequency of the pulse.

neutrons

The number of neutrons per pulse.

pulses

The number of pulses.

as_json()[source]#

Return the source as a JSON-serializable dictionary.

Return type:

dict

property data: DataArray#

The data array containing the neutrons in the pulse.

property facility: str | None#

The name of the facility used to create the source.

property frequency: Variable#

The frequency of the pulse.

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 (Variable | None, default: None) – Frequency of the pulse.

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

  • seed (int | None, 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 (Variable | None, default: None) – Frequency of the pulse.

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

property neutrons: int#

The number of neutrons per pulse.

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

property pulses: int#

The number of pulses.