10.5. Some Builtin Line-shape Functions

Changed in version 0.9.34: The definitions of these line shapes are now taken from the lmfit package, and have a more uniform interface.

Larch provides a number of convenience functions for common line-shapes used in fitting of experimental data. This list is not exhaustive, but can be amended easily. All these functions return either a floating point scalar or array, depending on the input x.

gaussian(x, amplitude=1, center=0, sigma=1)

a Gaussian or normal distribution function (see http://en.wikipedia.org/wiki/Normal_distribution), with three Parameters: amplitude, center, and sigma.

\[f(x; A, \mu, \sigma) = \frac{A}{\sigma\sqrt{2\pi}} e^{[{-{(x-\mu)^2}/{{2\sigma}^2}}]}\]

where the parameter amplitude corresponds to \(A\), center to \(\mu\), and sigma to \(\sigma\).

The full width at half maximum is \(2\sigma\sqrt{2\ln{2}}\), approximately \(2.3548\sigma\). The maximum height is \(A/(\sigma\sqrt{2\pi})\).

lorentzian(x, amplitude=1, center=0, sigma=1)

A Lorentzian or Cauchy-Lorentz distribution function (see http://en.wikipedia.org/wiki/Cauchy_distribution), with three Parameters: amplitude, center, and sigma.

\[f(x; A, \mu, \sigma) = \frac{A}{\pi} \big[\frac{\sigma}{(x - \mu)^2 + \sigma^2}\big]\]

where the parameter amplitude corresponds to \(A\), center to \(\mu\), and sigma to \(\sigma\). The full width at half maximum is \(2\sigma\). The maximum height is \(A/(\sigma\pi)\).

voigt(x, amplitude=1, center=0, sigma=1, gamma=None)

A Voigt distribution function (see http://en.wikipedia.org/wiki/Voigt_profile), with four Parameters: amplitude, center, sigma, and gamma defined as:

\[f(x; A, \mu, \sigma, \gamma) = \frac{A \textrm{Re}[w(z)]}{\sigma\sqrt{2\pi}}\]


\begin{eqnarray*} z &=& \frac{x-\mu +i\gamma}{\sigma\sqrt{2}} \\ w(z) &=& e^{-z^2}{\operatorname{erfc}}(-iz) \end{eqnarray*}

and erfc() is the complimentary error function. As above, the parameter amplitude corresponds to \(A\), center to \(\mu\), and sigma to \(\sigma\). With the default value of None, gamma (\(\gamma\)) is constrained to have value equal to sigma, though it can be varied independently. For the case when \(\gamma = \sigma\), the full width at half maximum is approximately \(3.6013\sigma\).

pvoigt(x, amplitude=1, center=0, sigma=1, fraction=0.5)

A pseudo-Voigt distribution function, which is a weighted sum of a Gaussian and Lorentzian distribution functions with the same values for amplitude (\(A\)) , center (\(\mu\)) and the same full width at half maximum (so constrained values of sigma`, \(\sigma\)). A paramater fraction (\(\alpha\)) controls controls the relative weight of the Gaussian and Lorentzian components, giving the full definition of

\[f(x; A, \mu, \sigma, \alpha) = \frac{(1-\alpha)A}{\sigma_g\sqrt{2\pi}} e^{[{-{(x-\mu)^2}/{{2\sigma_g}^2}}]} + \frac{\alpha A}{\pi} \big[\frac{\sigma}{(x - \mu)^2 + \sigma^2}\big]\]
pearson7(x, amplitude=1, center=0, sigma=1, exponent=0.5)

A Pearson VII distribution function (see http://en.wikipedia.org/wiki/Pearson_distribution#The_Pearson_type_VII_distribution), with four parameers: amplitude (\(A\)), center (\(\mu\)), sigma (\(\sigma\)), and exponent (\(m\)) in

\[f(x; A, \mu, \sigma, m) = \frac{A}{\sigma{\beta(m-\frac{1}{2}, \frac{1}{2})}} \bigl[1 + \frac{(x-\mu)^2}{\sigma^2} \bigr]^{-m}\]

where \(\beta\) is the beta function (see scipy.special.beta in scipy.special).

students_t(x, amplitude=1, center=0, sigma=1)

A Student’s t distribution function (see http://en.wikipedia.org/wiki/Student%27s_t-distribution), with three Parameters: amplitude (\(A\)), center (\(\mu\)) and sigma (\(\sigma\)) in

\[f(x; A, \mu, \sigma) = \frac{A \Gamma(\frac{\sigma+1}{2})} {\sqrt{\sigma\pi}\,\Gamma(\frac{\sigma}{2})} \Bigl[1+\frac{(x-\mu)^2}{\sigma}\Bigr]^{-\frac{\sigma+1}{2}}\]

where \(\Gamma(x)\) is the gamma function.

breit_wigner(x, amplitude=1, center=0, sigma=1, q=1)

A Breit-Wigner-Fano distribution function (see http://en.wikipedia.org/wiki/Fano_resonance>), with four Parameters: amplitude (\(A\)), center (\(\mu\)), sigma (\(\sigma\)), and q (\(q\)) in

\[f(x; A, \mu, \sigma, q) = \frac{A (q\sigma/2 + x - \mu)^2}{(\sigma/2)^2 + (x - \mu)^2}\]
lognormal(x, cen=0, sigma=1)

A Log-normal distribution function (see http://en.wikipedia.org/wiki/Lognormal), with three Parameters amplitude (\(A\)), center (\(\mu\)) and sigma (\(\sigma\)) in

\[f(x; A, \mu, \sigma) = \frac{A e^{-(\ln(x) - \mu)/ 2\sigma^2}}{x}\]

Several builtin special functions can also be used to create lineshapes useful in fitting spectra and other x-ray data. Some of these are detailed in the Table of Useful Line shapes.

Table of Useful Line shapes.

function description
gaussian(x, amplitude, center, sigma) Gaussian, normal distribution
lorentzian(x, amplitude, center, sigma) Lorentzian distribution
voigt(x, amplitude, center, sigma, gamma) Voigt distribution
pvoigt(x, amplitude, center, sigma, fraction) pseudo-Voigt distribution
pearson7(x, amplitude, center, sigma, exponent) Pearson-7 distribution
students_t(x, amplitude, center, sigma) Student’s t distribution
breit_wigner(x, amplitude, center, sigma, q) Breit-Wigner-Fano distribution
lognormal(x, amplitude, center, sigma) Log-normal distribution
arctan(x) Arc-tangent function
erf(x) Error function
erfc(x) Complemented Error function (1-erf(x))
gammaln(x) log of absolute value of gamma(x)

Other standard special functions (Bessel functions, Legendre polynomials, etc) can be accessed from scipy.special:

from scipy.special import j0 # Bessel function of order 0,
from scipy.special import y1 # Bessel function of second kind of order 1

A host of functions to generate other distribution functions can be accessed from scipy.stats.