hexsample.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:
PointBeam
represents a point-like beam;DiskBeam
represents a uniform disk;GaussianBeam
represents a simple gaussian beam.
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)#
Base class describing the morphology of a X-ray beam.
- Parameters:
x0 (float) – The x-coordinate of the beam centroid in cm.
y0 (float) – The y-coordinate of the beam centroid in cm.
- x0: float = 0.0#
- y0: float = 0.0#
- rvs(size: int = 1) Tuple[ndarray, ndarray] #
Do-nothing hook to generate random positions in the x-y plane.
- Parameters:
size (int) – The number of X-ray photon positions to be generated.
- Returns:
x, y – The photon positions on the x-y plane.
- Return type:
2-element tuple of np.ndarray of shape
size
- class hexsample.source.PointBeam(x0: float = 0.0, y0: float = 0.0)#
Point-like X-ray beam.
- Parameters:
x0 (float) – The x-coordinate of the beam centroid in cm.
y0 (float) – The y-coordinate of the beam centroid in cm.
- rvs(size: int = 1) Tuple[ndarray, ndarray] #
Overloaded method.
- Parameters:
size (int) – The number of X-ray photon positions to be generated.
- Returns:
x, y – The photon positions on the x-y plane.
- Return type:
2-element tuple of np.ndarray of shape
size
- class hexsample.source.DiskBeam(x0: float = 0.0, y0: float = 0.0, radius: float = 0.1)#
Uniform disk X-ray beam.
- Parameters:
x0 (float) – The x-coordinate of the beam centroid in cm.
y0 (float) – The y-coordinate of the beam centroid in cm.
radius (float) – The disk radius in cm.
- radius: float = 0.1#
- rvs(size: int = 1) Tuple[ndarray, ndarray] #
Overloaded method.
- Parameters:
size (int) – The number of X-ray photon positions to be generated.
- Returns:
x, y – The photon positions on the x-y plane.
- Return type:
2-element tuple of np.ndarray of shape
size
- class hexsample.source.GaussianBeam(x0: float = 0.0, y0: float = 0.0, sigma: float = 0.1)#
Azimuthally-simmetric gaussian beam.
- Parameters:
x0 (float) – The x-coordinate of the beam centroid in cm.
y0 (float) – The y-coordinate of the beam centroid in cm.
sigma (float) – The beam sigma in cm.
- sigma: float = 0.1#
- rvs(size: int = 1) Tuple[ndarray, ndarray] #
Overloaded method.
- Parameters:
size (int) – The number of X-ray photon positions to be generated.
- Returns:
x, y – The photon positions on the x-y plane.
- Return type:
2-element tuple of np.ndarray of shape
size
- class hexsample.source.SpectrumBase#
Base class for a photon energy spectrum.
- rvs(size: int = 1) ndarray #
Do-nothing hook to generate random energies.
- Parameters:
size (int) – The number of X-ray energies to be generated.
- Returns:
energy – The photon energies in eV.
- Return type:
np.ndarray of shape
size
- plot() None #
Do-nothing plotting hook.
- class hexsample.source.LineForest(element: str | int, initial_level: str | None = None, excitation_energy: float | None = None)#
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.
- Parameters:
element (int or str) – atomic number or atomic symbol for the given element
initial_level (str, optional) – iupac symbol of the initial level
excitation_energy (float, optional) – excitation energy in eV
- rvs(size: int = 1) ndarray #
Throw random energies from the line forest.
- Parameters:
size (int) – The number of X-ray energies to be generated.
- Returns:
energy – The photon energies in eV.
- Return type:
np.ndarray of shape
size
- plot() None #
Plot the line forest.
- class hexsample.source.Source(spectrum: SpectrumBase, beam: BeamBase, rate: float = 100.0)#
Base class for a X-ray source.
- Parameters:
rate (float) – The photon rate in Hz.
spectrum (SpectrumBase) – The source spectrum.
beam (BeamBase) – The source beam morphology.
- rvs_timestamp(size: int = 1, tmin: float = 0.0) ndarray #
Extract random times.
- Parameters:
size (int) – The number of X-ray timestamps to be generated.
- Returns:
timestamp – The photon timestamps in eV.
- Return type:
np.ndarray of shape
size
- rvs(size: int = 1) Tuple[ndarray, ndarray, ndarray, ndarray] #
Extract random X-ray initial properties.
- Parameters:
size (int) – The number of X-ray properties to be generated.
- Returns:
timestamp, energy, x, y – The photon properties.
- Return type:
4-element tuple of np.ndarray of shape
size