-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
31 lines (26 loc) · 955 Bytes
/
test.py
File metadata and controls
31 lines (26 loc) · 955 Bytes
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
''' Simple fit without fit error estimation.
For correct fit errors check the advanced example.
Bound should be defined. Eta has to be > 1.
'''
from scipy.optimize import curve_fit
import matplotlib.pyplot as plt
import numpy as np
import pylandau
# Create fake data with possion error
mpv, eta, sigma, A = 30, 5, 4, 1000
x = np.arange(0, 100, 0.5)
y = pylandau.langau(x, mpv, eta, sigma, A)
yerr = np.random.normal(np.zeros_like(x), np.sqrt(y))
yerr[y < 1] = 1
y += yerr
# Fit with constrains
coeff, pcov = curve_fit(pylandau.langau, x, y,
sigma=yerr,
absolute_sigma=True,
p0=(mpv, eta, sigma, A),
bounds=(1, 10000))
# Plot
plt.errorbar(x, y, np.sqrt(pylandau.langau(x, *coeff)), fmt=".")
print coeff
plt.plot(x, pylandau.langau(x, *coeff), "-")
plt.show()