45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
"""
|
|
Multi-peak search and gaussian fitting
|
|
"""
|
|
|
|
from mathutils import estimate_peak_indexes, fit_gaussians, create_fit_point_list
|
|
|
|
start = 1
|
|
end = 30
|
|
step_size = 0.2
|
|
|
|
result= lscan(sout,sinp,start,end,[step_size,],0.05)
|
|
|
|
path = get_current_data_group()
|
|
set_attribute(path, "ApertureX", apertureX.read())
|
|
|
|
readable = result.getReadable(0)
|
|
positions = result.getPositions(0)
|
|
|
|
threshold = (min(readable) + max(readable))/2
|
|
min_peak_distance = 5.0
|
|
|
|
peaks = estimate_peak_indexes(readable, positions, threshold, min_peak_distance)
|
|
print "Peak indexes: " + str(peaks)
|
|
print "Peak x: " + str(map(lambda x:positions[x], peaks))
|
|
print "Peak y: " + str(map(lambda x:readable[x], peaks))
|
|
|
|
log("Highest peak index = " +str(peaks[0]))
|
|
|
|
#Manually adding a dataset
|
|
data = [ [1,2,3,4,5], [2,3,4,5,6], [3,4,5,6,7]]
|
|
path="group/data2"
|
|
save_dataset(path, data)
|
|
|
|
gaussians = fit_gaussians(readable, positions, peaks)
|
|
|
|
|
|
plots = plot([readable],["Multi-peak search"],[positions])
|
|
for i in range(len(peaks)):
|
|
peak = peaks[i]
|
|
(norm, mean, sigma) = gaussians[i]
|
|
if abs(mean - positions[peak]) < min_peak_distance:
|
|
print "Peak -> " + str(mean)
|
|
plots[0].addMarker(mean, None, "N="+str(round(norm,2)), None)
|
|
else:
|
|
print "Invalid gaussian fit: " + str(mean) |