CirclePixelRegion#
- class regions.CirclePixelRegion(center, radius, meta=None, visual=None)[source]#
Bases:
PixelRegionA circle defined using pixel coordinates.
- Parameters:
- center
PixCoord The center position.
- radiusfloat
The radius in pixels.
- meta
RegionMetaordict, optional A dictionary that stores the meta attributes of the region.
- visual
RegionVisualordict, optional A dictionary that stores the visual meta attributes of the region.
- center
Examples
import matplotlib.pyplot as plt from regions import CirclePixelRegion, PixCoord fig, ax = plt.subplots() reg = CirclePixelRegion(PixCoord(x=8, y=7), radius=3.5) patch = reg.plot(ax=ax, facecolor='none', edgecolor='red', lw=2, label='Circle') ax.legend(handles=(patch,), loc='upper center') ax.set_xlim(0, 15) ax.set_ylim(0, 15) ax.set_aspect('equal')
(
Source code,png,hires.png,pdf,svg)
Attributes Summary
The exact analytical area of the region shape.
Bounding box (
RegionBoundingBox).The center pixel position as a
PixCoord.The meta attributes as a
RegionMetaThe radius in pixels as a float.
The visual attributes as a
RegionVisual.Methods Summary
as_artist([origin])Return a matplotlib patch object for this region (
matplotlib.patches.Circle).contains(pixcoord)Check whether a position or positions fall inside the region, excluding the boundary.
covers(pixcoord)Check whether a position or positions fall inside the region, including the boundary.
rotate(center, angle)Rotate the region.
to_mask([mode, subpixels])Return a mask for the region.
to_polygon([n_points])Return a
PolygonPixelRegionthat approximates this circle.to_sky(wcs, *[, as_ellipse])Return a sky region from this pixel region.
to_spherical_sky([wcs, ...])Convert to an equivalent spherical
SphericalSkyRegioninstance.Attributes Documentation
- area#
- bounding_box#
Bounding box (
RegionBoundingBox).
- meta#
The meta attributes as a
RegionMeta
- radius#
The radius in pixels as a float.
- visual#
The visual attributes as a
RegionVisual.
Methods Documentation
- as_artist(origin=(0, 0), **kwargs)[source]#
Return a matplotlib patch object for this region (
matplotlib.patches.Circle).
- contains(pixcoord)[source]#
Check whether a position or positions fall inside the region, excluding the boundary.
This method considers points on the boundary as outside the region, consistent with Shapely’s
containsfunction and DE-9IM semantics.- Parameters:
- pixcoord
PixCoord The position or positions to check.
- pixcoord
- Returns:
- resultbool or
ndarray A boolean or boolean array indicating whether the position(s) are inside the region.
- resultbool or
See also
coversCheck if points are inside or on the boundary.
- covers(pixcoord)[source]#
Check whether a position or positions fall inside the region, including the boundary.
This method considers points on the boundary as inside the region, consistent with Shapely’s
coversfunction and DE-9IM semantics.- Parameters:
- pixcoord
PixCoord The position or positions to check.
- pixcoord
- Returns:
- resultbool or
ndarray A boolean or boolean array indicating whether the position(s) are inside or on the boundary of the region.
- resultbool or
See also
containsCheck if points are strictly inside (excludes boundary).
- rotate(center, angle)[source]#
Rotate the region.
Positive
anglecorresponds to counter-clockwise rotation.- Parameters:
- Returns:
- region
CirclePixelRegion The rotated region (which is an independent copy).
- region
- to_mask(mode='center', subpixels=1)[source]#
Return a mask for the region.
- Parameters:
- mode{‘center’, ‘exact’, ‘subpixels’}, optional
The method used to determine the overlap of the region on the pixel grid. Not all options are available for all region types. Note that the more precise methods are generally slower. The following methods are available:
'center': A pixel is considered to be entirely in or out of the region depending on whether its center is in or out of the region. The returned mask will contain values only of 0 (out) and 1 (in).'exact'(default): The exact fractional overlap of the region and each pixel is calculated. The returned mask will contain values between 0 and 1.'subpixel': A pixel is divided into subpixels (see thesubpixelskeyword), each of which are considered to be entirely in or out of the region depending on whether its center is in or out of the region. Ifsubpixels=1, this method is equivalent to'center'. The returned mask will contain values between 0 and 1.
- subpixelsint, optional
For the
'subpixel'mode, resample pixels by this factor in each dimension. That is, each pixel is divided intosubpixels ** 2subpixels.
- Returns:
- mask
RegionMask A mask for the region.
- mask
- to_polygon(n_points=100)[source]#
Return a
PolygonPixelRegionthat approximates this circle.- Parameters:
- n_pointsint, optional
The number of polygon vertices. Default is 100.
- Returns:
- polygon
PolygonPixelRegion A polygon region approximating the circle.
- polygon
- to_sky(wcs, *, as_ellipse=False)[source]#
Return a sky region from this pixel region.
- Parameters:
- wcsWCS object
A world coordinate system (WCS) transformation that supports the astropy shared interface for WCS (e.g.,
astropy.wcs.WCS).- as_ellipsebool, optional
If
True, return anEllipseSkyRegioninstead of aCircleSkyRegion. An ellipse is generally a better approximation when the WCS has distortions or different pixel scales along different axes. Default isFalse.
- Returns:
- region
CircleSkyRegionorEllipseSkyRegion The sky region. An ellipse is returned if
as_ellipseisTrue.
- region
- to_spherical_sky(wcs=None, include_boundary_distortions=False, n_points=None)[source]#
Convert to an equivalent spherical
SphericalSkyRegioninstance.- Parameters:
- wcs
WCSinstance, optional The world coordinate system transformation to use to convert between sky and pixel coordinates. Required if transforming with boundary distortions (if
include_boundary_distortionsis True). Ignored if boundary distortions not included.- include_boundary_distortionsbool, optional
If True, accounts for boundary distortions in spherical to planar conversions, by discretizing the boundary and converting the boundary polygon. Default is False, which converts to an equivalent idealized shape.
- n_pointsint, optional
The number of polygon vertices for boundary discretization. This keyword will have no effect unless
include_boundary_distortions=True. Default is 100.
- wcs
- Returns:
- spherical_sky_region
SphericalSkyRegion A spherical sky region, with an equivalent shape (if
include_boundary_distortionsis False), or a discretized polygon of the boundary (ifinclude_boundary_distortionsis True).
- spherical_sky_region