tkp.sourcefinder.utils – Utility routines

This module contain utilities for the source finding routines

tkp.sourcefinder.utils.calculate_beamsize(semimajor, semiminor)[source]

Calculate the beamsize based on the semi major and minor axes

tkp.sourcefinder.utils.calculate_correlation_lengths(semimajor, semiminor)[source]

Calculate the Condon correlation length

In order to derive the error bars from Gauss fitting from the Condon (1997, PASP 109, 116C) formulae, one needs the so called correlation length. The Condon formulae assumes a circular area with diameter theta_N (in pixels) for the correlation. This was later generalized by Hopkins et al. (2003, AJ 125, 465) for correlation areas which are not axisymmetric.

Basically one has theta_N^2 = theta_B*theta_b.

Good estimates in general are:

  • theta_B = 2.0 * semimajar
  • theta_b = 2.0 * semiminor
tkp.sourcefinder.utils.circular_mask(xdim, ydim, radius)[source]

Returns a numpy array of shape (xdim, ydim). All points with radius of the centre are set to 0; outside that region, they are set to 1.


Flatten a nested list

Nested lists are made in the deblending algorithm. They’re awful. This is a piece of code I grabbed from

The output from this method is a generator, so make sure to turn it into a list, like this:

flattened = list(flatten(nested)).
tkp.sourcefinder.utils.fudge_max_pix(semimajor, semiminor, theta)[source]

Estimate peak flux correction at pixel of maximum flux

Previously, we adopted Rengelink’s correction for the underestimate of the peak of the Gaussian by the maximum pixel method: fudge_max_pix = 1.06. See the WENSS paper (1997A&AS..124..259R) or his thesis. (The peak of the Gaussian is, of course, never at the exact center of the pixel, that’s why the maximum pixel method will always underestimate it.)

But, instead of just taking 1.06 one can make an estimate of the overall correction by assuming that the true peak is at a random position on the peak pixel and averaging over all possible corrections. This overall correction makes use of the beamshape, so strictly speaking only accurate for unresolved sources.

tkp.sourcefinder.utils.generate_result_maps(data, sourcelist)[source]

Return a source and residual image

Given a data array (image) and list of sources, return two images, one showing the sources themselves and the other the residual after the sources have been removed from the input data.

tkp.sourcefinder.utils.generate_subthresholds(min_value, max_value, num_thresholds)[source]

Generate a series of num_thresholds logarithmically spaced values in the range (min_value, max_value) (both exclusive).

tkp.sourcefinder.utils.get_error_radius(wcs, x_value, x_error, y_value, y_error)[source]

Estimate an absolute angular error on the position (x_value, y_value) with the given errors.

This is a pessimistic estimate, because we take sum of the error along the X and Y axes. Better might be to project them both back on to the major/minor axes of the elliptical fit, but this should do for now.

tkp.sourcefinder.utils.maximum_pixel_method_variance(semimajor, semiminor, theta)[source]

Estimate variance for peak flux at pixel position of maximum

When we use the maximum pixel method, with a correction fudge_max_pix, there should be no bias, unless the peaks of the Gaussians are not randomly distributed, but relatively close to the centres of the pixels due to selection effects from detection thresholds.

Disregarding the latter effect and noise, we can compute the variance of the maximum pixel method by integrating (the true flux-the average true flux)^2 = (the true flux-fudge_max_pix)^2 over the pixel area and dividing by the pixel area ( = 1). This is just equal to integral of the true flux^2 over the pixel area - fudge_max_pix^2.