Peak models
As for the background models, the peak models in Fitspy are issued either from predefined models, or by he user-defined models.
Predefined models
The predefined peak models available in Fitspy relies on the following parameters:
\(x0\) : the peak position
\(ampli\) : the peak amplitude
\(fwhm\) : the Full Width at Half Maximum
\(fwhm_l\) : the fwhm at the left side of x0 (for the asymmetric models)
\(fwhm_r\) : the fwhm at the right side of x0 (for the asymmetric models)
\(alpha\) : weighting coefficient (used in the Pseudovoigt model)
Gaussian
Lorentzian
Asymetric Gaussian
Asymetric Lorentzian
Pseudovoigt
User-defined models
As for the background, users models can be defined through literal expressions in a ‘.txt’ file or from python scripts in a ‘.py’ file.
Example of a model defined by a literal expression:
Gaussian_1 = ampli * exp(-(x - x0) ** 2 / (fwhm**2 / (4 * log(2))))
Example of a model defined in python:
import numpy as np
from lmfit.models import GaussianModel
from fitspy import PEAK_MODELS
LMFIT_GAUSSIAN_MODEL = GaussianModel()
def gaussian_2(x, ampli, fwhm, x0):
sigma = fwhm / (2. * np.sqrt(2. * np.log(2.)))
coef = 1. / (2 * sigma ** 2)
return ampli * np.exp(-coef * (x - x0) ** 2)
def gaussian_3(x, x0, ampli, fwhm):
sigma = fwhm / (2. * np.sqrt(2. * np.log(2.)))
return sigma * np.sqrt(2. * np.pi) * LMFIT_GAUSSIAN_MODEL.eval(x=x, center=x0, amplitude=ampli, sigma=sigma)
PEAK_MODELS.update({"Gaussian_2": gaussian_2})
PEAK_MODELS.update({"Gaussian_3": gaussian_3})
where in the examples given above, the resulting Gaussian_1
, Gaussian_2
and Gaussian_3
yield identical results to those obtained from the predefined Gaussian
model.
As with the background models:
Through the GUI, the corresponding ‘.txt’ or ‘.py’ files can be loaded via the button Load
located to the right of the MODEL combobox.
In python, the users models can be loaded by the functions load_models_from_txt()
and load_models_from_py()
.
(See example in ex_gui_users_defined_models.py )
For recurrent use, the user-defined models can be defined in files named peak_models.txt
or peak_models.py
to put in %HOMEUSER%/Fitspy
.
Warning
The users models can be defined with parameters that differ from those used in the predefined models. In such cases, these parameters are initialized to 1 for the fitting process and are not subject to any range limitations.
However, it is strongly recommended to use the same parameters as much as possible as those used in the predefined models.