PixelAperture#

class photutils.aperture.PixelAperture[source]#

Bases: Aperture

Abstract base class for apertures defined in pixel coordinates.

Attributes Summary

area

The exact geometric area of the aperture shape.

bbox

The minimal bounding box for the aperture.

isscalar

Whether the instance is scalar (i.e., a single position).

shape

The shape of the instance.

Methods Summary

area_overlap(data, *[, mask, method, subpixels])

Return the area of overlap between the data and the aperture.

copy()

Make a deep copy of this object.

do_photometry(data[, error, mask, method, ...])

Perform aperture photometry on the input data.

plot([ax, origin])

Plot the aperture on a matplotlib Axes instance.

positions()

The aperture positions, as an array of (x, y) coordinates or a SkyCoord.

to_mask([method, subpixels])

Return a mask for the aperture.

to_sky(wcs)

Convert the aperture to a SkyAperture object defined in celestial coordinates.

Attributes Documentation

area#

The exact geometric area of the aperture shape.

Use the area_overlap method to return the area of overlap between the data and the aperture, taking into account the aperture mask method, masked data pixels (mask keyword), and partial/no overlap of the aperture with the data.

Returns:
areafloat

The aperture area.

See also

area_overlap
bbox#

The minimal bounding box for the aperture.

If the aperture is scalar then a single BoundingBox is returned, otherwise a list of BoundingBox is returned.

isscalar#

Whether the instance is scalar (i.e., a single position).

shape#

The shape of the instance.

Methods Documentation

area_overlap(data, *, mask=None, method='exact', subpixels=5)[source]#

Return the area of overlap between the data and the aperture.

This method takes into account the aperture mask method, masked data pixels (mask keyword), and partial/no overlap of the aperture with the data. In other words, it returns the area that used to compute the aperture sum (assuming identical inputs).

Use the area method to calculate the exact analytical area of the aperture shape.

Parameters:
dataarray_like or Quantity

A 2D array.

maskarray_like (bool), optional

A boolean mask with the same shape as data where a True value indicates the corresponding element of data is masked. Masked data are excluded from the area overlap.

method{‘exact’, ‘center’, ‘subpixel’}, optional

The method used to determine the pixel weights (the fraction of the pixel area covered by the aperture):

  • 'exact' (default): Calculates the exact geometric overlap area. Weights are continuous in the range [0, 1].

  • 'center': Binary weighting based on the pixel center. Weights are either 0 or 1.

  • 'subpixel': Approximates the overlap by averaging binary samples on a subgrid. The number of samples is set by the subpixels parameter. Weights are discrete in the range [0, 1].

subpixelsint, optional

The subsampling factor per axis used when method='subpixel'. Each pixel is divided into a grid of subpixels**2 subpixels to approximate the overlap. This parameter is ignored for other methods.

Returns:
areasfloat or array_like

The area (in pixels**2) of overlap between the data and the aperture.

See also

area
copy()#

Make a deep copy of this object.

Returns:
resultAperture

A deep copy of the Aperture object.

do_photometry(data, error=None, mask=None, method='exact', subpixels=5)[source]#

Perform aperture photometry on the input data.

Parameters:
dataarray_like or Quantity instance

The 2D array on which to perform photometry. data should be background subtracted.

errorarray_like or Quantity, optional

The pixel-wise Gaussian 1-sigma errors of the input data. error is assumed to include all sources of error, including the Poisson error of the sources (see calc_total_error). error must have the same shape as the input data.

maskarray_like (bool), optional

A boolean mask with the same shape as data where a True value indicates the corresponding element of data is masked. Masked data are excluded from all calculations.

method{‘exact’, ‘center’, ‘subpixel’}, optional

The method used to determine the pixel weights (the fraction of the pixel area covered by the aperture):

  • 'exact' (default): Calculates the exact geometric overlap area. Weights are continuous in the range [0, 1].

  • 'center': Binary weighting based on the pixel center. Weights are either 0 or 1.

  • 'subpixel': Approximates the overlap by averaging binary samples on a subgrid. The number of samples is set by the subpixels parameter. Weights are discrete in the range [0, 1].

subpixelsint, optional

The subsampling factor per axis used when method='subpixel'. Each pixel is divided into a grid of subpixels**2 subpixels to approximate the overlap. This parameter is ignored for other methods.

Returns:
aperture_sumsndarray or Quantity

The sum within each aperture. The values are always float64, regardless of the input data dtype.

aperture_sum_errsndarray or Quantity

The errors on the sum within each aperture. The values are always float64, regardless of the input error dtype.

plot(ax=None, origin=(0, 0), **kwargs)[source]#

Plot the aperture on a matplotlib Axes instance.

Parameters:
axmatplotlib.axes.Axes or None, optional

The matplotlib axes on which to plot. If None, then the current Axes instance is used.

originarray_like, optional

The (x, y) position of the origin of the displayed image.

**kwargsdict, optional

Any keyword arguments accepted by matplotlib.patches.Patch.

Returns:
patchlist of Patch

A list of matplotlib patches for the plotted aperture. The patches can be used, for example, when adding a plot legend.

abstractmethod positions()#

The aperture positions, as an array of (x, y) coordinates or a SkyCoord.

to_mask(method='exact', subpixels=5)[source]#

Return a mask for the aperture.

Parameters:
method{‘exact’, ‘center’, ‘subpixel’}, optional

The method used to determine the pixel weights (the fraction of the pixel area covered by the aperture):

  • 'exact' (default): Calculates the exact geometric overlap area. Weights are continuous in the range [0, 1].

  • 'center': Binary weighting based on the pixel center. Weights are either 0 or 1.

  • 'subpixel': Approximates the overlap by averaging binary samples on a subgrid. The number of samples is set by the subpixels parameter. Weights are discrete in the range [0, 1].

subpixelsint, optional

The subsampling factor per axis used when method='subpixel'. Each pixel is divided into a grid of subpixels**2 subpixels to approximate the overlap. This parameter is ignored for other methods.

Returns:
maskApertureMask or list of ApertureMask

A mask for the aperture. If the aperture is scalar then a single ApertureMask is returned, otherwise a list of ApertureMask is returned.

abstractmethod to_sky(wcs)[source]#

Convert the aperture to a SkyAperture object defined in celestial coordinates.

Parameters:
wcsWCS object

A world coordinate system (WCS) transformation that supports the astropy shared interface for WCS (e.g., astropy.wcs.WCS, gwcs.wcs.WCS).

Returns:
apertureSkyAperture object

A SkyAperture object.