File: doc_peakmodels.py

package info (click to toggle)
lmfit-py 0.8.0%2Bdfsg.1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,776 kB
  • ctags: 1,203
  • sloc: python: 7,041; makefile: 102; sh: 43
file content (37 lines) | stat: -rw-r--r-- 779 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
#<examples/doc_peakmodels.py>
from numpy import loadtxt
from lmfit.models import LorentzianModel, GaussianModel, VoigtModel
import matplotlib.pyplot as plt

data = loadtxt('test_peak.dat')
x = data[:, 0]
y = data[:, 1]

MODEL = 'gauss'
MODEL = 'loren'
MODEL = 'voigt'
# gamma_free = False
gamma_free = True

if MODEL.lower().startswith('g'):
    mod = GaussianModel()
elif MODEL.lower().startswith('l'):
    mod = LorentzianModel()
elif MODEL.lower().startswith('v'):
    mod = VoigtModel()

pars = mod.guess(y, x=x)

if gamma_free:
    pars['gamma'].set(value=0.7, vary=True, expr='')

out = mod.fit(y, pars, x=x)
print(out.fit_report(min_correl=0.25))

plt.plot(x, y,  'b-')
plt.plot(x, out.best_fit,  'r-')
plt.show()


#<end examples/doc_peakmodels.py>