autoemxsp.XSp_calibs package
Calibration Loader for SEM EDS Analysis
This module provides a function to dynamically load and inject microscope-specific calibration parameters and functions into the caller’s namespace.
- Usage from other modules:
import XSp_calibs as calibs calibs.load_microscope_calibrations(microscope_ID =’PhenomXL’, meas_mode = ‘point’, load_detector_channel_params = True)
Author: Andrea Giunto Created on: Mon Jan 20 15:40:42 2025
- autoemxsp.XSp_calibs.load_microscope_calibrations(microscope_ID: str, meas_mode: str | None = None, load_detector_channel_params: bool = False) None[source]
Dynamically load calibration parameters for a given microscope and EDS mode.
This function imports all public attributes from the calibration module corresponding to the specified microscope_ID and injects them into the current module’s namespace.
Optionally, it also loads the latest detector channel parameters. This is only needed during spectra acquisition, not when fitting or quantifying. In the latter cases, the detector channel parameters should be loaded from the measurement files diurectly.
- Parameters:
microscope_ID (str) – The name of the microscope (must match a folder in the calibration directory).
meas_mode (str, Optional) – If provided, it checks whether it is included in the available_meas_modes. The EDS mode to use (must be listed in ‘available_meas_modes’ in the calibration module).
load_detector_channel_params (bool, optional) – If True, loads the latest detector channel parameters as well (default: False).
- Raises:
ValueError – If the calibration directory or module cannot be found, or if the meas_mode is invalid.
AttributeError – If the calibration module does not define ‘available_meas_modes’.
FileNotFoundError – If no detector channel calibration file is found.
Warning
This function injects variables and functions into the module namespace. Use with care to avoid name collisions.
- autoemxsp.XSp_calibs.load_latest_detector_channel_params(meas_mode)[source]
Load the latest detector channel parameters for a given measurement mode.
This function retrieves the most recent detector channel calibration parameters (such as beam current, energy scale, and offset) for the specified measurement mode. It ensures that all required calibration keys are present before returning.
The parameters are loaded via the get_latest_detector_channel_params() function, which must populate the global detector_channel_params dictionary.
- Parameters:
meas_mode (str) – The measurement mode for which detector channel parameters are requested. Must be one of the modes available in detector_channel_params.
- Raises:
RuntimeError – If detector_channel_params is not loaded into the global namespace.
ValueError – If the requested meas_mode is not present in detector_channel_params.
KeyError – If one or more required calibration keys are missing for the given meas_mode.
- autoemxsp.XSp_calibs.get_latest_detector_channel_params(verbose: bool = True) None[source]
Load dictionary of detector channel calibration parameters for each meas_mode.
- Each entry contains:
offset: float, energy offset (keV) for channel 0
scale: float, energy bin width (keV/channel)
spot_size: float, related to beam current
These parameters should be recalibrated regularly.
- Raises:
FileNotFoundError – If no detector channel calibration file is found.:
- autoemxsp.XSp_calibs.update_detector_channel_params(meas_mode, new_offset, new_scale, verbose: bool = True)[source]
Update and save detector channel calibration parameters for a given measurement mode.
This function retrieves the latest detector channel parameters for the specified measurement mode, updates the offset and scale values, and saves the updated parameters to a timestamped JSON file in the calibration directory.
- Parameters:
meas_mode (str) – The measurement mode for which parameters will be updated. Must be present in the loaded detector_channel_params.
new_offset (float) – The new detector channel offset value to set.
new_scale (float) – The new detector channel scale value to set.
verbose (bool, optional) – If True (default), prints/logs the location of the saved calibration file.
- Raises:
RuntimeError – If detector channel parameters cannot be loaded.
ValueError – If the specified meas_mode does not exist in the parameters.
KeyError – If required calibration keys are missing from the parameters.
- autoemxsp.XSp_calibs.load_standards(meas_type: str, beam_energy: int) dict[source]
Load standards data for a specified technique and beam energy.
Called when performing quantifications.
- Parameters:
beam_energy (int) – The beam energy (in keV) for which to load the standards.
- Returns:
standards – Dictionary containing the loaded EDS standards data.
- Return type:
dict
- Raises:
FileNotFoundError – If the standards file does not exist.
ValueError – If the standards file cannot be parsed as JSON.
Notes
Expects a file named ‘EDSstandards_{beam_energy}keV.json’ in the directory specified by microscope_calib_dir. beam_energy will be converted to an int for the file name’s purpose.