SkyPolygonAperture#
- class photutils.aperture.SkyPolygonAperture(positions, vertex_offsets)[source]#
Bases:
SkyApertureA polygon aperture defined in sky coordinates.
The aperture has a single fixed shape, defined by angular
vertex_offsetsrelative to eachpositionsentry, but it can have multiple positions. The angular offsets are applied as spherical offsets from each position (seespherical_offsets_by).- Parameters:
- positions
SkyCoord The celestial coordinates of the aperture center(s). This can be either scalar coordinates or an array of coordinates.
- vertex_offsets
Quantity Shape
(n_vertices, 2)angular Quantity of polygon vertex offsets(d_lon, d_lat)relative topositions, applied as spherical offsets from each position. The polygon must be simple (non-self-intersecting) with at least 3 vertices. The polygon may be convex or nonconvex. Either vertex ordering is accepted. The input is normalized internally to counterclockwise order in the(d_lon, d_lat)plane.
- positions
- Raises:
- TypeError
TypeError If
vertex_offsetsis not aQuantity.- UnitsError
UnitsError If
vertex_offsetsdoes not have angular units.- ValueError
ValueError If
vertex_offsetsdoes not have shape(n_vertices, 2), contains nonfinite values, or does not define a simple polygon of nonzero area with at least 3 vertices.
- TypeError
Examples
>>> import astropy.units as u >>> import numpy as np >>> from astropy.coordinates import SkyCoord >>> from photutils.aperture import SkyPolygonAperture >>> positions = SkyCoord(ra=[10.0, 20.0], dec=[30.0, 40.0], unit='deg') >>> theta = np.linspace(0, 2 * np.pi, 5, endpoint=False) >>> r = 1.0 >>> offsets = np.column_stack([r * np.cos(theta), ... r * np.sin(theta)]) * u.arcsec >>> aper = SkyPolygonAperture(positions, offsets)
Attributes Summary
The exterior angle of the regular polygon as an angular
Quantityin degrees.The angular inner (inscribed-circle) radius of the regular polygon as a
Quantityin arcseconds, i.e., the distance frompositionsto the midpoint of each side.The interior angle of the regular polygon as an angular
Quantityin degrees.Trueif the polygon is regular (equal-length sides and equal interior angles, with all vertices at the same angular distance frompositions).Whether the instance is scalar (i.e., a single position).
The number of vertices of the polygon.
The angular outer (circumscribed-circle) radius of the regular polygon as a
Quantityin arcseconds, i.e., the distance frompositionsto each vertex.The angular perimeter of the polygon as a
Quantityin arcseconds.The center position(s) in sky coordinates.
The shape of the instance.
The angular side length of the regular polygon as a
Quantityin arcseconds.The rotation angle of the regular polygon as an angular
Quantityin degrees.The (n_vertices, 2) angular Quantity of polygon vertex offsets (d_lon, d_lat) relative to
positions.The absolute sky vertices of the polygon at each aperture position, as a
SkyCoord.Methods Summary
copy()Make a deep copy of this object.
from_regular_polygon(positions, n_vertices, ...)Construct a regular
SkyPolygonAperturefrom a center, vertex count, angular circumradius, and rotation angle.from_vertices(vertices)Construct a
SkyPolygonAperturefrom a single set of absolute sky vertices.to_pixel(wcs)Convert the aperture to a
PolygonApertureobject defined in pixel coordinates.Attributes Documentation
- exterior_angle[source]#
The exterior angle of the regular polygon as an angular
Quantityin degrees.This attribute is only defined for regular polygons. Accessing it for a nonregular polygon raises
ValueError.
- inner_radius[source]#
The angular inner (inscribed-circle) radius of the regular polygon as a
Quantityin arcseconds, i.e., the distance frompositionsto the midpoint of each side.This is also called the inradius.
This attribute is only defined for regular polygons. Accessing it for a nonregular polygon raises
ValueError.
- interior_angle[source]#
The interior angle of the regular polygon as an angular
Quantityin degrees.This attribute is only defined for regular polygons. Accessing it for a nonregular polygon raises
ValueError.
- is_regular[source]#
Trueif the polygon is regular (equal-length sides and equal interior angles, with all vertices at the same angular distance frompositions).
- isscalar#
Whether the instance is scalar (i.e., a single position).
- outer_radius[source]#
The angular outer (circumscribed-circle) radius of the regular polygon as a
Quantityin arcseconds, i.e., the distance frompositionsto each vertex.This is also called the circumradius.
This attribute is only defined for regular polygons. Accessing it for a nonregular polygon raises
ValueError.
- perimeter[source]#
The angular perimeter of the polygon as a
Quantityin arcseconds.The perimeter is computed as the sum of the Euclidean distances between consecutive vertices in the
(d_lon, d_lat)offset plane.
- positions#
The center position(s) in sky coordinates.
- shape#
The shape of the instance.
- side_length[source]#
The angular side length of the regular polygon as a
Quantityin arcseconds.This attribute is only defined for regular polygons. Accessing it for a nonregular polygon raises
ValueError.
- theta[source]#
The rotation angle of the regular polygon as an angular
Quantityin degrees.The angle is the position angle of the first stored vertex, measured from the
+latdirection (North) toward increasing longitude (East), in the range[0, 360) deg. This convention matches thethetaparameter offrom_regular_polygon.Note that the rotation of a regular polygon with
nvertices is defined only modulo360 / ndegrees, because rotating it by its exterior angle reproduces the same shape. The reported value therefore depends on which vertex is stored first, which is not necessarily the first vertex the user input. Clockwisevertex_offsetsare reversed when they are normalized to counterclockwise order.This attribute is only defined for regular polygons. Accessing it for a nonregular polygon raises
ValueError.
- vertex_offsets#
The (n_vertices, 2) angular Quantity of polygon vertex offsets (d_lon, d_lat) relative to
positions.
- vertices[source]#
The absolute sky vertices of the polygon at each aperture position, as a
SkyCoord.For a scalar aperture, the returned SkyCoord has shape
(n_vertices,). For an aperture withn_positionspositions, the returned SkyCoord has shape(n_positions, n_vertices).
Methods Documentation
- classmethod from_regular_polygon(positions, n_vertices, radius, *, theta=<Quantity 0. deg>)[source]#
Construct a regular
SkyPolygonAperturefrom a center, vertex count, angular circumradius, and rotation angle.The first vertex is placed in the
+latdirection from the center (North for standard celestial coordinates) fortheta == 0and is rotated toward increasing longitude (East) bytheta.- Parameters:
- positions
SkyCoord The celestial coordinates of the aperture center(s).
- n_verticesint
The number of vertices (must be at least 3).
- radius
Quantity The angular circumradius (outer radius) of the polygon (must be a positive angular Quantity).
- theta
Quantity, optional The rotation angle of the polygon, measured from the
+latdirection (North) toward increasing longitude (East). This is the same position-angle convention as thethetaparameter of the other sky apertures (e.g.,SkyEllipticalAperture).
- positions
- Returns:
- aperture
SkyPolygonAperture The regular sky polygon aperture.
- aperture
- classmethod from_vertices(vertices)[source]#
Construct a
SkyPolygonAperturefrom a single set of absolute sky vertices.The aperture’s
positionsis set to an approximate centroid of the input vertices, computed as the mean of the spherical offsets of the vertices from the first vertex. The spherical offsets of the vertices from this centroid average to approximately zero.vertex_offsetsis set to those offsets.- Parameters:
- vertices
SkyCoord A SkyCoord with shape
(n_vertices,)of absolute polygon vertex coordinates.
- vertices
- Returns:
- aperture
SkyPolygonAperture A scalar sky polygon aperture whose
verticesproperty reproduces the input vertices. Input that is clockwise in the(d_lon, d_lat)offset plane is returned in reversed (counterclockwise) order.
- aperture
- Raises:
- TypeError
TypeError If
verticesis not a one-dimensionalSkyCoord.- ValueError
ValueError If
verticescontains nonfinite values or does not define a simple polygon of nonzero area with at least 3 vertices.
- TypeError
- to_pixel(wcs)[source]#
Convert the aperture to a
PolygonApertureobject defined in pixel coordinates.The conversion uses
wcs.world_to_pixeldirectly on the absolute sky vertex coordinates, evaluated at the first aperture position.- 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
PolygonAperture The equivalent pixel-coordinate polygon aperture.
- aperture