fitting Package

Gefit Module

PyMca5.PyMcaMath.fitting.Gefit.ChisqAlphaBeta(model0, parameters, x, y, weight, constrains, model_deriv=None, linear=None)[source]
PyMca5.PyMcaMath.fitting.Gefit.LeastSquaresFit(model, parameters0, data=None, maxiter=100, constrains=None, weightflag=0, model_deriv=None, deltachi=None, fulloutput=0, xdata=None, ydata=None, sigmadata=None, linear=None)[source]

Typical use:

LeastSquaresFit(model_function, parameters, xdata=xvalues, ydata=yvalues)

model_function - it has the form model_function(parameters, x) where parameters is a sequence
containing the parameters to be refined and x is the array of values in which the function is to be evaluated.

parameters - sequence with the initial values to be refined

xdata - array with the x axis data points

ydata - array with the y axis data points

Additional keywords:

sigmadata - array with the uncertainties associated to ydata (default is sqrt(y) )

weightflag - 0 Means no weighted fit 1 means weighted fit

constrains - if provided, it is a 2D sequence of dimension (3, n_parameters) where, for each

parameter denoted by the index i, the meaning is

constrains[0][i] -> 0 - Free (Gefit.CFREE)
1 - Positive (Gefit.CPOSITIVE) 2 - Quoted (Gefit.CQUOTED) 3 - Fixed (Gefit.CFIXED) 4 - Factor (Gefit.CFACTOR) 5 - Delta (Gefit.CDELTA) 6 - Sum (Gefit.CSUM)
constrains[1][i] -> Ignored if constrains[0][i] is 0, 1, 3
Min value of the parameter if constrains[0][i] is Gefit.CQUOTED Index of fitted parameter to which it is related
constrains[2][i] -> Ignored if constrains[0][i] is 0, 1, 3
Max value of the parameter if constrains[0][i] is Gefit.CQUOTED Factor to apply to related parameter with index constrains[1][i] Difference with parameter with index constrains[1][i] Sum obtained when adding parameter with index constrains[1][i]
model_deriv - function providing the derivatives of the fitting function respect to the fitted parameters.
It will be called as model_deriv(parameters, index, x) where parameters are the current values of the fitting parameters, index is the fitting parameter index of which the the derivative has to be provided in the supplied array of x points.

linear - Flag to indicate a linear fit instead of a non-linear. Default is non-linear fit (=false)

maxiter - Maximum number of iterations (default is 100)

Output:

fitted_parameters, reduced_chi_square, uncertainties
PyMca5.PyMcaMath.fitting.Gefit.LinearLeastSquaresFit(model0, parameters0, data0, maxiter, constrains0, weightflag, model_deriv=None, deltachi=0.01, fulloutput=0, xdata=None, ydata=None, sigmadata=None)[source]
PyMca5.PyMcaMath.fitting.Gefit.RestreinedLeastSquaresFit(model0, parameters0, data0, maxiter, constrains0, weightflag, model_deriv=None, deltachi=0.01, fulloutput=0, xdata=None, ydata=None, sigmadata=None)[source]
PyMca5.PyMcaMath.fitting.Gefit.fitpar2par(fitpar, constrains, free_index)[source]
PyMca5.PyMcaMath.fitting.Gefit.gauss(param0, t0)[source]
PyMca5.PyMcaMath.fitting.Gefit.getparameters(parameters, constrains)[source]
PyMca5.PyMcaMath.fitting.Gefit.getsigmaparameters(parameters, sigma0, constrains)[source]
PyMca5.PyMcaMath.fitting.Gefit.myexp(x)[source]
PyMca5.PyMcaMath.fitting.Gefit.test(npoints)[source]

SimpleFitModule Module

class PyMca5.PyMcaMath.fitting.SimpleFitModule.SimpleFit[source]

Bases: object

configure(ddict=None)[source]
estimate()[source]
estimateBackground()[source]
estimateFunction()[source]
evaluateDefinedFunction(x=None)[source]
fit()[source]
getBackgroundFunction()[source]
getConfiguration()[source]
getDefaultConfiguration()[source]
getFitFunction()[source]
getResult(configuration=False)[source]
getStatus()[source]
importFunctions(modname)[source]
modelFunction(pars, t)[source]
modelFunctionDerivative(pars, index, x)[source]
numericDerivative(self, f, parameters, index, x)[source]

calculates the numeric derivate of f(parameters, x) respect to the parameter indexed by the given index

