File: model1d_doc2.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 (38 lines) | stat: -rw-r--r-- 801 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
38
import numpy as np
from lmfit.old_models1d import  GaussianModel, VoigtModel
import matplotlib.pyplot as plt

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

model = VoigtModel(background='linear')

# get default starting values, but then alter them
model.guess_starting_values(y, x=x)
model.params['amplitude'].value = 2.0

init_fit = model.model(x=x)

# the actual fit
model.fit(y, x=x)

print model.fit_report(min_correl=0.25)

vfit = model.model(x=x)


mod2 = GaussianModel(background='linear')

mod2.fit(y, x=x)
gfit = mod2.model(x=x)

print mod2.fit_report(min_correl=0.25)

print 'Voigt    Sum of Squares: ', ((vfit - y)**2).sum()
print 'Gaussian Sum of Squares: ', ((gfit - y)**2).sum()

plt.plot(x, vfit, 'r-')
plt.plot(x, gfit, 'b-')
plt.plot(x, y,    'bo')
plt.show()