SkyPolygonAperture#

class photutils.aperture.SkyPolygonAperture(positions, vertex_offsets)[source]#

Bases: SkyAperture

A polygon aperture defined in sky coordinates.

The aperture has a single fixed shape, defined by angular vertex_offsets relative to each positions entry, but it can have multiple positions. The angular offsets are applied as spherical offsets from each position (see spherical_offsets_by).

Parameters:
positionsSkyCoord

The celestial coordinates of the aperture center(s). This can be either scalar coordinates or an array of coordinates.

vertex_offsetsQuantity

Shape (n_vertices, 2) angular Quantity of polygon vertex offsets (d_lon, d_lat) relative to positions, 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.

Raises:
TypeErrorTypeError

If vertex_offsets is not a Quantity.

UnitsErrorUnitsError

If vertex_offsets does not have angular units.

ValueErrorValueError

If vertex_offsets does not have shape (n_vertices, 2), contains nonfinite values, or does not define a simple polygon of nonzero area with at least 3 vertices.

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

exterior_angle

The exterior angle of the regular polygon as an angular Quantity in degrees.

inner_radius

The angular inner (inscribed-circle) radius of the regular polygon as a Quantity in arcseconds, i.e., the distance from positions to the midpoint of each side.

interior_angle

The interior angle of the regular polygon as an angular Quantity in degrees.

is_regular

True if the polygon is regular (equal-length sides and equal interior angles, with all vertices at the same angular distance from positions).

isscalar

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

n_vertices

The number of vertices of the polygon.

outer_radius

The angular outer (circumscribed-circle) radius of the regular polygon as a Quantity in arcseconds, i.e., the distance from positions to each vertex.

perimeter

The angular perimeter of the polygon as a Quantity in arcseconds.

positions

The center position(s) in sky coordinates.

shape

The shape of the instance.

side_length

The angular side length of the regular polygon as a Quantity in arcseconds.

theta

The rotation angle of the regular polygon as an angular Quantity in degrees.

vertex_offsets

The (n_vertices, 2) angular Quantity of polygon vertex offsets (d_lon, d_lat) relative to positions.

vertices

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 SkyPolygonAperture from a center, vertex count, angular circumradius, and rotation angle.

from_vertices(vertices)

Construct a SkyPolygonAperture from a single set of absolute sky vertices.

to_pixel(wcs)

Convert the aperture to a PolygonAperture object defined in pixel coordinates.

Attributes Documentation

exterior_angle[source]#

The exterior angle of the regular polygon as an angular Quantity in 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 Quantity in arcseconds, i.e., the distance from positions to 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 Quantity in degrees.

This attribute is only defined for regular polygons. Accessing it for a nonregular polygon raises ValueError.

is_regular[source]#

True if the polygon is regular (equal-length sides and equal interior angles, with all vertices at the same angular distance from positions).

isscalar#

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

n_vertices[source]#

The number of vertices of the polygon.

outer_radius[source]#

The angular outer (circumscribed-circle) radius of the regular polygon as a Quantity in arcseconds, i.e., the distance from positions to 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 Quantity in 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 Quantity in 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 Quantity in degrees.

The angle is the position angle of the first stored vertex, measured from the +lat direction (North) toward increasing longitude (East), in the range [0, 360) deg. This convention matches the theta parameter of from_regular_polygon.

Note that the rotation of a regular polygon with n vertices is defined only modulo 360 / n degrees, 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. Clockwise vertex_offsets are 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 with n_positions positions, the returned SkyCoord has shape (n_positions, n_vertices).

Methods Documentation

copy()#

Make a deep copy of this object.

Returns:
resultAperture

A deep copy of the Aperture object.

classmethod from_regular_polygon(positions, n_vertices, radius, *, theta=<Quantity 0. deg>)[source]#

Construct a regular SkyPolygonAperture from a center, vertex count, angular circumradius, and rotation angle.

The first vertex is placed in the +lat direction from the center (North for standard celestial coordinates) for theta == 0 and is rotated toward increasing longitude (East) by theta.

Parameters:
positionsSkyCoord

The celestial coordinates of the aperture center(s).

n_verticesint

The number of vertices (must be at least 3).

radiusQuantity

The angular circumradius (outer radius) of the polygon (must be a positive angular Quantity).

thetaQuantity, optional

The rotation angle of the polygon, measured from the +lat direction (North) toward increasing longitude (East). This is the same position-angle convention as the theta parameter of the other sky apertures (e.g., SkyEllipticalAperture).

Returns:
apertureSkyPolygonAperture

The regular sky polygon aperture.

classmethod from_vertices(vertices)[source]#

Construct a SkyPolygonAperture from a single set of absolute sky vertices.

The aperture’s positions is 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_offsets is set to those offsets.

Parameters:
verticesSkyCoord

A SkyCoord with shape (n_vertices,) of absolute polygon vertex coordinates.

Returns:
apertureSkyPolygonAperture

A scalar sky polygon aperture whose vertices property reproduces the input vertices. Input that is clockwise in the (d_lon, d_lat) offset plane is returned in reversed (counterclockwise) order.

Raises:
TypeErrorTypeError

If vertices is not a one-dimensional SkyCoord.

ValueErrorValueError

If vertices contains nonfinite values or does not define a simple polygon of nonzero area with at least 3 vertices.

to_pixel(wcs)[source]#

Convert the aperture to a PolygonAperture object defined in pixel coordinates.

The conversion uses wcs.world_to_pixel directly 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:
aperturePolygonAperture

The equivalent pixel-coordinate polygon aperture.