tkp.sourcefinder.image
– Image class & routines¶
This module provides simple access to an image, without database
overhead. The Image class handles the actual data (a (2D) numpy
array), the world coordinate system (a tkp.utility.coordinates.WCS
instance) and the beam information. While these three objects are
supplied upon instantiation of an Image, one can use a
tkp.accessors.dataaccessor.DataAccessor
object to automatically
derive these from the image file itself (provided the header
information in the file is correct).
Some generic utility routines for number handling and calculating (specific) variances
-
class
tkp.sourcefinder.image.
ImageData
(data, beam, wcs, margin=0, radius=0, back_size_x=32, back_size_y=32, residuals=True)[source]¶ Encapsulates an image in terms of a numpy array + meta/headerdata.
This is your primary contact point for interaction with images: it icludes facilities for source extraction and measurement, etc.
Sets up an ImageData object.
- Args:
- data (2D numpy.ndarray): actual image data
- wcs (utility.coordinates.wcs): world coordinate system specification
- beam (3-tuple): beam shape specification as (semimajor, semiminor, theta)
-
backmap
¶ Background map
-
static
box_slice_about_pixel
(x, y, box_radius)[source]¶ Returns a slice centred about (x,y), of width = 2*int(box_radius) + 1
-
clearcache
()[source]¶ Zap any calculated data stored in this object.
Clear the background and rms maps, labels, clip, and any locally held data. All of these can be reconstructed from the data accessor.
Note that this must be run to pick up any new settings.
-
data
¶ Masked image data
-
data_bgsubbed
¶ Background subtracted masked image data
-
extract
(det, anl, noisemap=None, bgmap=None, labelled_data=None, labels=None, deblend_nthresh=0, force_beam=False)[source]¶ Kick off conventional (ie, RMS island finding) source extraction.
Kwargs:
- det (float): detection threshold, as a multiple of the RMS
- noise. At least one pixel in a source must exceed this for it to be regarded as significant.
- anl (float): analysis threshold, as a multiple of the RMS
- noise. All the pixels within the island that exceed this will be used when fitting the source.
noisemap (numpy.ndarray):
bgmap (numpy.ndarray):
- deblend_nthresh (int): number of subthresholds to use for
- deblending. Set to 0 to disable.
- force_beam (bool): force all extractions to have major/minor axes
- equal to the restoring beam
Returns: tkp.utility.containers.ExtractionResults
-
fd_extract
(alpha, anl=None, noisemap=None, bgmap=None, deblend_nthresh=0, force_beam=False)[source]¶ False Detection Rate based source extraction. The FDR procedure guarantees that <FDR> < alpha.
-
fit_fixed_positions
(positions, boxsize, threshold=None, fixed='position+shape', ids=None)[source]¶ Convenience function to fit a list of sources at the given positions
This function wraps around fit_to_point().
Parameters: - positions (tuple) – list of (RA, Dec) tuples. Positions to be fit, in decimal degrees.
- boxsize – See
fit_to_point()
- threshold – as above.
- fixed – as above.
- ids (tuple) – A list of identifiers. If not None, then must match
the length and order of the
requested_fits
. Any successfully fit positions will be returned in a tuple along with the matching id. As these are simply passed back to calling code they can be a string, tuple or whatever.
In particular, boxsize is in pixel coordinates as in fit_to_point, not in sky coordinates.
Returns: - A list of successful fits.
- If
ids
is None, returns a single list oftkp.sourcefinder.extract.Detection
s. Otherwise, returns a tuple of two matched lists: ([detections], [matching_ids]).
Return type: tuple
-
fit_to_point
(x, y, boxsize, threshold, fixed)[source]¶ Fit an elliptical Gaussian to a specified point on the image.
The fit is carried on a square section of the image, of length boxsize & centred at pixel coordinates x, y. Any data below threshold * rmsmap is not used for fitting. If fixed is set to
position
, then the pixel coordinates are fixed in the fit.Returns an instance of
tkp.sourcefinder.extract.Detection
.
-
flux_at_pixel
(x, y, numpix=1)[source]¶ Return the background-subtracted flux at a certain position in the map
-
grids
¶ Gridded RMS and background data for interpolating
-
label_islands
(detectionthresholdmap, analysisthresholdmap)[source]¶ Return a lablled array of pixels for fitting.
Parameters: - detectionthresholdmap (numpy.ndarray) –
- analysisthresholdmap (numpy.ndarray) –
Returns: list of valid islands (list of int)
labelled islands (numpy.ndarray)
-
pixmax
¶ Maximum pixel value (pre-background subtraction)
-
pixmin
¶ Minimum pixel value (pre-background subtraction)
-
reverse_se
(det)[source]¶ Run source extraction on the negative of this image.
Obviously, there should be no sources in the negative image, so this tells you about the false positive rate.
We need to clear cached data – backgroung map, cached clips, etc – before & after doing this, as they’ll interfere with the normal extraction process. If this is regularly used, we’ll want to implement a separate cache.
-
rmsmap
¶ RMS map
-
xdim
¶ X pixel dimension of (unmasked) data
-
ydim
¶ Y pixel dimension of (unmasked) data