aperture_photometry#

photutils.aperture.aperture_photometry(data, apertures, error=None, mask=None, method='exact', subpixels=5, wcs=None, *, segmentation_image=None, labels=None, mask_method='none')[source]#

Perform aperture photometry on the input data by summing the flux within the given aperture(s).

Note that this function returns the sum of the (weighted) input data values within the aperture. It does not convert data in surface brightness units to flux or counts. Conversion from surface-brightness units should be performed before using this function.

Parameters:
dataarray_like, Quantity, NDData

The 2D array on which to perform photometry. data should be background-subtracted. If data is a Quantity array, then error (if input) must also be a Quantity array with the same units. See the Notes section below for more information about NDData input.

aperturesAperture, supported regions.Region, list of Aperture or regions.Region

The aperture(s) to use for the photometry. If apertures is a list of Aperture or regions.Region, then they all must have the same position(s). If apertures contains a SkyAperture or SkyRegion object, then a WCS must be input using the wcs keyword. Region objects are converted to aperture objects.

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. If a Quantity array, then data must also be a Quantity array with the same units.

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. A pixel is included only if its center lies strictly inside the aperture; pixel centers lying exactly on the aperture boundary are excluded (weight 0).

  • '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]. A subpixel is included only if its center lies strictly inside the aperture; subpixel centers lying exactly on the aperture boundary are excluded (weight 0).

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.

wcsWCS object, optional

A world coordinate system (WCS) transformation that supports the astropy shared interface for WCS (e.g., astropy.wcs.WCS, gwcs.wcs.WCS). If provided, the output table will include a 'sky_center' column with the sky coordinates of the input aperture center(s). This keyword is required if the input apertures contains a SkyAperture or SkyRegion.

segmentation_imageSegmentationImage, 2D array_like, or None, optional

A 2D segmentation image with the same shape as data, where background pixels have a value of 0 and sources are labeled with positive integers. If input, neighboring sources can be masked or corrected within each aperture according to the mask_method keyword. This keyword is required if mask_method is not 'none'.

labelsint, 1D array_like, or None, optional

The source label(s) in segmentation_image associated with the aperture position(s). If input, labels must have the same length as the number of aperture positions. If None (default), the label for each aperture is determined by sampling segmentation_image at the aperture center (rounded to the nearest pixel). An aperture whose center falls on a background pixel (label 0) has its masking behavior disabled.

mask_method{‘none’, ‘mask’, ‘source_only’, ‘correct’}, optional

The method used to handle neighboring sources within each aperture using the segmentation_image:

  • 'none' (default): The segmentation_image is ignored and all pixels within the aperture are included.

  • 'mask': Pixels belonging to neighboring sources (i.e., labeled but not the target source) are excluded.

  • 'source_only': Only pixels belonging to the target source are included; both neighboring sources and background pixels are excluded.

  • 'correct': Pixels belonging to neighboring sources are replaced by the values of the pixels mirrored across the aperture center. If a mirror pixel is unavailable, the pixel is excluded.

Returns:
tableQTable

A table of the photometry with the following columns:

  • 'id': The source ID.

  • 'x_center', 'y_center': The x and y pixel coordinates of the input aperture center(s).

  • 'sky_center': The sky coordinates of the input aperture center(s). Returned if a wcs is input.

  • 'aperture_sum': The sum of the values within the aperture(s). The values are always float64, regardless of the input data dtype (a Quantity with float64 values if data has units).

  • 'aperture_sum_err': The corresponding uncertainty in the 'aperture_sum' values (always float64). Returned only if the input error is not None.

The table metadata includes the Astropy and Photutils version numbers and the aperture_photometry calling arguments.

Notes

Region objects are converted to Aperture objects using the region_to_aperture() function.

If the input data is a NDData instance, then the error, mask, and wcs keyword inputs are ignored. Instead, these values should be defined as attributes in the NDData object. In the case of error, it must be defined in the uncertainty attribute with a StdDevUncertainty instance.