autoemx.runners.calibrate_detector_model module
Runners: Calibrate the Peak Shape and Background Functions of the Detector Model
The detector model of a microscope (autoemx/calibrations/<microscope_ID>/detector_model.json) describes, as functions of energy or atomic number, parameters that are fixed during fitting:
Peak shape (incomplete charge collection, ICC): gamma, f_tail, R_e and F_loss, each a sigmoid of the X-ray energy E (keV): scale * (offset + amplitude / (1 + exp(-steepness * (E - center)))). gamma and f_tail apply to lines below 1.84 keV, R_e and F_loss to lines between 1.18 and 5 keV.
Background (modified Duncumb model): P (quadratic in the mean atomic number Z), F (1 - exp(-(Z + z_offset) / z_scale)) and beta (sigmoid + Gaussian in Z).
These runners refit spectra of standards with some of these parameters fitted freely (chosen by the user), collect their fitted values, and fit the functions of the detector model to them, starting from the current coefficients and weighting each point by its standard error. Only the coefficients chosen by the user are fitted; the others keep their current values. Since the parameters are correlated, calibrate them one at a time, updating the detector model before calibrating the next one (see the documentation for the recommended order).
Use high-count spectra of bulk standards, ideally pure elements, spanning the energy (peak shape) or atomic number (background) range. The results are printed with the current values, plotted, and given as a snippet for detector_model.json: the detector model is not changed.
Created on Mon Oct 12 2026 @author: Andrea
- autoemx.runners.calibrate_detector_model.calibrate_peak_shape_params(samples: Dict[str, Sequence[str]], params: Sequence[str] = ('gamma', 'f_tail', 'R_e', 'F_loss'), sigmoid_coeffs: Sequence[str] = ('offset', 'amplitude', 'center', 'steepness'), max_spectra_per_sample: int | None = 5, plot: bool = True) Dict[str, Any][source]
Calibrate the peak shape (ICC) functions of the detector model.
- Parameters:
samples (dict) – {path of a standard (sample folder with ledger.json): elements whose peak shapes are fitted freely}.
params (sequence of str, optional) – Peak shape parameters fitted freely, among ‘gamma’, ‘f_tail’, ‘R_e’, ‘F_loss’. Default: all. The others keep the values of the detector model during the fits.
sigmoid_coeffs (sequence of str, optional) – Coefficients of the sigmoids fitted to the values of each parameter, among ‘offset’, ‘amplitude’, ‘center’, ‘steepness’. Default: all. The others keep their current values. A sigmoid is fitted only with more points (lines) than coefficients.
max_spectra_per_sample (int or None, optional) – Spectra fitted per standard (default 5; None: all).
plot (bool, optional) – If True (default), plots the fitted values with the current and fitted functions.
- Returns:
microscope_ID, meas_mode, and for each parameter: points (line, energy, value, stdev, n, n_at_bound), current and fitted (None if not fitted) sigmoid coefficients.
- Return type:
dict
- autoemx.runners.calibrate_detector_model.calibrate_background_params(samples: Sequence[str], params: Sequence[str] = ('P', 'F', 'beta'), fit_functions: Sequence[str] | None = None, coeffs: Dict[str, Sequence[str]] | None = None, max_spectra_per_sample: int | None = 5, plot: bool = True) Dict[str, Any][source]
Calibrate the background functions (modified Duncumb model) of the detector model.
- Parameters:
samples (sequence of str) – Paths of standards (sample folders with ledger.json), ideally pure elements: the values are attributed to the mean atomic number Z of each standard (for beta, exact only for pure elements).
params (sequence of str, optional) – Background parameters fitted freely, among ‘P’, ‘F’, ‘beta’. Default: all. The others are set by the functions of the detector model during the fits (also beta, otherwise fitted freely for bulk samples).
fit_functions (sequence of str, optional) – Parameters whose functions are fitted to their values, among params. Default: all params. E.g. params [‘P’, ‘F’, ‘beta’] with fit_functions [‘P’] fits the spectra with all three free, and only the function of P.
coeffs (dict, optional) – Coefficients fitted for each parameter, e.g. {‘P’: [‘a0’]} (P: ‘a2’, ‘a1’, ‘a0’, for a2*Z**2 + a1*Z + a0; F: ‘z_offset’, ‘z_scale’; beta: the fields of BetaParams). Default: all. The others keep their current values. A function is fitted only with more points (standards) than coefficients.
max_spectra_per_sample (int or None, optional) – Spectra fitted per standard (default 5; None: all).
plot (bool, optional) – If True (default), plots the fitted values with the current and fitted functions.
- Returns:
microscope_ID, meas_mode, and for each parameter: points (sample, Z, value, stdev, n, n_at_bound), current and fitted (None if not fitted) coefficients.
- Return type:
dict