qem.model
Functions
|
A decorator indicating abstract methods. |
|
Parse a .env file and then load all the variables found as environment variables. |
|
Safely convert a Keras tensor to numpy array, handling different backends. |
|
Safely convert a numpy array to Keras tensor. |
Classes
Gaussian kernel implementation. |
|
|
Gaussian peak model. |
|
Base class for all image models. |
|
Lorentzian peak model. |
|
Voigt peak model. |
- class qem.model.ImageModel(*args: Any, **kwargs: Any)[source]
Base class for all image models.
- __init__(dx: float = 1.0)[source]
Initialize the model.
- Parameters:
dx (
float, optional
) – Pixel size. Defaults to 1.0.
- abstract model_fn(x, y, pos_x, pos_y, height, width, *args)[source]
Core model function that defines the peak shape.
- abstract volume(params: dict) numpy.ndarray [source]
Calculate the volume of each peak.
- sum(x_grid: numpy.ndarray, y_grid: numpy.ndarray, local: bool = True)[source]
Calculates the sum of all peaks on a grid, with an optional background.
This method supports both a global calculation and a memory-efficient local calculation suitable for JIT compilation.
- Parameters:
x_grid (
array
) – A 2D array of X coordinates (from meshgrid).y_grid (
array
) – A 2D array of Y coordinates (from meshgrid).local (
bool, optional
) – If True, calculates peaks in local windows to conserve memory. This approach is JIT-compatible. Defaults to True.
- Returns:
array – A 2D array representing the rendered image of peaks plus background.
- class qem.model.GaussianModel(*args: Any, **kwargs: Any)[source]
Gaussian peak model.
- volume(params: dict) numpy.ndarray [source]
Calculate the volume of each Gaussian peak.
For a 2D Gaussian, the volume is: height * 2π * width²
- class qem.model.LorentzianModel(*args: Any, **kwargs: Any)[source]
Lorentzian peak model.
- volume(params: dict) numpy.ndarray [source]
Calculate the volume of each Lorentzian peak.
For a 2D Lorentzian, the volume is: height * π * width²
- class qem.model.VoigtModel(*args: Any, **kwargs: Any)[source]
Voigt peak model.
- __init__(dx: float = 1.0)[source]
Initialize the model.
- Parameters:
dx (
float, optional
) – Pixel size. Defaults to 1.0.
- volume(params: dict) numpy.ndarray [source]
Calculate the volume of each Voigt peak.
For a 2D Voigt profile, the volume is a weighted sum of Gaussian and Lorentzian volumes: V = ratio * (height * 2π * width²) + (1-ratio) * (height * π * width²)
- class qem.model.GaussianKernel[source]
Gaussian kernel implementation.
- qem.model.gaussian_2d_single(xy, pos_x, pos_y, height, width, background)
2D Gaussian function for single atom.