xcal.models

Functions:

Base_Spec_Model([params_list])

Base class for all spectral components in xcal.

Reflection_Source(voltage, takeoff_angle[, ...])

A template source model designed specifically for reflection sources, including all necessary methods.

Transmission_Source(voltage, ...)

A template source model designed specifically for reflection sources, including all necessary methods.

Filter(materials, thickness)

A template filter model based on Beer's Law and NIST mass attenuation coefficients, including all necessary methods.

Scintillator(thickness, materials[, device, ...])

A template scintillator model based on Beer's Law, NIST mass attenuation coefficients, and mass energy-absorption coefficients, including all necessary methods.

class xcal.models.Base_Spec_Model(params_list=[])[source]

Bases: Module

Base class for all spectral components in xcal.

Parameters:

params_list (list) – List of dictionaries containing possible discrete and continuous parameters combinations. All dictionaries share the same keywords. Each dictionary contains both discrete and continuous parameters. Continuous parameters should be specified as tuples with the format (initial value, lower bound, upper bound), while discrete parameters can be directly specified.

set_spectrum(energies, sp)[source]
Parameters:
  • energies (numpy.array) – A numpy array containing the X-ray energies of a poly-energetic source in units of keV.

  • sp (numpy.array) – Spectrum.

Returns:

forward(energies)[source]

Placeholder forward method.

Parameters:

energies (numpy.array) – A numpy array containing the X-ray energies of a poly-energetic source in units of keV.

Returns:

Output response.

Return type:

torch.Tensor

set_params(params)[source]

Set estimates from a dictionary of parameters.

Parameters:

params (dict) – Dictionary containing parameters.

get_params()[source]

Read estimated parameters as a dictionary.

Returns:

Dictionary containing estimated parameters.

Return type:

dict

class xcal.models.Reflection_Source(voltage, takeoff_angle, single_takeoff_angle=True)[source]

Bases: Base_Spec_Model

A template source model designed specifically for reflection sources, including all necessary methods.

Parameters:
  • voltage (tuple) – (initial value, lower bound, upper bound) for the source voltage. These three values cannot be all None. It will not be optimized when lower == upper.

  • takeoff_angle (tuple) – (initial value, lower bound, upper bound) for the takeoff angle, in degrees. These three values cannot be all None. It will not be optimized when lower == upper.

  • single_takeoff_angle (bool, optional) – Determines whether the takeoff angle is same for all instances. If set to True (default), the same takeoff angle is applied to all instances of Reflection_Source. If set to False, each instance may have a distinct takeoff angle, with different prefix.

set_src_spec_list(energies, src_spec_list, voltages, takeoff_angles)[source]

Set source spectra for interpolation, which will be used only by forward function.

Parameters:
  • energies (numpy.ndarray) – Energies vector for lookup table.

  • src_spec_list (numpy.ndarray) – NVoltages * NAngles * NEnergies. This array contains the reference X-ray source spectra. Each spectrum in this array corresponds to one of the source voltages from src_voltage_list and one of takeoff angle from takeoff_angles.

  • voltages (numpy.ndarray) – This is a sorted array containing the source voltages, each corresponding to a specific reference X-ray source spectrum.

  • takeoff_angles (numpy.ndarray) – List of the anode take-off angles, expressed in degrees.

forward(energies)[source]

Takes X-ray energies and returns the source spectrum.

Parameters:

energies (torch.Tensor) – A tensor containing the X-ray energies of a poly-energetic source in units of keV.

Returns:

The source response.

Return type:

torch.Tensor

class xcal.models.Transmission_Source(voltage, target_thickness, single_target_thickness)[source]

Bases: Base_Spec_Model

A template source model designed specifically for reflection sources, including all necessary methods.

Parameters:

voltage (tuple) – (initial value, lower bound, upper bound) for the source voltage. These three values cannot be all None. It will not be optimized when lower == upper.

set_src_spec_list(energies, src_spec_list, voltages, target_thicknesses)[source]

Set source spectra for interpolation, which will be used only by forward function.

Parameters:
  • src_spec_list (numpy.ndarray) – This array contains the reference X-ray source spectra. Each spectrum in this array corresponds to a specific combination of the ref_takeoff_angle and one of the source voltages from src_voltage_list.

  • src_voltage_list (numpy.ndarray) – This is a sorted array containing the source voltages, each corresponding to a specific reference X-ray source spectrum.

  • ref_takeoff_angle (float) – This value represents the anode take-off angle, expressed in degrees, which is used in generating the reference X-ray spectra.

forward(energies)[source]

Takes X-ray energies and returns the source spectrum.

Parameters:

energies (torch.Tensor) – A tensor containing the X-ray energies of a poly-energetic source in units of keV.

Returns:

The source response.

Return type:

torch.Tensor

class xcal.models.Filter(materials, thickness)[source]

Bases: Base_Spec_Model

A template filter model based on Beer’s Law and NIST mass attenuation coefficients, including all necessary methods.

Parameters:
  • materials (list) – A list of possible materials for the filter, where each material should be an instance containing formula and density.

  • thickness (tuple or list) – If a tuple, it should be (initial value, lower bound, upper bound) for the filter thickness. If a list, it should have the same length as the materials list, specifying thickness for each material. These values cannot be all None. It will not be optimized when lower == upper.

forward(energies)[source]

Takes X-ray energies and returns the filter response.

Parameters:

energies (torch.Tensor) – A tensor containing the X-ray energies of a poly-energetic source in units of keV.

Returns:

The filter response as a function of input energies, selected material, and its thickness.

Return type:

torch.Tensor

class xcal.models.Scintillator(thickness, materials, device=None, dtype=None)[source]

Bases: Base_Spec_Model

A template scintillator model based on Beer’s Law, NIST mass attenuation coefficients, and mass energy-absorption coefficients, including all necessary methods.

Parameters:
  • materials (list) – A list of possible materials for the scintillator, where each material should be an instance containing formula and density.

  • thickness (tuple) – (initial value, lower bound, upper bound) for the scintillator thickness. These three values cannot be all None. It will not be optimized when lower == upper.

forward(energies)[source]

Takes X-ray energies and returns the scintillator response.

Parameters:

energies (torch.Tensor) – A tensor containing the X-ray energies of a poly-energetic source in units of keV.

Returns:

The scintillator conversion function as a function of input energies, selected material, and its thickness.

Return type:

torch.Tensor