setBackgroundFunction(name)[source]
setConfiguration(ddict, try_import=False)[source]
setData(x, y, sigma=None, xmin=None, xmax=None, **kw)[source]
setFitFunction(name)[source]
startFit()[source]
PyMca5.PyMcaMath.fitting.SimpleFitModule.test()[source]

SimpleFitUserEstimatedFunctions Module

class PyMca5.PyMcaMath.fitting.SimpleFitUserEstimatedFunctions.SimpleFitDefaultFunctions[source]

Bases: object

atan(pars, x)[source]
hypermet(pars, x)[source]

Default hypermet function

polynomial(pars, x)[source]
slit(pars, x)[source]

Function to calulate slit width and knife edge cut

stepDown(pars, x)[source]

Complementary error function like.

stepUp(pars, x)[source]

Error function like.

Specfit Module

class PyMca5.PyMcaMath.fitting.Specfit.Specfit(*vars, **kw)[source]

Bases: object

addbackground(background=None, function=None, parameters=None, estimate=None)

method addbackground(self, background, function, parameters, estimate) Usage: self.addbackground(background,function,parameters,estimate=None) Input:

background: String with the name describing the function function: The actual function parameters: Parameters names [‘p1’,’p2’,’p3’,...] estimate: The initial parameters estimation function if any
Output:
Returns 0 if everything went fine or a positive number in- dicating the offending parameter
addfilter(filterfun, *vars, **kw)
addtheory(theory=None, function=None, parameters=None, estimate=None, configure=None, derivative=None)

method addtheory(self, theory, function, parameters, estimate) Usage: self.addtheory(theory,function,parameters,estimate,configure=None)

or self.addtheory(theory=theory,

function=function, parameters=parameters, estimate=estimate)
Input:

theory: String with the name describing the function function: The actual function parameters: Parameters names [‘p1’,’p2’,’p3’,...] estimate: The initial parameters estimation function to be called if any configure: Optional function to be called to initialize parameters prior to fit derivative: Optional analytical derivative function.

Its signature should be function(parameter_values, parameter_index, x) See Gefit.py module for more information.
Output:
Returns 0 if everything went fine or a positive number indicating the offending parameter
bkg_constant(pars, x)

Constant background

bkg_internal(pars, x)

Internal Background

bkg_linear(pars, x)

Linear background

bkg_none(pars, x)

Internal Background

bkg_squarefilter(pars, x)

Square filter Background

configure(**kw)

Configure the current theory passing a dictionary to the supply method

deletefilter(self, *vars, **kw)

Deletes a filter from self.filterlist self.delete(2) just makes del(self.filterlist[2]) self.delete(filtername=’sort’) deletes any filter named sort

estimate(mcafit=0)

Fill the parameters entries with an estimation made on the given data.

estimate_bkg(xx, yy)
estimate_builtin_bkg(xx, yy)
estimate_fun(xx, yy, zz, xscaling=1.0, yscaling=None)
filter(*vars, **kw)
fitfunction(pars, t)
gendata(*vars, **kw)
guess_fwhm(**kw)
guess_yscaling(*vars, **kw)
importfun(file)
mcafit(*var, **kw)
mcagetareas(**kw)
mcagetresult()
mcaregions(peaks, fwhm)
mcaresidualssearch(**kw)
mcaresidualssearch_old(**kw)
myderiv(param0, index, t0)
num_deriv(param0, index, t0)
numderiv(*vars, **kw)

numeriv(self,*vars,**kw) Usage: self.numderiv(x,y)

self.numderiv(x=x,y=y) self.numderiv()
pretreat(xdata, ydata, xmin=None, xmax=None)
setbackground(theory)

method: setbackground(self,background) Usage: self.setbackground(background) Input:

theory: The name of the background to be used.
It has to be one of the keys of self.bkgdict
Output:
returns 0 if everything went fine
setdata(*vars, **kw)
settheory(theory)

method: settheory(self,theory) Usage: self.settheory(theory) Input:

theory: The name of the theory to be used.
It has to be one of the keys of self.theorydict
Output:
returns 0 if everything went fine
smooth(self, *vars, **kw)

Usage: self.smooth(y) self.smooth(y=y) self.smooth()

squarefilter(*vars)
startfit(mcafit=0)

Launch the fit routine

PyMca5.PyMcaMath.fitting.Specfit.test()[source]

SpecfitFunctions Module

class PyMca5.PyMcaMath.fitting.SpecfitFunctions.SpecfitFunctions(config=None)[source]

Bases: object

agauss(pars, x)[source]

A fit function.

