Implemented Models in SpectraFit¶
SpectraFit provides a wide range of mathematical models for fitting spectroscopic data. This page documents all the available models, their parameters, and examples of their use.
About implemented modxels
In principle, every model can bexx implemented in SpectraFit by extending the module spectrafit.models
with new functions. It is important to extend the raise
check in both solver_model
and calculated_model
for new function names.
See the lmfit custom model example for more details.
Section navigation
Use the navigation on the left to quickly jump between model types, constants, and visualization examples.
Model Notation Reference¶
Method | Old Notation | New Notation |
---|---|---|
Gaussian-FWHM | fwhm | fwhmg |
Lorentzian-FWHM | fwhm | fwhml |
Pseudo-Voigt | fwhm_g | fwhmg |
Pseudo-Voigt | fwhm_l | fwhml |
Voigt | fwhm | fwhmv |
List of Implemented Models¶
Bell-shaped curve widely used for modeling spectral peaks.
Distribution with wider tails than Gaussian, common in resonance phenomena.
Linear combination of Gaussian and Lorentzian profiles.
Convolution of Gaussian and Lorentzian profiles.
Model for exponential decay or growth processes.
Function with a variable exponent.
Basic linear background model.
Flat background with a single amplitude parameter.
Sigmoid curve used for step-like transitions.
Step function for modeling abrupt changes.
Smooth transition function.
Natural logarithm function for transforming data.
Gaussian distribution with complex component.
Lorentzian distribution with complex component.
Voigt distribution with complex component.
Quadratic polynomial for curved backgrounds.
Cubic polynomial for more complex backgrounds.
Beta distribution for asymmetric peaks.
Special case of Type I with symmetric shape.
Gamma distribution for asymmetric peaks.
Flexible distribution with four parameters.
Peak Distribution Models¶
Gaussian Distribution¶
The Gaussian distribution is a symmetric bell-shaped curve defined by its amplitude, center, and width:
\[f(x) = \frac{A}{\sigma\sqrt{2\pi}} \exp\left(-\frac{(x-\mu)^2}{2\sigma^2}\right)\]
Where:
- \(A\) is the amplitude
- \(\mu\) is the center (mean)
- \(\sigma\) is related to the full width at half maximum (FWHM) by \(\text{FWHM} = 2\sigma\sqrt{2\ln{2}}\)
Gaussian Model Parameters
Lorentzian Distribution¶
The Lorentzian distribution, also known as the Cauchy distribution, is characterized by wider tails compared to the Gaussian distribution:
\[f(x) = \frac{A}{\pi} \frac{\gamma}{(x-x_0)^2 + \gamma^2}\]
Where:
- \(A\) is the amplitude
- \(x_0\) is the center
- \(\gamma\) is the half-width at half-maximum (HWHM)
Lorentzian Model Parameters
Pseudo-Voigt Distribution¶
The Pseudo-Voigt distribution is a linear combination of Gaussian and Lorentzian distributions:
\[f(x) = \eta \cdot L(x) + (1-\eta) \cdot G(x)\]
Where:
- \(\eta\) is the mixing parameter (calculated from fwhmg and fwhml)
- \(L(x)\) is the Lorentzian component
- \(G(x)\) is the Gaussian component
Pseudo-Voigt Model Parameters
Voigt Distribution¶
The Voigt distribution is the convolution of a Gaussian and a Lorentzian distribution:
\[f(x) = \int_{-\infty}^{\infty} G(x') \cdot L(x-x') dx'\]
This distribution is implemented using the Faddeeva function.
Voigt Model Parameters
Background Models¶
Exponential Function¶
\[f(x) = A \cdot \exp(b \cdot x + c)\]
Power Function¶
\[f(x) = A \cdot x^b + c\]
Linear Function¶
\[f(x) = A \cdot x + b\]
Constant Function¶
\[f(x) = A\]
Step Functions¶
Error Function¶
\[f(x) = A \cdot \text{erf}\left(\frac{x-\mu}{\sigma\sqrt{2}}\right) + b\]
Heaviside Function¶
\[f(x) = A \cdot H(x-x_0) + b\]
Where \(H\) is the Heaviside step function.
Arctangent Function¶
\[f(x) = A \cdot \tan^{-1}\left(\frac{x-x_0}{w}\right) + b\]
Other Functions¶
Logarithmic Function¶
\[f(x) = A \cdot \ln(b \cdot x + c) + d\]
Complex Gaussian¶
Gaussian distribution with a complex component.
Complex Lorentzian¶
Lorentzian distribution with a complex component.
Complex Voigt¶
Voigt distribution with a complex component.
Polynomial (2nd Order)¶
\[f(x) = a_0 + a_1 \cdot x + a_2 \cdot x^2\]
Polynomial (3rd Order)¶
\[f(x) = a_0 + a_1 \cdot x + a_2 \cdot x^2 + a_3 \cdot x^3\]
Pearson Distributions¶
Pearson Type I¶
Beta distribution with flexible shape parameters.
Pearson Type II¶
Special case of Type I with symmetric shape.
Pearson Type III¶
Gamma distribution for asymmetric peaks.
Pearson Type IV¶
Flexible distribution with four parameters.
Important Constants for the Models¶
For calculating the models, a few math constants are needed, which are implemented in the constants
module.
Mathematical constants for the curve models.
Constants
-
Natural logarithm of 2
\[ ln2 = \log{2} \]
-
Square root of 2 times pi
\[ sq2pi = \sqrt{2 \pi} \]
-
Square root of pi
\[ sqpi = \sqrt{ \pi} \]
-
Square root of 2
\[ sq2 = \sqrt{2} \]
-
Full width at half maximum to sigma for Gaussian
\[ fwhmg2sig = \frac{1}{ 2 \sqrt{2\log{2}}} \]
-
Full width at half maximum to sigma for Lorentzian
\[ fwhml2sig = \frac{1}{2} \]
-
Full width at half maximum to sigma for Voigt according to the article by Olivero and Longbothum1, check also XPSLibary website.
$$ fwhm_{text{Voigt}} approx 0.5346 cdot fwhm_{text{Gaussian}} + sqrt{ 0.2166 fwhm_{text{Lorentzian}}^2 + fwhm_{text{Gaussian}}^2 }
$$
In case of equal FWHM for Gaussian and Lorentzian, the Voigt FWHM can be defined as:
\[ fwhm_{\text{Voigt}} \approx 1.0692 + 2 \sqrt{0.2166 + 2 \ln{2}} \cdot \sigma \]
\[ fwhmv2sig = \frac{1}{fwhm_{\text{Voigt}}} \]
-
J.J. Olivero, R.L. Longbothum, Empirical fits to the Voigt line width: A brief review, Journal of Quantitative Spectroscopy and Radiative Transfer, Volume 17, Issue 2, 1977, Pages 233-236, ISSN 0022-4073, doi.org/10.1016/0022-4073(77)90161-3. ↩
Source code in spectrafit/models.py
@dataclass(frozen=True)
class Constants:
r"""Mathematical constants for the curve models.
!!! info "Constants"
1. Natural logarithm of 2
$$
ln2 = \log{2}
$$
2. Square root of 2 times pi
$$
sq2pi = \sqrt{2 \pi}
$$
3. Square root of pi
$$
sqpi = \sqrt{ \pi}
$$
4. Square root of 2
$$
sq2 = \sqrt{2}
$$
5. Full width at half maximum to sigma for Gaussian
$$
fwhmg2sig = \frac{1}{ 2 \sqrt{2\log{2}}}
$$
6. Full width at half maximum to sigma for Lorentzian
$$
fwhml2sig = \frac{1}{2}
$$
7. Full width at half maximum to sigma for Voigt according to the article by
Olivero and Longbothum[^1], check also
[XPSLibary website](https://xpslibrary.com/voigt-peak-shape/).
$$
fwhm_{\text{Voigt}} \approx 0.5346 \cdot fwhm_{\text{Gaussian}} +
\sqrt{ 0.2166 fwhm_{\text{Lorentzian}}^2 + fwhm_{\text{Gaussian}}^2 }
$$
In case of equal FWHM for Gaussian and Lorentzian, the Voigt FWHM can be
defined as:
$$
fwhm_{\text{Voigt}} \approx 1.0692 + 2 \sqrt{0.2166 + 2 \ln{2}} \cdot \sigma
$$
$$
fwhmv2sig = \frac{1}{fwhm_{\text{Voigt}}}
$$
[^1]:
J.J. Olivero, R.L. Longbothum,
_Empirical fits to the Voigt line width: A brief review_,
**Journal of Quantitative Spectroscopy and Radiative Transfer**,
Volume 17, Issue 2, 1977, Pages 233-236, ISSN 0022-4073,
https://doi.org/10.1016/0022-4073(77)90161-3.
"""
ln2 = log(2.0)
sq2pi = sqrt(2.0 * pi)
sqpi = sqrt(pi)
sq2 = sqrt(2.0)
fwhmg2sig = 1 / (2.0 * sqrt(2.0 * log(2.0)))
fwhml2sig = 1 / 2.0
fwhmv2sig = 1 / (2 * 0.5346 + 2 * sqrt(0.2166 + log(2) * 2))
Visualization of the Models¶
About Peaks' Components
Comparing components of the peaks in a table is important for identifying trends, patterns, and outliers in your data. Having this information in a table format makes it easier to visualize, interpret, and communicate results.
This can be seen in example9_3.ipynb.
This provides an interactive table and allows exporting the iterative results as a CSV file.Download Peak Components Example CSV
The following dataset demonstrates the structure of exported peak components. You can download and explore it:
This CSV contains columns for each parameter and rows for initial, model, and best values.