31 lines
1.0 KiB
Python
Executable File
31 lines
1.0 KiB
Python
Executable File
"""
|
|
Function fitting and peak search with mathutils facade
|
|
"""
|
|
from mathutils import fit_gaussian, Gaussian
|
|
from plotutils import plot_function, plot_data
|
|
import math
|
|
|
|
|
|
ydata = [0, 1,2,3,4,5,6,7,8,9,8,7,6,5,4,4,3,3,2,2,1,0]
|
|
xdata = range(len(ydata))
|
|
|
|
|
|
|
|
(normalization, mean, sigma) = fit_gaussian(readable, positions)
|
|
fitted_gaussian_function = Gaussian(normalization, mean, sigma)
|
|
print (normalization, mean, sigma)
|
|
|
|
|
|
fit = []
|
|
resolution = float(xdata[0] - xdata[1])/100
|
|
xfit = frange(start,end,resolution, True)
|
|
for x in xfit:
|
|
fit.append(fitted_gaussian_function.value(x))
|
|
|
|
|
|
peaks = calculate_peaks(fitted_polynomial_function, start, end)
|
|
|
|
#plots = plot([ydata, fit],["data", "gaussian"], xdata = [xdata,xfit], title="Fit")
|
|
#plots[0].addMarker(mean, None, "Mean=" + str(round(mean,2)), java.awt.Color.LIGHT_GRAY)
|
|
|
|
p = plot(None, title="Fit")[0]
|
|
plot_data(p, ydata, "Data", xdata=xdata, show_points = True, color=Color.BLUE)
|
|
plot_function(p, fitted_gaussian_function, "Fit", range, show_points=False, color=Color.RED) |