alorentz(pars, x)[source]

Fit function.

apvoigt(pars, x)[source]

Fit function.

atan(pars, x)[source]
bkg_constant(pars, x)[source]

Constant background

bkg_internal(pars, x)[source]

Internal Background

bkg_linear(pars, x)[source]

Linear background

bkg_none(pars, x)[source]

Internal Background

configure(*vars, **kw)[source]
estimate(x, y, z, xscaling=1.0, yscaling=1.0)[source]
estimate_agauss(xx, yy, zzz, xscaling=1.0, yscaling=None)[source]
estimate_alorentz(xx, yy, zzz, xscaling=1.0, yscaling=None)[source]
estimate_apvoigt(xx, yy, zzz, xscaling=1.0, yscaling=None)[source]
estimate_atan(*var, **kw)[source]
estimate_gauss(xx, yy, zzz, xscaling=1.0, yscaling=None)[source]
estimate_hypermet(xx, yy, zzz, xscaling=1.0, yscaling=None)[source]
if yscaling == None:
try:
yscaling=self.config[‘Yscaling’]
except:
yscaling=1.0
if yscaling == 0:
yscaling=1.0
estimate_lorentz(xx, yy, zzz, xscaling=1.0, yscaling=None)[source]
estimate_periodic_gauss(xx, yy, zzz, xscaling=1.0, yscaling=None)[source]
estimate_pvoigt(xx, yy, zzz, xscaling=1.0, yscaling=None)[source]
estimate_slit(xxx, yyy, zzz, xscaling=1.0, yscaling=1.0)[source]
estimate_splitgauss(xx, yy, zzz, xscaling=1.0, yscaling=None)[source]
estimate_splitlorentz(xx, yy, zzz, xscaling=1.0, yscaling=None)[source]
estimate_splitpvoigt(xx, yy, zzz, xscaling=1.0, yscaling=None)[source]
estimate_stepdown(xxx, yyy, zzz, xscaling=1.0, yscaling=1.0)[source]
estimate_stepup(xxx, yyy, zzz, xscaling=1.0, yscaling=1.0)[source]
fun(param, t)[source]
gauss(pars, x)[source]

A fit function.

gauss2(param0, t0)[source]
guess_fwhm(**kw)[source]
hypermet(pars, x)[source]

A fit function.

indexx(x)[source]
lorentz(pars, x)[source]

Fit function.

myexp(x)[source]
periodic_gauss(pars, x)[source]

Fit function periodic_gauss(pars, x) pars = [npeaks, delta, height, position, fwhm]

pvoigt(pars, x)[source]

Fit function.

seek(y, x=None, yscaling=None, fwhm=None, sensitivity=None, mca=None)[source]
SpecfitFunctions.seek(self,y,
x=None, yscaling=None,fwhm=None,sensitivity=None, mca=None)

It searches for peaks in the y array. If x it is given, it gives back the closest x(s) to the position of the peak(s). Otherways it gives back the index of the closest point to the peak.

slit(pars, x)[source]

A fit function.

splitgauss(pars, x)[source]

Asymmetric gaussian.

splitlorentz(pars, x)[source]

Asymmetric lorentz.

splitpvoigt(pars, x)[source]

Asymmetric pseudovoigt.

stepdown(pars, x)[source]

A fit function.

stepup(pars, x)[source]

A fit function.

PyMca5.PyMcaMath.fitting.SpecfitFunctions.test(a)[source]

StackSimpleFit Module

class PyMca5.PyMcaMath.fitting.StackSimpleFit.StackSimpleFit(fit=None)[source]

Bases: object

aboutToGetStackData(idx)[source]
estimateFinished()[source]
fitFinished()[source]
getFitInputValues(index)[source]

Returns the fit parameters x, y, sigma, xmin, xmax

getOutputFileNames()[source]
onProcessStackFinished()[source]
processStack(mask=None)[source]
processStackData(i)[source]
progressUpdate()[source]

This methos returns a dictionnary with the keys progress: A number between 0 and 100 indicating the fit progress status: Status of the calculation thread.

setConfiguration(ddict)[source]
setConfigurationFile(fname)[source]
setData(stack_x, stack_y, sigma=None, xmin=None, xmax=None)[source]
setDataIndex(data_index=None)[source]
setOutputDirectory(outputdir)[source]
setOutputFileBaseName(outputfile)[source]
setProgressCallback(method)[source]

The method will be called as method(current_fit_index, total_fit_index)

PyMca5.PyMcaMath.fitting.StackSimpleFit.test()[source]