Bases: pymodelfit.core.FunctionModel, pymodelfit.core.InputCoordinateTransformer
This class is a FunctionModel that maps a two-dimensional input to a scalar output for each 2D coordinate. The input thus is at least a two-dimensional array, with the first dimension of length 2.
x.__init__(...) initializes x; see help(type(x)) for signature
call the function on the input x,which will be flattened. If not 1D, the output will be reshaped to the input
Methods
addTransform(input, output, func) | Register a function as a transform from one coordinate system to another. |
cartesian_to_polar(x, y[, degrees]) | Converts arrays in 2D rectangular Cartesian coordinates to polar |
chi2Data([x, y, weights, ddof]) | Computes the chi-squared statistic for the data assuming this model. |
f(x, *params) | This abstract method must be overriden in subclasses. |
fitData([x, y, fixedpars, weights, ...]) | Fit the provided data using algorithms from scipy.optimize, and adjust the model parameters to match. |
getCov() | Computes the covariance matrix for the last fitData() call. |
getFluxSize([flux, frac, mode, cen, v0, ...]) | Compute the radius/area enclosing a specified amount of flux. |
getMCMC(x, y[, priors, datamodel]) | Generate an Markov Chain Monte Carlo sampler for the data and model. |
gradient(x) | |
integrateCartesian(xl, xu, yl, yu, **kwargs) | Integrates the function in a rectangular area defined in rectangular coordinates. |
integrateCircular(outr[, inr, theta]) | Integrates using a circular jacobian from inr to outr |
inv(output, *args, **kwargs) | Compute the inverse of this model for the requested output. |
isVarnumModel() | Determines if the model represented by this class accepts a variable number of parameters (i.e. |
pixelize(xl, xu, yl, yu[, nx, ny, sampling]) | Generates a 2D array of the model smoothed/integrated over a certain |
plot([datarange, nx, ny, clf, cb, data, log]) | Plots the model over the range requested using the matplotlib.pyplot.imshow() function. |
plot3d([datarange, nx, ny, clf, cb, data]) | Generate a 3D plot of the model using mayavi. |
plotResiduals([x, y, fmt, xaxis, clf, relative]) | Plots residuals between data and the model for a variety of projections. |
polar_to_cartesian(r, t[, degrees]) | Converts arrays in 2D polar coordinates to rectangular cartesian |
resampleFit([x, y, xerr, yerr, bootstrap, ...]) | Estimates errors via resampling. |
residuals([x, y, retdata]) | Compute residuals of the provided data against the model. |
stdData([x, y]) | Determines the standard deviation of the model from data. |
transformCoordinates(x[, incoordsys, ...]) | Transform from the input coordinate system into that defined for the model function. |
Attributes
data | The fitting data for this model. |
errors | Error on the data. |
fittypes | A Sequence of the available valid values for the fittype |
params | A tuple of the parameter names. |
pardict | A dictionary mapping parameter names to the associated values. |
parvals | The values of the parameters in the same order as params |
weightstype | Determines the statistical interpretation of the weights in data. |
Register a function as a transform from one coordinate system to another.
Parameters: |
|
---|
Converts arrays in 2D rectangular Cartesian coordinates to polar coordinates.
Parameters: |
|
---|---|
Returns: | (r,theta) where theta is measured from the +x axis increasing towards the +y axis |
Computes the chi-squared statistic for the data assuming this model.
Parameters: |
|
---|---|
Returns: | tuple of floats (chi2,reducedchi2,p-value) |
The fitting data for this model. Should be either None, or a tuple(datain,dataout,weights). Note that the weights are interpreted statistically as errors based on the weightstype attribute.
Error on the data. Sets the weights on data assuming the interpretation for errors given by weightstype. If data is None/missing, a TypeError will be raised.
This abstract method must be overriden in subclasses. It is interpreted as the function that takes an array (or array-like) as the first argument and returns an array of output values appropriate for the model.
model parameters are passed in as the rest of the arguments, in the order they are given in the _pars sequence.
Fit the provided data using algorithms from scipy.optimize, and adjust the model parameters to match.
The fitting technique is sepcified by the fittype attribute of the object, which by default can be any of the optimization types in the scipy.optimize module (except for scalar minimizers)
The full fitting output is available in lastfit attribute after this method completes.
Parameters: |
|
---|
kwargs are passed into the fitting function.
Returns: | array of the best fit parameters |
---|---|
Raises ModelTypeError: | |
If the output of the model does not match the shape of y. |
See also
A Sequence of the available valid values for the fittype attribute. (Read-only)
Computes the covariance matrix for the last fitData() call.
Returns: | The covariance matrix with variables in the same order as params. Diagonal entries give the variance in each parameter. |
---|
Warning
This is not guaranteed to work for custom fit-types, but will always work with the default (leastsq) fit.
Compute the radius/area enclosing a specified amount of flux.
Parameters: |
|
---|
kwargs are passed into the minimization function
Returns: | The location at which the flux enclosed is given by flux as specified by the mode argument. |
---|
Generate an Markov Chain Monte Carlo sampler for the data and model. This function requires the PyMC package for the MCMC internals and sampling.
Parameters: |
|
---|---|
Raises ValueError: | |
If a prior is not provided for any parameter. |
|
Returns: | A pymc.MCMC object ready to sample for this model. |
Integrates the function in a rectangular area defined in rectangular coordinates.
Parameters: |
---|
kwargs are passed into scipy.integrate.dblquad()
Integrates using a circular jacobian from inr to outr
Parameters: |
---|
kwargs are passed into scipy.integrate.dblquad()
Compute the inverse of this model for the requested output.
Parameters: | output – The output value of the model at which to compute the inverse. |
---|---|
Returns: | The input value at which the model produces output |
Raises ModelTypeError: | |
If the model is not invertable for the provided data set. |
Determines if the model represented by this class accepts a variable number of parameters (i.e. number of parameters is set when the object is created).
Returns: | True if this model has a variable number of parameters. |
---|
A tuple of the parameter names. (read-only)
A dictionary mapping parameter names to the associated values.
Generates a 2D array of the model smoothed/integrated over a certain pixel size.
Parameters: |
|
---|---|
Returns: | An nx X ny array with the pixelized model. |
Note
The attribute lastintegrate stores the result of the integrations if sampling is None, with lastintegrate[0] storing the result and lasteintegrate[1] storing the error on the integral for each pixel.
Plots the model over the range requested using the matplotlib.pyplot.imshow() function.
Parameters: |
|
---|
kwargs are passed into matplotlib.pyplot.imshow()
Raises ValueError: | |
---|---|
if data is not present and datarange is None |
Generate a 3D plot of the model using mayavi.
See plot() for meaning of the arguments
Plots residuals between data and the model for a variety of projections. If x and y are None, the residuals will be inferred from the last-fit data. For details on how residuals are computed see FunctionModel.residuals()
Parameters: |
|
---|
Converts arrays in 2D polar coordinates to rectangular cartesian coordinates.
Note that the spherical coordinates are in physicist convention such that (1,0,pi/2) is x-axis.
Parameters: |
|
---|---|
Returns: | arrays (x,y) |
Estimates errors via resampling. Uses the fitData function to fit the function many times while either using the “bootstrap” technique (resampling w/replacement), monte carlo estimates for the error, or both to estimate the error in the fit.
Parameters: |
|
---|
kwargs are passed into fitData
Returns: | (histd,cov) where histd is a dictionary mapping parameters to their histograms and cov is the covariance matrix of the parameters in parameter order. |
---|
Note
If x, y, xerr, or yerr are provided, they do not overwrite the stored data, unlike most other methods for this class.
Compute residuals of the provided data against the model. E.g. .
Parameters: | |
---|---|
Returns: | Residuals of model from y or if retdata is True, a tuple (x,y,residuals). |
Return type: | array-like |
Determines the standard deviation of the model from data. Data can either be provided or (by default) will be taken from the stored data.
Parameters: | |
---|---|
Returns: | standard deviation of model from y |
Transform from the input coordinate system into that defined for the model function.
Parameters: |
|
---|
if incoordsys is None, self.`incoordsys will be used
Determines the statistical interpretation of the weights in data. Can be:
Weights act as inverse errors (default)
Weights act as inverse variance
Weights act as errors (non-standard - this makes points with larger error bars count more towards the fit).
Weights act as variance (non-standard - this makes points with larger error bars count more towards the fit).