autoemx.core.fitter.detector_response module
Detector Response Function module.
Provides handling of EDS detector response, including convolution matrices for energy resolution and incomplete charge collection (ICC).
This module is used by both peaks and background models to accurately simulate detector effects.
- Main Class:
DetectorResponseFunction: Manages detector response and convolution operations
- class autoemx.core.fitter.detector_response.SparseConvolutionRow(*, start_index: int, values: list[float])[source]
Bases:
BaseModelSparse representation of a matrix row.
- start_index: int
- values: list[float]
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class autoemx.core.fitter.detector_response.DetectorResponseFunction[source]
Bases:
objectProvides static and class methods for handling the detector’s instrumental response.
Includes convolution matrices for energy resolution and incomplete charge collection (ICC). This class is initialized with calibration data and is used by both background and peak models to accurately simulate detector effects.
Class Attributes
- det_res_conv_matrixnp.ndarray or None
Detector resolution convolution matrix (cropped to spectrum limits).
- icc_conv_matrixnp.ndarray or None
ICC convolution matrix (cropped to spectrum limits).
- det_response_opscipy.sparse.csr_matrix or None
Sparse product icc_conv_matrix @ det_res_conv_matrix, applied in _apply_det_response_fncts.
- det_eff_energy_valsnp.ndarray
Energy values for detector efficiency curve.
- det_eff_valsnp.ndarray
Detector efficiency values.
- energy_vals_paddingint
Padding added to energy_vals for convolution operations.
- det_res_conv_matrix = None
- icc_conv_matrix = None
- det_response_op = None
- energy_vals_padding = 30
- conv_zero_tol = 1e-14
- classmethod ensure_conv_matrices_cached(det_ch_offset, det_ch_width, microscope_ID, verbose=True) bool[source]
Ensure convolution matrices for this detector channel setup exist on disk.
- Returns:
True if matrices were newly computed, False if already cached.
- Return type:
bool
- classmethod setup_detector_response_vars(det_ch_offset, det_ch_width, spectrum_lims, microscope_ID, verbose=True)[source]
Initialize detector response variables for the EDS system.
Loads detector efficiency and convolution matrices for the specified microscope. If convolution matrices for the given channel settings do not exist, they are calculated and saved.
- Parameters:
det_ch_offset (float) – Energy offset for detector channels (in keV).
det_ch_width (float) – Channel width (in keV).
spectrum_lims (tuple of int) – (low, high) indices for the usable spectrum region.
microscope_ID (str) – Identifier for the microscope/calibration directory.
verbose (bool, optional) – If True, print status messages.
Attributes (Sets Class)
---------------------
det_eff_energy_vals (np.ndarray) – Energy values for detector efficiency.
det_eff_vals (np.ndarray) – Detector efficiency values.
det_res_conv_matrix (np.ndarray) – Detector response convolution matrix (cropped to spectrum_lims).
icc_conv_matrix (np.ndarray) – ICC convolution matrix (cropped to spectrum_lims).
Notes
Convolution matrices are detector-dependent and cached in ~/.autoemx/cache/<microscope_ID>/ for efficiency.
Prefer calling
ensure_conv_matrices_cachedonce on the main process before parallel quantification so workers only hit the cached fast path.If multiple EDS detectors are used, this code should be adapted.
- static det_sigma(E, conv_eff, elec_noise, F)[source]
Detector Gaussian sigma (keV) at X-ray energy E (keV), for given detector parameters.
sigma = conv_eff * sqrt(elec_noise^2 + E * F / conv_eff), with conv_eff the energy per electron-hole pair (keV), elec_noise the electronic noise (in electrons) and F the Fano factor. See _det_sigma for the version using the loaded microscope calibrations.
- static get_icc_spectrum(energy_vals, line_en, R_e=5e-06, F_loss=0.27)[source]
Generate the ICC (Incomplete Charge Collection) smearing function for a given line energy.
- Parameters:
energy_vals (array-like) – Energy axis (in keV) of detector channels.
line_en (float) – X-ray line energy (in keV).
R_e (float, optional) – Effective recombination parameter (cm).
F_loss (float, optional) – Fractional charge loss parameter.
- Returns:
icc_n_vals_distr – ICC distribution, mapped to detector channel energies.
- Return type:
list