Closedown
This commit is contained in:
@@ -17,50 +17,8 @@ def get_energy():
|
||||
return e
|
||||
|
||||
|
||||
#Fitting
|
||||
|
||||
from mathutils import estimate_peak_indexes, fit_gaussians, create_fit_point_list, Gaussian
|
||||
import java.awt.Color as Color
|
||||
|
||||
def fit(ydata, xdata = None):
|
||||
if xdata is None:
|
||||
xdata = frange(0, len(ydata), 1)
|
||||
max_y= max(ydata)
|
||||
index_max = ydata.index(max_y)
|
||||
max_x= xdata[index_max]
|
||||
print "Max index:" + str(index_max),
|
||||
print " x:" + str(max_x),
|
||||
print " y:" + str(max_y)
|
||||
|
||||
gaussians = fit_gaussians(ydata, xdata, [index_max,])
|
||||
(norm, mean, sigma) = gaussians[0]
|
||||
|
||||
p = plot([ydata],["data"],[xdata], context="Fit" )[0]
|
||||
fitted_gaussian_function = Gaussian(norm, mean, sigma)
|
||||
scale_x = [float(min(xdata)), float(max(xdata)) ]
|
||||
points = max((len(xdata)+1), 100)
|
||||
resolution = (scale_x[1]-scale_x[0]) / points
|
||||
fit_y = []
|
||||
fit_x = frange(scale_x[0],scale_x[1],resolution, True)
|
||||
for x in fit_x:
|
||||
fit_y.append(fitted_gaussian_function.value(x))
|
||||
p.addSeries(LinePlotSeries("fit"))
|
||||
p.getSeries(1).setData(fit_x, fit_y)
|
||||
|
||||
print "---"
|
||||
print mean, xdata[index_max], abs(mean - xdata[index_max])
|
||||
print scale_x, (scale_x[0] + scale_x[1])/2, abs((scale_x[0] + scale_x[1])/2)
|
||||
print abs(mean - xdata[index_max]) < abs((scale_x[0] + scale_x[1])/2)
|
||||
if abs(mean - xdata[index_max]) < abs((scale_x[0] + scale_x[1])/2):
|
||||
print "Mean -> " + str(mean)
|
||||
p.addMarker(mean, None, "Mean="+str(round(mean,2)), Color.MAGENTA.darker())
|
||||
return (norm, mean, sigma)
|
||||
else:
|
||||
p.addMarker(max_x, None, "Max="+str(round(max_x,2)), Color.GRAY)
|
||||
print "Invalid gaussian fit: " + str(mean)
|
||||
return (None, None, None)
|
||||
|
||||
|
||||
run("fit")
|
||||
run("rock")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user