CircularAperture#
- class photutils.aperture.CircularAperture(positions, r)[source]#
Bases:
PixelApertureA circular aperture defined in pixel coordinates.
The aperture has a single fixed size/shape, but it can have multiple positions (see the
positionsinput).- Parameters:
- Raises:
- ValueError
ValueError If the input radius,
r, is negative.
- ValueError
Examples
>>> from photutils.aperture import CircularAperture >>> aper = CircularAperture([10.0, 20.0], 3.0) >>> aper = CircularAperture((10.0, 20.0), 3.0)
>>> pos1 = (10.0, 20.0) # (x, y) >>> pos2 = (30.0, 40.0) >>> pos3 = (50.0, 60.0) >>> aper = CircularAperture([pos1, pos2, pos3], 3.0) >>> aper = CircularAperture((pos1, pos2, pos3), 3.0)
Attributes Summary
The exact geometric area of the aperture shape.
The minimal bounding box for the aperture.
Whether the instance is scalar (i.e., a single position).
The center pixel position(s).
The radius in pixels.
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
Axesinstance.to_mask([method, subpixels])Return a mask for the aperture.
to_polygon(*[, n_vertices])Return a
PolygonAperturethat approximates this circular aperture.to_sky(wcs)Convert the aperture to a
SkyCircularApertureobject defined in celestial coordinates.Attributes Documentation
- area#
The exact geometric area of the aperture shape.
- bbox#
The minimal bounding box for the aperture.
If the aperture is scalar then a single
BoundingBoxis returned, otherwise a list ofBoundingBoxis returned.
- isscalar#
Whether the instance is scalar (i.e., a single position).
- positions#
The center pixel position(s).
- r#
The radius in pixels.
- shape#
The shape of the instance.
Methods Documentation
- area_overlap(data, *, mask=None, method='exact', subpixels=5)#
Return the area of overlap between the data and the aperture.
This method takes into account the aperture mask method, masked data pixels (
maskkeyword), 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
areamethod 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
datawhere aTruevalue indicates the corresponding element ofdatais 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. 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 thesubpixelsparameter. 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 ofsubpixels**2subpixels to approximate the overlap. This parameter is ignored for other methods.
- dataarray_like or
- Returns:
- areasfloat or array_like
The area (in pixels**2) of overlap between the data and the aperture.
See also
- do_photometry(data, error=None, mask=None, method='exact', subpixels=5, *, segmentation_image=None, labels=None, mask_method='none')#
Perform aperture photometry on the input data.
- Parameters:
- dataarray_like or
Quantityinstance The 2D array on which to perform photometry.
datashould be background subtracted.- errorarray_like or
Quantity, optional The pixel-wise Gaussian 1-sigma errors of the input
data.erroris assumed to include all sources of error, including the Poisson error of the sources (seecalc_total_error).errormust have the same shape as the inputdata.- maskarray_like (bool), optional
A boolean mask with the same shape as
datawhere aTruevalue indicates the corresponding element ofdatais 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 thesubpixelsparameter. 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 ofsubpixels**2subpixels to approximate the overlap. This parameter is ignored for other methods.- segmentation_image
SegmentationImage, 2D array_like, orNone, 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 themask_methodkeyword. This keyword is required ifmask_methodis not'none'.- labelsint, 1D array_like, or
None, optional The source label(s) in
segmentation_imageassociated with the aperture position(s). If input,labelsmust have the same length as the number of aperture positions. IfNone(default), the label for each aperture is determined by samplingsegmentation_imageat 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): Thesegmentation_imageis 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.
- dataarray_like or
- Returns:
- plot(ax=None, origin=(0, 0), **kwargs)#
Plot the aperture on a matplotlib
Axesinstance.- Parameters:
- ax
matplotlib.axes.AxesorNone, optional The matplotlib axes on which to plot. If
None, then the currentAxesinstance 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.
- ax
- 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.
- patchlist of
- to_mask(method='exact', subpixels=5)#
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. 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 thesubpixelsparameter. 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 ofsubpixels**2subpixels to approximate the overlap. This parameter is ignored for other methods.
- Returns:
- mask
ApertureMaskor list ofApertureMask A mask for the aperture. If the aperture is scalar then a single
ApertureMaskis returned, otherwise a list ofApertureMaskis returned.
- mask
- to_polygon(*, n_vertices=100)[source]#
Return a
PolygonAperturethat approximates this circular aperture.- Parameters:
- n_verticesint, optional
The number of polygon vertices used to approximate the circle. Must be at least 3. Default is 100.
- Returns:
- aperture
PolygonAperture A polygon aperture that approximates the circle.
- aperture
- to_sky(wcs)[source]#
Convert the aperture to a
SkyCircularApertureobject 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:
- aperture
SkyCircularApertureobject A
SkyCircularApertureobject.
- aperture
Notes
The aperture shape parameters are converted using the local WCS pixel scale evaluated at the first aperture position. Because aperture objects require scalar shape parameters, only a single reference position is used for the conversion. For apertures with multiple positions used with a WCS that has spatially-varying distortions, this may produce inaccurate results for positions far from the first position.