snpl.fit module

Utilities for curve fitting analyses

Note

This module is not really useful anymore. It is encouraged to use directly the scipy.optimize package instead.

snpl.fit.AreaGaussian(p)[source]
snpl.fit.AreaLorentzian(p)[source]
snpl.fit.AreaPseudoVoigt(p)[source]

I think it’s ok…

class snpl.fit.Baseline(xdata, ydata, x_range=[])[source]

Bases: Function

A class for baseline.

class snpl.fit.BaselineStable(xdata, ydata, left, right, hwidth)[source]

Bases: Function

snpl.fit.EMG(x, p)[source]
class snpl.fit.Function(expr, params, share=[], lock=[], headers=[], **lineprops)[source]

Bases: object

Bound(ind, bound=(-inf, inf))[source]

Specify the boundary for the parameter. @param ind: index of the target parameter @param bound: two-tuple of the lower and upper boundary.

Decode(params)[source]

Makes the “full” parameters containing locked parameters, from the “partial” parameters excluding locked ones.

DecodeErrors(errors)[source]

Makes the “full” parameters containing locked parameters, from the “partial” parameters excluding locked ones.

Encode()[source]

Makes the “partial” parameters & bounds excluding locked parameters, from the currently-set parameters & errors. @return: two-tuple of lists

Evaluate(x)[source]

Get the value of the function at x with current parameters. @return: float number

EvaluateWithParam(x, params)[source]

Get the value of the function at x with given parameters. NOTE: This method doesn’t overwrite the parameters held by this class. @return: float number

EvaluateWithPartialParam(x, *params)[source]

Get the value of the function at x with given parameters. This method doesn’t overwrite the parameters held by this class. Unlike EvaluateWithParam(), this method accepts a “partial” parameter excluding locked values.

Fit(xs, ys, sigma=None, **kwargs)[source]

Fit the model to given data set. @param xs: array of x @param ys: array of y @param sigma: array of std. dev., optional

GetLineProps()[source]
GetParameterLength()[source]

Get the number of parameters needed (including locked/shared parameters).

GetParamsHeadersString(fmt='{0:>15s}', sep='\t')[source]

Returns a formatted string of parameter headers.

GetParamsString(fmt='{0:>15f}', sep='\t')[source]
GetPlotData(start, stop, num=1000, xlog=False, baseline=None)[source]

Make the arrays for plotting functions. @param start: starting value for x @param stop: stopping value for x @param num: number of points @param xlog: If True, x will be evenly spaced in log scale. @param baseline: another Function() instance @return: (array of x, array of y)

Integrate(xi, xf)[source]
Lock(*args)[source]

Lock the parameter(s). Locked parameters don’t change during fitting. @param *args: index (or indices) of the parameters to be locked. NOT A LIST OF INDICES.

Share(*args)[source]

Specify the parameter(s) to be shared. @param *args: index (or indices) of the parameters to be shared. NOT A LIST OF INDICES.

Unbound(ind)[source]
Unlock(*args)[source]
Unshare(*args)[source]
Update(params, errors=None)[source]

Overwrite parameters.

UpdateParameter(params, errors)[source]

Updates the currently-set parameter & error info with the given “partial” parameter & error excluding locked values.

snpl.fit.Gaussian(x, p)[source]

p[0]: amp p[1]: position p[2]: fwhm

snpl.fit.Line(x, p)[source]
snpl.fit.Lorentzian(x, p)[source]
class snpl.fit.Model(funcs=[])[source]

Bases: object

A class for fitting model function composed of multiple functions.

AddFunction(func)[source]

add a function to the model @param func: Function object.

Decode(params)[source]

Chop the given parameters into parameter lists for each function. @param params: a list of parameters @return: a list of lists of parameters (ret[i][j]: jth parameter of ith function)

Encode()[source]

Return a list of current parameters (considering locked and shared parameters) @return: a list of parameters and a list of two-tuples of bounds

20160930 added bounds tuples

Evaluate(x)[source]

Evalute the model using currently set parameters. @param x: x

EvaluateWithParams(x, *params)[source]

Evaluate the model using x and given parameters. Note that the parameters given here do not affect the parameters of this instance. To update the parameters of the instance, call self.UpdateParameters. @param x: @param *params: parameters

Fit(xs, ys, sigma=None)[source]

Fit the model to given data set. @param xs: array of x @param ys: array of y @param sigma: array of std. dev., optional

GetPlotData(start, stop, num=1000, xlog=False, ind=None, baseline=None)[source]

Make the arrays for plotting functions. @param start: starting value for x @param stop: stopping value for x @param num: number of points @param xlog: use x evenly spaced in log space if True. @param ind: index of a function to be plotted. If None, the data for whole model will be evaluated. @param baseline: another Function() object @return: (array of x, array of y)

UpdateEncoderMap()[source]

Make a map for encoding parameters.

UpdateParameters(params, errors=None)[source]

Update the parameters with given parameter list. @param params: a list of parameters

snpl.fit.Parabolic(x, p)[source]

p[0]: height (>0) p[1]: position p[2]: full width at half maximum (fwhm)

snpl.fit.PseudoVoigt(x, p)[source]

Gaussian-Lorentzian Sum (Amplitude), from PeakFit v4.12 Manual 7-11

class snpl.fit.Residuals(residuals_function, p0)[source]

Bases: object

A class for general least-square optimization. It calculates the sum of squared residuals and try to minimize it with respect to the parameters, starting from p0.

Bound(ind, bound=(-inf, inf))[source]

Specify the boundary for the parameter. @param ind: index of the target parameter @param bound: two-tuple of the lower and upper boundary.

Fit()[source]
snpl.fit.SplitGaussian(x, p)[source]
snpl.fit.Voigt(x, p)[source]