source — X-ray sources#

This module contains all the facilities for the description of simple X-ray sources, for both the morphological and spectral part. At the very basic level, a Source object is the datum of an energy spectrum and a beam description, and has the primary purpose of generating lists of X-ray basic properties (time, energy and position in the horizontal plane) than can be folded into an actual detector simulation.

spectrum = LineForest('Cu', 'K')
beam = GaussianBeam(sigma=0.1)
source = Source(spectrum, beam, rate=10.)
timestamp, energy, x, y = source.rvs()

Note

At this point a Source is a very simple object describing a parallel beam of photons traveling along the z axis, that is, orthogonally to the detector plane—the latter will be always assumed to lie in the x-y plane—with no concept, e.g., of beam divergence. This is an area where we might want to add functionalities in the future.

Morphology#

The morphological part of the source description is encapsulated in a series of subclasses of the (purely virtual) BeamBase class. More specifically:

Spectrum#

Likewise, the source spectrum is encapsulated in subclasses of the (virtual) SpectrumBase class and, particularly, LineForest.

Module documentation#

X-ray source description.

class hexsample.source.BeamBase(x0: float = 0.0, y0: float = 0.0)[source]#

Base class describing the morphology of a X-ray beam.

Arguments#

x0float

The x-coordinate of the beam centroid in cm.

y0float

The y-coordinate of the beam centroid in cm.

x0: float = 0.0#
y0: float = 0.0#
rvs(size: int = 1) Tuple[ndarray, ndarray][source]#

Do-nothing hook to generate random positions in the x-y plane.

Arguments#

sizeint

The number of X-ray photon positions to be generated.

Returns#

x, y2-element tuple of np.ndarray of shape size

The photon positions on the x-y plane.

class hexsample.source.PointBeam(x0: float = 0.0, y0: float = 0.0)[source]#

Point-like X-ray beam.

Arguments#

x0float

The x-coordinate of the beam centroid in cm.

y0float

The y-coordinate of the beam centroid in cm.

rvs(size: int = 1) Tuple[ndarray, ndarray][source]#

Overloaded method.

Arguments#

sizeint

The number of X-ray photon positions to be generated.

Returns#

x, y2-element tuple of np.ndarray of shape size

The photon positions on the x-y plane.

class hexsample.source.DiskBeam(x0: float = 0.0, y0: float = 0.0, radius: float = 0.1)[source]#

Uniform disk X-ray beam.

Arguments#

x0float

The x-coordinate of the beam centroid in cm.

y0float

The y-coordinate of the beam centroid in cm.

radiusfloat

The disk radius in cm.

radius: float = 0.1#
rvs(size: int = 1) Tuple[ndarray, ndarray][source]#

Overloaded method.

Arguments#

sizeint

The number of X-ray photon positions to be generated.

Returns#

x, y2-element tuple of np.ndarray of shape size

The photon positions on the x-y plane.

class hexsample.source.GaussianBeam(x0: float = 0.0, y0: float = 0.0, sigma: float = 0.1)[source]#

Azimuthally-simmetric gaussian beam.

Arguments#

x0float

The x-coordinate of the beam centroid in cm.

y0float

The y-coordinate of the beam centroid in cm.

sigmafloat

The beam sigma in cm.

sigma: float = 0.1#
rvs(size: int = 1) Tuple[ndarray, ndarray][source]#

Overloaded method.

Arguments#

sizeint

The number of X-ray photon positions to be generated.

Returns#

x, y2-element tuple of np.ndarray of shape size

The photon positions on the x-y plane.

class hexsample.source.SpectrumBase[source]#

Base class for a photon energy spectrum.

rvs(size: int = 1) ndarray[source]#

Do-nothing hook to generate random energies.

Arguments#

sizeint

The number of X-ray energies to be generated.

Returns#

energynp.ndarray of shape size

The photon energies in eV.

plot() None[source]#

Do-nothing plotting hook.

class hexsample.source.LineForest(element: str | int, initial_level: str | None = None, excitation_energy: float | None = None)[source]#

Class describing a set of X-ray emission lines for a given element and initial level or excitation energy.

See https://xraypy.github.io/XrayDB/python.html#x-ray-emission-lines for more information.

Arguments#

elementint or str

atomic number or atomic symbol for the given element

initial_levelstr, optional

iupac symbol of the initial level

excitation_energyfloat, optional

excitation energy in eV

rvs(size: int = 1) ndarray[source]#

Throw random energies from the line forest.

Arguments#

sizeint

The number of X-ray energies to be generated.

Returns#

energynp.ndarray of shape size

The photon energies in eV.

plot() None[source]#

Plot the line forest.

class hexsample.source.Source(spectrum: SpectrumBase, beam: BeamBase, rate: float = 100.0)[source]#

Base class for a X-ray source.

Arguments#

ratefloat

The photon rate in Hz.

spectrumSpectrumBase

The source spectrum.

beamBeamBase

The source beam morphology.

rvs_timestamp(size: int = 1, tmin: float = 0.0) ndarray[source]#

Extract random times.

Arguments#

sizeint

The number of X-ray timestamps to be generated.

Returns#

timestampnp.ndarray of shape size

The photon timestamps in eV.

rvs(size: int = 1) Tuple[ndarray, ndarray, ndarray, ndarray][source]#

Extract random X-ray initial properties.

Arguments#

sizeint

The number of X-ray properties to be generated.

Returns#

timestamp, energy, x, y4-element tuple of np.ndarray of shape size

The photon properties.