1 """Utility mathematical functions and common lineshapes for minimizer
2 """
3 import numpy
4 import scipy
5 from scipy.special import gamma
6
7 CUSTOM_FUNCTIONS = {}
8
9 log2 = numpy.log(2)
10 pi = numpy.pi
11
12 -def gauss(x, amp, cen, wid):
13 "gaussian function: wid = half-width at half-max"
14 return amp * numpy.exp(-log2 * (x-cen) **2 / wid**2)
15
16 -def loren(x, amp, cen, wid):
17 "lorenztian function: wid = half-width at half-max"
18 return (amp / (1 + ((x-cen)/wid)**2))
19
21 "scaled gaussian function: wid = half-width at half-max"
22 return numpy.sqrt(log2/pi) * gauss(x, amp, cen, wid) / wid
23
25 "scaled lorenztian function: wid = half-width at half-max"
26 return loren(x, amp, cen, wid) / (pi*wid)
27
28 -def pvoigt(x, amp, cen, wid, frac):
29 """pseudo-voigt function:
30 (1-frac)*gauss(amp, cen, wid) + frac*loren(amp, cen, wid)"""
31 return amp * (gauss(x, (1-frac), cen, wid) +
32 loren(x, frac, cen, wid))
33
35 """scaled pseudo-voigt function:
36 (1-frac)*gauss_area(amp, cen, wid) + frac*loren_are(amp, cen, wid)"""
37
38 return amp * (gauss_area(x, (1-frac), cen, wid) +
39 loren_area(x, frac, cen, wid))
40
42 """pearson peak function """
43 xp = 1.0 * expon
44 return amp / (1 + ( ((x-cen)/wid)**2) * (2**(1/xp) -1) )**xp
45
46
48 """scaled pearson peak function """
49 xp = 1.0 * expon
50 scale = gamma(xp) * sqrt((2**(1/xp) - 1)) / (gamma(xp-0.5))
51 return scale * pearson7(x, amp, cen, wid, xp) / (wid*sqrt(pi))
52
53 return scale * pearson7(x, amp, cen, sigma, expon) / (sigma*sqrt(pi))
54
55 CUSTOM_FUNCTIONS = {'gauss': gauss, 'gauss_area': gauss_area,
56 'loren': loren, 'loren_area': loren_area,
57 'pvoigt': pvoigt, 'pvoigt_area': pvoigt_area,
58 'pearson7': pearson7, 'pearson7_area': pearson7_area}
59