RectangularAperture#
- class photutils.aperture.RectangularAperture(positions, w, h, theta=0.0)[source]#
Bases:
PixelApertureA rectangular aperture defined in pixel coordinates.
The aperture has a single fixed size/shape, but it can have multiple positions (see the
positionsinput).- Parameters:
- positionsarray_like
The pixel coordinates of the aperture center(s) in one of the following formats:
- wfloat
The full width of the rectangle in pixels. For
theta=0the width side is along thexaxis.- hfloat
The full height of the rectangle in pixels. For
theta=0the height side is along theyaxis.- thetafloat or
Quantity, optional The rotation angle as an angular quantity (
QuantityorAngle) or value in radians (as a float) from the positivexaxis. The rotation angle increases counterclockwise.
- Raises:
- ValueError
ValueError If either width (
w) or height (h) is negative.
- ValueError
Examples
>>> from astropy.coordinates import Angle >>> from photutils.aperture import RectangularAperture
>>> theta = Angle(80, 'deg') >>> aper = RectangularAperture([10.0, 20.0], 5.0, 3.0) >>> aper = RectangularAperture((10.0, 20.0), 5.0, 3.0, theta=theta)
>>> pos1 = (10.0, 20.0) # (x, y) >>> pos2 = (30.0, 40.0) >>> pos3 = (50.0, 60.0) >>> aper = RectangularAperture([pos1, pos2, pos3], 5.0, 3.0) >>> aper = RectangularAperture((pos1, pos2, pos3), 5.0, 3.0, theta=theta)
Attributes Summary
The exact geometric area of the aperture shape.
The minimal bounding box for the aperture.
The full height in pixels.
Whether the instance is scalar (i.e., a single position).
The center pixel position(s).
The shape of the instance.
The counterclockwise rotation angle as an angular Quantity or a value in radians from the positive x axis.
The full width in pixels.
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_sky(wcs)Convert the aperture to a
SkyRectangularApertureobject 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.
- h#
The full height in pixels.
- isscalar#
Whether the instance is scalar (i.e., a single position).
- positions#
The center pixel position(s).
- shape#
The shape of the instance.
- theta#
The counterclockwise rotation angle as an angular Quantity or a value in radians from the positive x axis.
- w#
The full width in pixels.
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.'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].
- 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)#
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.'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].
- 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:
- 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.'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].
- 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_sky(wcs)[source]#
Convert the aperture to a
SkyRectangularApertureobject 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
SkyRectangularApertureobject A
SkyRectangularApertureobject.
- aperture
Notes
The aperture shape parameters are converted using the local WCS properties (pixel scale, rotation angle) 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.