autoemxsp.runners.fit_and_quantify_spectrum module

Fitting and quantification of a single X-ray spectrum.

For spectrum-level analysis of fitting and quantification performance.

Import this module in your own code and call the fit_and_quantify_spectrum() function, passing your desired ‘sample_ID’, ‘spectrum_ID’ and options as arguments. This enables integration into larger workflows or pipelines.

Workflow:
  • Loads sample configurations from Spectra_collection_info.json

  • Loads acquired spectral data from Data.csv

  • Performs quantification (optionally only on unquantified spectra)

  • Optionally performs clustering/statistical analysis and saves results

Notes

  • Only the sample_ID and ‘spectrum_ID’ are required if acquisition output is saved in the default Results directory; otherwise, specify results_path.

param sample_ID:

Sample identifier.

type sample_ID:

str

param spectrum_ID:

Value reported in ‘Spectrum #’ column in Data.csv.

type spectrum_ID:

int

param els_sample:

List of elements in the sample.

type els_sample:

list, optional

param els_substrate:

List of substrate elements.

type els_substrate:

list, optional

param is_standard:

Defines whether measurement is from an experimental standard (i.e., sample of known composition)

type is_standard:

bool

param results_path:

Base directory where results are stored. Default: autoemxsp/Results

type results_path:

str, optional

param use_instrument_background:

Whether to use instrument background if present. Default: False

type use_instrument_background:

bool, optional

param quantify_plot:

Whether to quantify the spectrum.

type quantify_plot:

bool, optional

param plot_signal:

Whether to plot the fitted spectrum.

type plot_signal:

bool, optional

param zoom_plot:

Whether to zoom on a specific line.

type zoom_plot:

bool, optional

param line_to_plot:

Line to zoom on.

type line_to_plot:

str, optional

param fit_tol:

scipy fit tolerance. Defines conditions of fit convergence

type fit_tol:

float, optional

param is_particle:

If True, treats sample as particle (powder). Uses particle geometry fitting parameters

type is_particle:

bool, optional

param max_undetectable_w_fr:

Maximum allowed weight fraction for undetectable elements (default: 0). Total mass fraction of fitted elements is forced to be between [1-max_undetectable_w_fr, 1]

type max_undetectable_w_fr:

float, optional

param force_single_iteration:

If True, quantification will be run for a single iteration only (default: False).

type force_single_iteration:

bool, optional

param interrupt_fits_bad_spectra:

If True, interrupt fitting if spectrum is detected to lead to poor quantification (default: False).

type interrupt_fits_bad_spectra:

bool, optional

param print_results:

If True, prints all fitted parameters and their values (default: True).

type print_results:

bool, optional

param quant_verbose:

If True, prints quantification operations

type quant_verbose:

bool, optional

param fitting_verbose:

If True, prints fitting operations

type fitting_verbose:

bool, optional

param Created on Tue Jul 29 13:

type Created on Tue Jul 29 13:

18:16 2025

param @author:

type @author:

Andrea

autoemxsp.runners.fit_and_quantify_spectrum.fit_and_quantify_spectrum(sample_ID: str, spectrum_ID: int, els_sample: list = None, els_substrate: list = None, is_standard: bool = False, spectrum_lims: tuple = None, results_path: str = None, use_instrument_background: bool = False, quantify_plot: bool = True, plot_signal: bool = True, zoom_plot: bool = False, line_to_plot: str = '', fit_tol: float = 0.0001, is_particle: bool = True, max_undetectable_w_fr: float = 0, force_single_iteration: bool = False, interrupt_fits_bad_spectra: bool = False, standards_dict: dict = None, print_results: bool = True, quant_verbose: bool = True, fitting_verbose: bool = True)[source]

Fit and (optionally) quantify a single spectrum.

Parameters:
  • sample_ID (str) – Sample identifier.

  • spectrum_ID (int) – Value reported in ‘Spectrum #’ column in Data.csv.

  • els_sample (list, optional) – List of elements in the sample.

  • els_substrate (list, optional) – List of substrate elements.

  • is_standard (bool) – Defines whether measurement is from an experimental standard (i.e., sample of known composition)

  • results_path (str, optional) – Base directory where results are stored. Default: autoemxsp/Results

  • use_instrument_background (bool, optional) – Whether to use instrument background if present. Default: False

  • quantify_plot (bool, optional) – Whether to quantify the spectrum.

  • plot_signal (bool, optional) – Whether to plot the fitted spectrum.

  • zoom_plot (bool, optional) – Whether to zoom on a specific line.

  • line_to_plot (str, optional) – Line to zoom on.

  • fit_tol (float, optional) – scipy fit tolerance. Defines conditions of fit convergence

  • is_particle (bool, optional) – If True, treats sample as particle (powder). Uses particle geometry fitting parameters

  • max_undetectable_w_fr (float, optional) – Maximum allowed weight fraction for undetectable elements (default: 0). Total mass fraction of fitted elements is forced to be between [1-max_undetectable_w_fr, 1]

  • force_single_iteration (bool, optional) – If True, quantification will be run for a single iteration only (default: False).

  • interrupt_fits_bad_spectra (bool, optional) – If True, interrupt fitting if spectrum is detected to lead to poor quantification (default: False).

  • print_results (bool, optional) – If True, prints all fitted parameters and their values (default: True).

  • quant_verbose (bool, optional) – If True, prints quantification operations

  • fitting_verbose (bool, optional) – If True, prints fitting operations

Returns:

quantifier – The quantifier object containing the results, fit parameters, and methods for further analysis and plotting.

Return type:

XSp_Quantifier