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) Return type: dict Raises: exceptions.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.
goodness_of_fit
(masked_residuals, noise, beam)[source]¶ Calculates the goodnessoffit values, chisq and reduced_chisq.
Warning
We do not use the standard chisquared formula for calculating these goodnessoffit values, and should probably rename them in the next release. See below for details.
These goodnessoffit values are related to, but not quite the same as reduced chisquared. Strictly speaking the reduced chisquared is statistically invalid for a Gaussian model from the outset (see arxiv:1012.3754). We attempt to provide a resolutionindependent estimate of goodnessoffit (‘reduced chisquared’), by using the same ‘independent pixels’ correction as employed when estimating RMS levels, to normalize the chisquared value. However, as applied to the standard formula this will sometimes imply that we are fitting a fractional number of datapoints less than 1! As a result, it doesn’t really make sense to try and apply the ‘degreesoffreedom’ correction, as this would likely result in a negative
reduced_chisq
value. (And besides, the ‘degrees of freedom’ concept is invalid for nonlinear models.) Finally, note that when called fromsource_profile_and_errors()
, the noiseestimate at the peakpixel is supplied, so will typically overestimate the noise and hence underestimate the chisquared values.Parameters: Returns: chisq, reduced_chisq
Return type:

tkp.sourcefinder.fitting.
moments
(data, beam, threshold=0)[source]¶ Calculate source positional values using moments
Parameters:  data (numpy.ndarray) – Actual 2D image data
 beam (3tuple) – beam (psf) information, with semimajor and semiminor axes
Returns: peak, total, x barycenter, y barycenter, semimajor axis, semiminor axis, theta
Return type: Raises: exceptions.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.