Source
xxxxxxxxxx
36
36
def gauss_func(x, *p):
37
37
amp, center, width, offset = p
38
38
y = amp * numpy.exp(-(x - center)**2 / (2. * width**2)) + offset
39
39
return y
40
40
41
41
42
42
def gauss_fit(x, y):
43
43
# initial guess
44
44
o = y.mean()
45
45
a = numpy.abs(y - o).max()
46
-
c = x[numpy.where(numpy.abs(y - o) == a)[0]]
46
+
c = x[numpy.where(numpy.abs(y - o) == a)[0]][0]
47
47
w = numpy.abs(y - o).sum() / a
48
48
#print("initial guess: (%f, %f, %f, %f)" % (a,c,w,o))
49
49
return curve_fit(gauss_func, x, y, p0=(a, c, w, o))
50
50
51
51
52
52
# a named tuple to store spectral information.
53
53
# start, end: start and end of a channel range
54
54
# max, min: max and min value of the channel range
55
55
# peak, center, width: gaussian fit parameters of the channel range
56
56
SpectralInfo = namedtuple('SpectralInfo',