tof.Source#

class tof.Source(facility, neutrons=1000000, pulses=1, frequency=None, wmin=None, wmax=None, tmin=None, tmax=None, seed=None, optimize_for=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. Currently, the following facilities are supported:

    • ’ess’: the standard ESS source profile, applicable for all ESS instruments

    • ’ess-odin’: a source specific to the ESS Odin instrument, sampled at the location where cold and thermal neutrons are combined (~2.35m away from the surface of the moderator)

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

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

  • wmin (Variable | None, default: None) – Minimum neutron wavelength.

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

  • tmin (Variable | None, default: None) – Minimum neutron birth time.

  • tmax (Variable | None, default: None) – Maximum neutron birth time.

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

  • optimize_for (list[Chopper] | None, default: None) –

    List of choppers to optimize the source for. A chopper acceptance diagram will be overlaid on the source distribution, and samples will be taken only from the regions where the chopper cascade is accepting neutrons.

    Added in version 26.4.0.

__init__(facility, neutrons=1000000, pulses=1, frequency=None, wmin=None, wmax=None, tmin=None, tmax=None, seed=None, optimize_for=None)[source]#

Methods

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

as_json()

Return the source as a JSON-serializable dictionary.

as_readonly()

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

Create source pulses from time and wavelength probability distributions.

from_json(params)

Create a source from a JSON-serializable dictionary.

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.

distance

The position of the source along the beamline.

facility

The name of the facility used to create the source.

frequency

The frequency of the pulse.

neutrons

The number of neutrons per pulse.

period

The period of the pulse.

pulses

The number of pulses.

seed

The seed for the random number generator.

as_json()[source]#

Return the source as a JSON-serializable dictionary.

Added in version 25.11.0.

Return type:

dict

property data: DataArray#

The data array containing the neutrons in the pulse.

property distance: Variable#

The position of the source along the beamline.

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=None, p_time=None, p_wav=None, neutrons=1000000, pulses=1, frequency=None, seed=None, distance=None, wmin=None, wmax=None, tmin=None, tmax=None, optimize_for=None)[source]#

Create source pulses from time and 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. This can either be a single 2D distribution, or separate 1D distributions for time and wavelength. Note that in this case, the time and wavelength distributions are considered 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 (DataArray | None, default: None) –

    2D probability distribution for a single pulse.

    Added in version 25.12.0.

  • p_time (DataArray | None, default: None) – Time probability distribution (1D) for a single pulse.

  • p_wav (DataArray | None, default: None) – Wavelength probability distribution (1D) for a single pulse.

  • 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.

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

  • distance (Variable | None, default: None) – Position of the source along the beamline.

  • wmin (Variable | None, default: None) – Minimum wavelength.

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

  • tmin (Variable | None, default: None) – Minimum birth time.

  • tmax (Variable | None, default: None) – Maximum birth time.

  • optimize_for (list[Chopper] | None, default: None) –

    List of choppers to optimize the source for. A chopper acceptance diagram will be overlaid on the source distribution, and samples will be taken only from the regions where the chopper cascade is accepting neutrons.

    Added in version 26.4.0.

classmethod from_json(params)[source]#

Create a source from a JSON-serializable dictionary. Currently, only sources from facilities are supported when loading from JSON.

The dictionary should have the following format:

{
    "type": "source",
    "facility": "ess",
    "neutrons": 1000000,
    "pulses": 1,
    "seed": 42
}
Return type:

Source

classmethod from_neutrons(birth_times, wavelengths, frequency=None, pulses=1, distance=None)[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.

  • distance (Variable | None, default: None) – Position of the source along the beamline.

property neutrons: int#

The number of neutrons per pulse.

property period: Variable#

The period of the 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.

property seed: int | None#

The seed for the random number generator.