fit
index
/home/oxygen3/CHA/epics/extensions/lang/python/fit.py

# fit.py :      GUI for the module Scientific.Functions.LeastSquares
#               Implementation of the Levenberg-Marquardt algorithm for general
#               non-linear least-squares fits.
#
#  from fit import *
#  root = Tk()
#  data = [1.,2.,3.,4.1, ...]
#  fit(data)
#

 
Modules
       
matplotlib
pylab
Numeric
numarray
Scientific.Functions
string
sys
os
Ttkinter
Pmw
plotAscii

 
Classes
       
Tkinter.Frame(Tkinter.Widget)
FitDialog

 
class FitDialog(Tkinter.Frame)
    
Method resolution order:
FitDialog

Methods defined here:
__init__(self, master=None)
apply(self)
apply(self) - accept fit id and coeffs and pass data to fit calculation
createDialog(self, top)
createDialog(self,top) - create multiple fitting functions dialog
top - specify the parent widget
createPolyDialog(self, top, title)
createPolyDialog(self,top,title) - create polynomial fitting dialog
top - specify parent widget
e.g. power 4 polynomial
A0 * x**4 + a1 * x**3 + a2 * x**2 + a3 * x + a4
destroy(self)
destroy(self) - close multiple fitting functions dialog
initcoeffs(self)
initcoeffs(self) - initialize fit coeffs according fit function id #
polydestroy(self)
polydestroy(self) - destory polynomial fit dialog
runpolyfit(self)
runpolyfit(self) - accept pow # and perform polynomial fit
setfitid(self)
setfitid(self) - set fit function id and initialize fit coeffs
setlegend(self)
setlegend(self) - check for writing fit coeffs legend on plot

 
Functions
       
arange(...)
arange(start, stop=None, step=1, typecode=None)
 
 Just like range() except it returns an array whose type can be
specified by the keyword argument typecode.
array(...)
array(sequence, typecode=None, copy=1, savespace=0) will return a new array formed from the given (potentially nested) sequence with type given by typecode.  If no typecode is given, then the type will be determined as the minimum type required to hold the objects in sequence.  If copy is zero and sequence is already an array, a reference will be returned.  If savespace is nonzero, the new array will maintain its precision in operations.
arrayrange = arange(...)
arange(start, stop=None, step=1, typecode=None)
 
 Just like range() except it returns an array whose type can be
specified by the keyword argument typecode.
calcfwhm(x, y)
calcfwhm(x,y) - with input x,y vector this function calculate fwhm and return (fwhm,xpeak,ymax)
x - input independent variable
y - input dependent variable
fwhm - return full width half maximum
xpeak - return x value at y = ymax
choose(...)
choose(a, (b1,b2,...))
closewin(event)
closewin(event) - if right mouse event close the plot window
cross_correlate(...)
cross_correlate(a,v, mode=0)
empty(...)
empty((d1,...,dn),typecode='l',savespace=0) will return a new array
of shape (d1,...,dn) and given type with all its entries uninitialized.  If savespace is
nonzero, the array will be a spacesaver array.  This can be faster than zeros.
fit(data=None, title=None)
fit(data=None,title=None) - least square fitting dialog for input data vector
data - speicify a list of (x,y) vector to be fitted
title - specify the title of fit dialog window to be used
fit_allometric(parameters, values)
parameters = a, x0, c
values = x
return(a * (x-x0)**2 + c )
fit_boltzman(parameters, values)
parameters = x0, a1, a2, dx
values = x
return((a1-a2) /(1 + exp((x-x0)/dx)) + a2)
fit_cuadratic(parameters, values)
parameters = x0, a, b, c
values = x
return( a *(x-x0)**2 + b*(x-x0) + c )
fit_expassoc(parameters, values)
parameters = y0, a1, t1, a2, t2
values = x
return( y0 + a1 * (1+ exp(-t/t1)) + a2 * (1+ exp(-x/t2)) )
fit_expdecay(parameters, values)
parameters = x0, y0, a, t
values = x
return( y0 + a * exp(-(x-x0)/t) )
fit_expgrow(parameters, values)
parameters = x0, y0, a, t
values = x
return( y0 + a * exp((x-x0)/t) )
fit_gauss(parameters, values)
parameters = a, x0, w, y0
values = x
return( a * exp(-2*(x-x0)**2/w**2) + y0 )
fit_gaussamp(parameters, values)
parameters = a, x0, w, y0
values = x
return( a * exp(-(x-x0)**2/(2*w**2)) + y0 )
fit_hyperbl(parameters, values)
parameters = p1, p2
values = x
return( p1 * x /(p2 + x) )
fit_linear(parameters, values)
parameters = a, b
values = x
return( a + b * x )
fit_logistic(parameters, values)
parameters = x0, a1, a2, p
values = x
return( (a1-a2)/(1+(x/x0)**p) + a2 )
fit_lorentz(parameters, values)
parameters = a, x0, w
values = x
return( a * w**2 / ((x-x0)**2 + w**2) )
fit_pulse(parameters, values)
parameters = x0, y0, a, t1, t2
values = x
return( y0 + a*(1+exp(-(x-x0)/t1))* exp(-(x-x0)/t2) )
fit_rational0(parameters, values)
parameters = a, b, c
values = x
return( (b + c*x)/(1 + a*x) )
fit_sine(parameters, values)
parameters = x0, a, w
values = x
return( a * sin( pi*(x-x0)/w ) )
fitdata(data, xl=None, xr=None)
fitdata(data,xl=None,xr=None) - construct and return fit data list tuple [(X,Y),...]
data - input list of Y vector with N data points 
xl   - specify start X value at data[0], default to 1
xr   - specify end X value at data[N-1], default to N the number of 
        data points in Y data vector
