# tkp.sourcefinder.fitting – Source fitting routines¶

Source fitting routines.

tkp.sourcefinder.fitting.fitgaussian(pixels, params, fixed=None, maxfev=0)[source]

Calculate source positional values by fitting a 2D Gaussian

Parameters: pixels (numpy.ma.MaskedArray) – Pixel values (with bad pixels masked) params (dict) – initial fit parameters (possibly estimated using the moments() function, above)

Kwargs:

fixed (dict): parameters & their values to be kept frozen (ie, not
fitted)

maxfev (int): maximum number of calls to the error function

Returns: peak, total, x barycenter, y barycenter, semimajor, semiminor, theta (radians) (dict) ValueError (in case of a bad fit)

Perform a least squares fit to an elliptical Gaussian.

If a dict called fixed is passed in, then parameters specified within the dict with the same names as fit_params (below) will be “locked” in the fitting process.

tkp.sourcefinder.fitting.moments(data, beam, threshold=0)[source]

Calculate source positional values using moments

Parameters: data (numpy.ndarray) – Actual 2D image data beam (3-tuple) – beam (psf) information, with semi-major and semi-minor axes peak, total, x barycenter, y barycenter, semimajor axis, semiminor axis, theta (dict) ValueError (in case of NaN in input)

Use the first moment of the distribution is the barycenter of an ellipse. The second moments are used to estimate the rotation angle and the length of the axes.