deconvolution
module¶
- class pyfasma.deconvolution.FitGaussian(data, params_list, prefix='g', verbose=False)¶
Bases:
_BaseModel
Fit a series of Gaussian curves to the input data. The class uses a multi-curve implementation of lmfit’s GaussianModel. The number of Gaussian curves is determined by the number of parameter dictionaries in params_list. In contrast to lmfit’s GaussianModel, this class uses the height, and Full Width at Half Maximum (FWHM) as parameters instead of the amplitude and sigma since they can assist in easier estimation of the initial values of the curves.
- Parameters:
data (pd.DataFrame) – The input data with x-values as the index and y-values as columns.
params_list (list of dict) –
A list of dictionaries, where each dictionary contains the initial guesses for the parameters of a single Gaussian component. Each dictionary should have the following keys:
’height’: The peak height of the Gaussian. This can be a float or a dictionary specifying bounds or constraints. For example: - float: 10 - dict: {‘value’: 10, ‘min’: 1, ‘max’: 20}
’center’: The center position (mean) of the Gaussian. This can be a float or a dictionary specifying bounds or constraints. For example: - float: 5 - dict: {‘value’: 5, ‘min’: 0, ‘max’: 10}
’fwhm’: The full width at half maximum (FWHM) of the Gaussian. This can be a float or a dictionary specifying bounds or constraints. For example: - float: 1 - dict: {‘value’: 1, ‘min’: 0.1, ‘max’: 5}
These parameters are used to initialize the Gaussian models.
prefix (str, optional) – Prefix for parameter names in the model. Default is “g”.
verbose (bool, optional) – If True, provides verbose output during fitting. Default is False.
- model¶
A composite model consisting of multiple Gaussian functions, one for each entry in params_list.
- Type:
MultiGaussianModel
Notes
The fitting process automatically calculates additional parameters for each Gaussian component, such as sigma and amplitude, based on the fitted fwhm and height.
The class performs the fitting operation upon initialization and stores the results in results_dict.
This class leverages the lmfit library for model fitting. For more information on Gaussian models in lmfit, refer to the [lmfit Gaussian Model documentation](https://lmfit.github.io/lmfit-py/builtin_models.html#gaussianmodel).
Examples
>>> data = pd.DataFrame({...}) >>> params_list = [ ... {"height": 10, "center": 5, "fwhm": 1}, ... { ... "height": {'value': 15, 'min': 10, 'max': 20}, ... "center": 10, ... "fwhm": 2 ... }, ... ] >>> fit = FitGaussian(data, params_list) >>> fit_results = fit.results_dict
- class pyfasma.deconvolution.FitLorentzian(data, params_list, prefix='l', verbose=False)¶
Bases:
_BaseModel
Fit a series of Lorentzian curves to the input data. The class uses a multi-curve implementation of lmfit’s LorentzianModel. The number of Lorentzian curves is determined by the number of parameter dictionaries in params_list. In contrast to lmfit’s LorentzianModel, this class uses the height, and Full Width at Half Maximum (FWHM) as parameters instead of the amplitude and gamma since they can assist in easier estimation of the initial values of the curves.
- Parameters:
data (pd.DataFrame) – The input data with x-values as the index and y-values as columns.
params_list (list of dict) –
A list of dictionaries, where each dictionary contains the initial guesses for the parameters of a single Lorentzian component. Each dictionary should have the following keys:
’height’: The peak height of the Lorentzian. This can be a float or a dictionary specifying bounds or constraints. For example: - float: 10 - dict: {‘value’: 10, ‘min’: 1, ‘max’: 20}
’center’: The center position (mean) of the Lorentzian. This can be a float or a dictionary specifying bounds or constraints. For example: - float: 5 - dict: {‘value’: 5, ‘min’: 0, ‘max’: 10}
’fwhm’: The full width at half maximum (FWHM) of the Lorentzian. This can be a float or a dictionary specifying bounds or constraints. For example: - float: 1 - dict: {‘value’: 1, ‘min’: 0.1, ‘max’: 5}
These parameters are used to initialize the Lorentzian models.
prefix (str, optional) – Prefix for parameter names in the model. Default is “l”.
verbose (bool, optional) – If True, provides verbose output during fitting. Default is False.
- model¶
A composite model consisting of multiple Lorentzian functions, one for each entry in params_list.
- Type:
MultiLorentzianModel
Notes
The fitting process automatically calculates additional parameters for each Lorentzian component, such as gamma and amplitude, based on the fitted fwhm and height.
The class performs the fitting operation upon initialization and stores the results in results_dict.
This class leverages the lmfit library for model fitting. For more information on Lorentzian models in lmfit, refer to the [lmfit Lorentzian Model documentation](https://lmfit.github.io/lmfit-py/builtin_models.html#lorentzianmodel).
Examples
>>> data = pd.DataFrame({...}) >>> params_list = [ ... {"height": 10, "center": 5, "fwhm": 1}, ... { ... "height": {'value': 15, 'min': 10, 'max': 20}, ... "center": 10, ... "fwhm": 2 ... }, ... ] >>> fit = FitLorentzian(data, params_list) >>> fit_results = fit.results_dict
- class pyfasma.deconvolution.FitVoigt(data, params_list, prefix='v', verbose=False)¶
Bases:
_BaseModel
Fit a series of Voigt curves to the input data. The class uses a multi-curve implementation of lmfit’s VoigtModel. The number of Voigt curves is determined by the number of parameter dictionaries in params_list. In contrast to lmfit’s VoigtModel, this class uses the height, Full Width at Half Maximum (FWHM) of the Gaussian component (fwhm_g), and FWHM of the Lorentzian component (fwhm_l) as parameters instead of sigma and gamma, which can assist in easier estimation of the initial values of the curves.
- Parameters:
data (pd.DataFrame) – The input data with x-values as the index and y-values as columns.
params_list (list of dict) –
A list of dictionaries, where each dictionary contains the initial guesses for the parameters of a single Voigt component. Each dictionary should have the following keys:
’height’: The peak height of the Voigt profile. This can be a float or a dictionary specifying bounds or constraints. For example: - float: 10 - dict: {‘value’: 10, ‘min’: 1, ‘max’: 20}
’center’: The center position (mean) of the Voigt profile. This can be a float or a dictionary specifying bounds or constraints. For example: - float: 5 - dict: {‘value’: 5, ‘min’: 0, ‘max’: 10}
’fwhm_g’: The full width at half maximum (FWHM) of the Gaussian component of the Voigt profile. This can be a float or a dictionary specifying bounds or constraints. For example: - float: 1 - dict: {‘value’: 1, ‘min’: 0.1, ‘max’: 5}
’fwhm_l’: The full width at half maximum (FWHM) of the Lorentzian component of the Voigt profile. This can be a float or a dictionary specifying bounds or constraints. For example: - float: 2 - dict: {‘value’: 2, ‘min’: 0.1, ‘max’: 5}
These parameters are used to initialize the Voigt models.
prefix (str, optional) – Prefix for parameter names in the model. Default is “v”.
verbose (bool, optional) – If True, provides verbose output during fitting. Default is False.
- model¶
A composite model consisting of multiple Voigt functions, one for each entry in params_list.
- Type:
MultiVoigtModel
Notes
The fitting process automatically calculates additional parameters for each Voigt component, such as sigma, gamma, amplitude, and fwhm, based on the fitted fwhm_g, fwhm_l, and height.
The class performs the fitting operation upon initialization and stores the results in results_dict.
This class leverages the lmfit library for model fitting. For more information on Voigt models in lmfit, refer to the [lmfit Voigt Model documentation](https://lmfit.github.io/lmfit-py/builtin_models.html#voigtmodel).
Examples
>>> data = pd.DataFrame({...}) >>> params_list = [ ... {"height": 10, "center": 5, "fwhm_g": 1, "fwhm_l": 2}, ... { ... "height": {'value': 15, 'min': 10, 'max': 20}, ... "center": 10, ... "fwhm_g": 2, ... "fwhm_l": 1 ... }, ... ] >>> fit = FitVoigt(data, params_list) >>> fit_results = fit.results_dict
- pyfasma.deconvolution.MultiGaussianModel(n: int, prefix: str) lmfit.Model ¶
Create a multi-Gaussian model with n Gaussian curves.
This function generates an lmfit.Model that represents the sum of n Gaussian functions. The parameter names for each Gaussian curve are prefixed with a user-defined string to allow for flexible naming and identification of each component.
- Parameters:
n (int) – The number of Gaussian components in the model.
prefix (str) – The prefix for the parameter names. For example, if prefix=’g’, the parameter names will be ‘g1_height’, ‘g1_center’, ‘g1_fwhm’, etc., for the first Gaussian, ‘g2_height’, ‘g2_center’, ‘g2_fwhm’, etc., for the second Gaussian, and so on.
- Returns:
The lmfit.Model object that can be used for fitting data to the multi-Gaussian model.
- Return type:
lmfit.Model
- pyfasma.deconvolution.MultiLorentzianModel(n: int, prefix: str) lmfit.Model ¶
Create a multi-Lorentzian model with n Lorentzian curves.
This function generates an lmfit.Model that represents the sum of n Lorentzian functions. The parameter names for each Lorentzian curve are prefixed with a user-defined string to allow for flexible naming and identification of each component.
- Parameters:
n (int) – The number of Lorentzian components in the model.
prefix (str) – The prefix for the parameter names. For example, if prefix=’l’, the parameter names will be ‘l1_height’, ‘l1_center’, ‘l1_fwhm’, etc., for the first Lorentzian, ‘l2_height’, ‘l2_center’, ‘l2_fwhm’, etc., for the second Lorentzian, and so on.
- Returns:
The lmfit.Model object that can be used for fitting data to the multi-Lorentzian model.
- Return type:
lmfit.Model
- pyfasma.deconvolution.MultiVoigtModel(n: int, prefix: str) lmfit.Model ¶
Create a multi-Voigt model with n Voigt curves.
This function generates an lmfit.Model that represents the sum of n Voigt functions. The parameter names for each Voigt curve are prefixed with a user-defined string to allow for flexible naming and identification of each component.
- Parameters:
n (int) – The number of Voigt components in the model.
prefix (str) – The prefix for the parameter names. For example, if prefix=’v’, the parameter names will be ‘v1_height’, ‘v1_center’, ‘v1_sigma’, ‘v1_gamma’, etc., for the first Voigt, ‘v2_height’, ‘v2_center’, ‘v2_sigma’, ‘v2_gamma’, etc., for the second Voigt, and so on.
- Returns:
The lmfit.Model object that can be used for fitting data to the multi-Voigt model.
- Return type:
lmfit.Model
- pyfasma.deconvolution.gaussian_profile(x: numpy.ndarray, height: float, center: float, fwhm: float) numpy.ndarray ¶
Evaluate a gaussian function at the values of x given its amplitude, center, and Full Width at Half Maximum (FWHM).
- Parameters:
x (np.ndarray) – The input values for which the Gaussian function is evaluated.
height (float) – The height of the Gaussian function.
center (float) – The center of the Gaussian function.
fwhm (float) – The FWHM of the Gaussian function.
- Returns:
The values of the Gaussian function evaluated at the values of x.
- Return type:
np.ndarray
- pyfasma.deconvolution.lorentzian_profile(x: numpy.ndarray, height: float, center: float, fwhm: float) numpy.ndarray ¶
Evaluate a Lorentzian function at the values of x given its amplitude, center, and Full Width at Half Maximum (FWHM).
- Parameters:
x (np.ndarray) – The input values for which the Lorentzian function is evaluated.
height (float) – The height of the Lorentzian function.
center (float) – The center of the Lorentzian function.
fwhm (float) – The FWHM of the Lorentzian function.
- Returns:
The values of the Lorentzian function evaluated at the values of x.
- Return type:
np.ndarray
- pyfasma.deconvolution.multi_gaussian_profile(x: numpy.ndarray, heights: list[float], centers: list[float], fwhms: list[float]) numpy.ndarray ¶
Compute the sum of multiple Gaussian curves.
- Parameters:
x (np.ndarray) – The input values for which the Gaussian functions are evaluated.
heights (list[float]) – List of the heights of the Gaussian functions. Length must match the number of centers and FWHMs.
centers (list[float]) – List of the centers of the Gaussian functions. Length must match the number of heights and FWHMs.
fwhms (list[float]) – List of the FWHMs of the Gaussian functions. Length must match the number of heights and centers.
- Returns:
The values of the Gaussian function evaluated at the values of x.
- Return type:
np.ndarray
- pyfasma.deconvolution.multi_lorentzian_profile(x: numpy.ndarray, heights: list[float], centers: list[float], fwhms: list[float]) numpy.ndarray ¶
Compute the sum of multiple Lorentzian curves.
- Parameters:
x (np.ndarray) – The input values for which the Lorentzian functions are evaluated.
heights (list[float]) – List of the heights of the Lorentzian functions. Length must match the number of centers and FWHMs.
centers (list[float]) – List of the centers of the Lorentzian functions. Length must match the number of heights and FWHMs.
fwhms (list[float]) – List of the FWHMs of the Lorentzian functions. Length must match the number of heights and centers.
- Returns:
The values of the Lorentzian function evaluated at the values of x.
- Return type:
np.ndarray
- pyfasma.deconvolution.multi_voigt_profile(x: numpy.ndarray, heights: list[float], centers: list[float], fwhms_g: list[float], fwhms_l: list[float]) numpy.ndarray ¶
Compute the sum of multiple Voigt curves.
- Parameters:
x (np.ndarray) – The input values for which the Voigt functions are evaluated.
heights (list[float]) – List of the heights of the Voigt functions. Length must match the number of centers, sigmas, and gammas.
centers (list[float]) – List of the centers of the Voigt functions. Length must match the number of heights, sigmas, and gammas.
sigmas (list[float]) – List of the sigmas of the Voigt functions. Length must match the number of heights, centers, and gammas.
gammas (list[float]) – List of the gammas of the Voigt functions. Length must match the number of heights, centers, and sigmas.
- Returns:
The values of the Voigt function evaluated at the values of x.
- Return type:
np.ndarray
- pyfasma.deconvolution.voigt_profile(x: numpy.ndarray, height: float, center: float, fwhm_g: float, fwhm_l: float) numpy.ndarray ¶
Evaluate a Voigt function at the values of x given its amplitude, center, sigma, and gamma.
- Parameters:
x (np.ndarray) – The input values for which the Voigt function is evaluated.
height (float) – The height of the Voigt function.
center (float) – The center of the Voigt function.
sigma (float) – The sigma of the Voigt function (related to the Gaussian component).
gamma (float) – The gamma of the Voigt function (related to the Lorentzian component).
- Returns:
The values of the Voigt function evaluated at the values of x.
- Return type:
np.ndarray