def analysis.fitting_toolkit.find_peak (   data  ) 

Find a positive peak in a data set, using a robust parabolic fitter.

This looks for the highest channel in data and then fits a parabola to the half-height points around it. This tends to be a very stable way to find a peak, even on a somewhat sloping background, and with little knowledge of the real shape. It does require that the peak be wide enough that at least 3 points fit between its half-height points.

Parameters:
data either a list of ordinates (abscissas assumed to be integers starting at 0) or a list of x,y pairs.
find a positive peak in data, assuming the background is 0.  
Data can either be a list of (x,y) or just a list of y, in which case integer x is assumed.
find_peak returns xcenter, hwhm, height.  
Algorithm is parabolic fit to data between half-height points around max of data.  
This makes sense if hwhm > 1 channel, so at least 3 points
get included in the fit.  It breaks for peaks narrower than this, 
but in that case, using the highest point is about the best one can do, anyway. 

Definition at line 835 of file fitting_toolkit.py.

00835                    :
00836     """find a positive peak in data, assuming the background is 0.  
00837     Data can either be a list of (x,y) or just a list of y, in which case integer x is assumed.
00838     find_peak returns xcenter, hwhm, height.  
00839     Algorithm is parabolic fit to data between half-height points around max of data.  
00840     This makes sense if hwhm > 1 channel, so at least 3 points
00841     get included in the fit.  It breaks for peaks narrower than this, 
00842     but in that case, using the highest point is about the best one can do, anyway. 
00843     """
00844     da=array(data, numeric_float) #put it in a well-known format
00845     if type(data[0]) is type(1.0):
00846         x=range(len(data))
00847         y=data
00848     else:
00849         x=data[:,0]
00850         y=data[:,1]
00851     
00852     topchan=Numeric.argmax(y)
00853     topy=y[topchan]
00854     #find half-height points
00855     startx=topchan
00856     while(y[startx] >= 0.5*topy): startx -= 1
00857     endx=topchan
00858     while(y[endx] >= 0.5*topy): endx += 1
00859     
00860     #f=polynomial_fit(2, xcenter=x[topchan])
00861     f=find_peak_fitter
00862     f.fit_data(x[startx:endx+1], y[startx:endx+1], xcenter=x[topchan]) #clears the fitter and does  fit
00863     c,b,a=f.funcparams #a*(x-x0)^2+b*(x-x0)+c
00864     x0=-b/(2.0*a)+x[topchan]
00865     hwhm=math.sqrt(-c/(2.0*a))
00866     return x0, hwhm, c #returns center, hwhm, height
00867             
##


Generated on Wed Nov 21 10:18:32 2007 for analysis by  doxygen 1.5.4