fitdialog(root,data=None, title=None)
fitdialog(root,data=None) - function fit dialog with specified input data list
root - specify the parent widget
data - specify the input  Y, or (X,Y) data list to be fitted
title - if specified it overrides the default window title
fithelp()
fithelp() - help info about fit.py
fittedData(f, x, y1, y2, ret, title=None)
fittedData(f,x,y1,y2,ret,title=None) - pop up text window to display fitted result
f - specify fitting function structure dictionary used
x - raw dependent X vector data
y1 - raw independent Y vector data
y2 - fitted function returned Y vector
ret - values returned by leastSquaresFit
title - specify tile used by pop up display window
fitting(fn, data, parms=None, steps=None)
fitting(fn,data,parms=None,steps=None) -
This function uses leastSquaresFit to calculate the fitting 
coefficients with user specified fitting function
fn    - function name defined in fitting functions directory
data  - specified the (x,y) data list to be fitted
steps - maximum number of iteration steps allowed
parms - returns the fitted parmeters
errs  - fitting least square  error returned
fromstring(...)
fromstring(string, typecode='l', count=-1) returns a new 1d array initialized from the raw binary data in string.  If count is positive, the new array will have count elements, otherwise it's size is determined by the size of string.
initFit()
initFit() - initialize global variable FIT
maketrans(...)
maketrans(frm, to) -> string
 
Return a translation table (a string of 256 bytes long)
suitable for use in string.translate.  The strings frm and to
must be of the same length.
pickFile()
pickFile() - use file selection dialog to load in Ascii data array
pickVect()
pickVect() - pick (X,Y) pair vector out of ascii column data array to be fitted
plotfitting(f, x, y1, y2, ret, legd=None)
        plotfitting(f,x,y1,y2,ret,legd=None) - this function use pylab plot 
routine to do fitted plot
        f - specify the fitted function 
        x - independent x array
        y1 - dependent data arry
        y2 - fitted dependent array
        ret - coeffs and err list returned by the leastSquareFit function
        ledg - indicator whether to record fit function and coefficients on plot
polyfitdialog(root, data=None, title=None)
polyfitdialog(root,data=None) - polynomial fit dialog with specified input data list
root - specify the parent widget
data - specify the input Y or (X,Y) data list to be fitted
reshape(...)
reshape(a, (d1, d2, ..., dn)).  Change the shape of a to be an n-dimensional array with dimensions given by d1...dn.  Note: the size specified for the new array must be exactly equal to the size of the  old one or an error will occur.
searchsorted = binarysearch(...)
binarysearch(a,v)
take(...)
take(a, indices, axis=0).  Selects the elements in indices from array a along the given axis.
testfit(self, data=None, fn=None, parms=None, legd=None, steps=None)
testfit(self,data=None,fn=None,parms=None,legd=None,steps=None) -
this function try to fit the data with user picked function
self  - specify the pointer for fit structure
data -  specify the data (x,y) list array to be fitted, it None
        specified the default data will be used
fn   -  string to specify the fitting function name, default 'Linear'
parms - return list from leastSquaresFit function
legd  - indicator whether to write fitted coefficients on plot  
steps - specify the maximum iteration steps used
zeros(...)
zeros((d1,...,dn),typecode='l',savespace=0) will return a new array of shape (d1,...,dn) and type typecode with all it's entries initialized to zero.  If savespace is nonzero the array will be a spacesaver array.