autoemx.runners.fit_and_quantify_spectrum_from_ledger 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_from_ledger() function, passing your desired ‘sample_ID’, ‘spectrum_ID’ and options as arguments. This enables integration into larger workflows or pipelines.
- Workflow:
Loads sample configurations and spectral data from ledger.json. Results saved in the legacy Data.csv format are converted to a ledger.json automatically
Fits and (optionally) quantifies the selected spectrum
Optionally plots the fitted spectrum
Notes
Only the sample_ID and ‘spectrum_ID’ are required if acquisition output is saved in the default Results directory; otherwise, specify results_path.
Created on Tue Jul 29 13:18:16 2025
@author: Andrea
- autoemx.runners.fit_and_quantify_spectrum_from_ledger.fit_and_quantify_spectrum_from_ledger(sample_ID: str, spectrum_ID: int, els_sample: List[str] | None = None, els_w_frs: Dict[str, float] | None = None, els_substrate: List[str] | None = None, is_standard: bool = False, spectrum_lims: tuple | None = None, results_path: str | None = None, use_instrument_background: bool = False, quantify: 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 = None, print_results: bool = True, quant_verbose: bool = True, fitting_verbose: bool = True, free_area_el_lines: List[str] | None = None, free_peak_shape_els: List[str] | None = None, free_peak_shape_params: List[str] | None = None, free_background_params: List[str] | None = None, peaks_to_annotate: str = 'main', ledger: Any | None = None, identify_missing_elements: bool | None = None, quantify_plot: bool | None = None)[source]
Fit and (optionally) quantify a single spectrum.
- Parameters:
sample_ID (str) – Sample identifier.
spectrum_ID (int) – Value reported in the ledger-backed Spectrum ID sequence (legacy-compatible with the historical ‘Spectrum #’ identifier from Data.csv).
els_sample (list(str), optional) – List of elements in the sample. If the first entry is “” or None, the rest of the list is appended to the list loaded from the ledger; otherwise, the provided list replaces it.
els_substrate (list(str), optional) – List of substrate elements. If the first entry is “” or None, the rest of the list is appended to the list loaded from the ledger; otherwise, the provided list replaces it.
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: autoemx/Results
use_instrument_background (bool, optional) – Whether to use instrument background if present. Default: False
quantify (bool, optional) – If True (default), fit and quantify the spectrum. If False, only fit it (e.g. to measure the P/B ratios of a standard).
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.
peaks_to_annotate (str, optional) – Which peaks to annotate in plot_quantified_spectrum (‘all’, ‘main’, ‘most).
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
identify_missing_elements (bool, optional) – If True, look for elements missing from the fit before fitting (see XSp_Quantifier). Elements confirmed by the fit are added (and quantified if a standard is available); weaker detections are reported. If None (default), uses the setting of the sample’s active quantification run (off for runs saved before this option existed).
quantify_plot (bool, optional) – Deprecated, use quantify.
- Returns:
quantifier – The quantifier object containing the results, fit parameters, and methods for further analysis and plotting.
- Return type: