Package park :: Package util :: Module peaks

Module peaks

source code

Peaks and backgrounds.

Available peaks and backgrounds:

gauss, lorentz, voigt, quadratic
constant, linear

The functions are standardized to unit height at zero, but can be adjusted with center, scale and width parameters.

Models corresponding to these use uppercase names. E.g.:

gauss(x, sigma=3, center=2, scale=4)

corresponds to:

m = Gauss(sigma=3, center=2, scale=4)
m(x)

The models define derivatives with respect to the parameters for the individual evaluation points x. E.g.:

m.dsigma(x)
Classes
  Gauss
Gauss peak: scale exp ( -0.5 (x-center)**2 / sigma**2 )
  Lorentz
Lorentz peak (HWHM): scale/pi gamma/((x-center)**2 + gamma**2)
  Voigt
Voigt peak (HWHM,sigma): A [G(sigma) * L(gamma)](x-center)
  Quadratic
Quadratic peak (HWHM): 1 - 1/2 ((x-c)/w)**2
  Linear
Linear background: scale (x - center + 1)
  Constant
Constant background: scale
Functions
 
gauss(x, sigma=1, center=0, scale=1)
Gauss peak.
source code
 
lorentz(x, gamma=1, center=0, scale=1)
Lorentz peak.
source code
 
voigt(x, sigma=1, gamma=1, center=0, scale=1)
Voigt peak.
source code
 
quadratic(x, width=1, center=0, scale=0)
Quadratic peak.
source code
 
linear(x, center=0, scale=1)
Sloping background.
source code
 
constant(x, scale=0)
Constant background.
source code
Function Details

gauss(x, sigma=1, center=0, scale=1)

source code 

Gauss peak.

The formula used to calculate this is:

G(x) = exp( -0.5 (x-center)**2 / sigma**2 )
Parameters:
  • sigma (real) - The 1-sigma width of the Gaussian
  • center (real) - Location of the center of the peak
  • scale (real) - Value at the highest point of the peak

lorentz(x, gamma=1, center=0, scale=1)

source code 

Lorentz peak.

The formula used to calculate this is:

L(x) = scale/pi  gamma/((x-center)**2 + gamma**2)
Parameters:
  • gamma (real) - Half-width at half-maximum peak width
  • center (real) - Location of the center of the peak
  • scale (real) - Value at the highest point of the peak

voigt(x, sigma=1, gamma=1, center=0, scale=1)

source code 

Voigt peak.

The voigt peak is the convolution of a Lorentz peak with a Gaussian peak.

The formula used to calculate this is:

z(x) = (x + 1j gamma) / (sqrt(2) sigma)
w(z) = exp(-z**2) erfc(-1j z) / (sqrt(2 pi) sigma)

V(x) = scale Re(w(z(x-center)))

Ref: W.I.F. David, J. Appl. Cryst. (1986). 19, 63-64

Note: adjusted to use stddev and HWHM rather than FWHM parameters

Parameters:
  • gamma (real) - The half-width half-maximum of the Lorentzian
  • sigma (real) - The 1-sigma width of the Gaussian, which is one standard deviation.
  • center (real) - Location of the center of the peak
  • scale (real) - Value at the highest point of the peak

quadratic(x, width=1, center=0, scale=0)

source code 

Quadratic peak.

The formula used to calculate this is:

Q(x) = A ( 1 - ( (x - c)/w )**2 / 2 )  if |x-c| < w sqrt(2)
Q(x) = 0                               otherwise
Parameters:
  • width (real) - The half-width half-maximum of the quadratic
  • center (real) - Location of the center of the peak
  • scale (real) - Value at the highest point of the peak

linear(x, center=0, scale=1)

source code 

Sloping background.

The background has unit height at zero.

The formula used to calculate this is:

S(x) = scale ( x - center + 1)
Parameters:
  • center (real) - Location of the zero crossing
  • scale (real) - Slope of the line

constant(x, scale=0)

source code 

Constant background.

The formula used to calculate this is:

C(x) = scale
Parameters:
  • scale (real) - Value at the highest point of the peak