CirclePixelRegion

class regions.CirclePixelRegion(center, radius, meta=None, visual=None)[source]

Bases: PixelRegion

A circle defined using pixel coordinates.

Parameters:
centerPixCoord

The center position.

radiusfloat

The radius in pixels.

metaRegionMeta or dict, optional

A dictionary that stores the meta attributes of the region.

visualRegionVisual or dict, optional

A dictionary that stores the visual meta attributes of the region.

Examples

from regions import PixCoord, CirclePixelRegion
import matplotlib.pyplot as plt

fig, ax = plt.subplots(1, 1)

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)

../_images/regions-CirclePixelRegion-1.png

Attributes Summary

area

The exact analytical area of the region shape.

bounding_box

Bounding box (RegionBoundingBox).

center

The center pixel position as a PixCoord.

meta

The meta attributes as a RegionMeta

radius

The radius in pixels as a float.

visual

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.

rotate(center, angle)

Rotate the region.

to_mask([mode, subpixels])

Return a mask for the region.

to_sky(wcs)

Return a region defined in sky coordinates.

to_spherical_sky([wcs, ...])

Convert to an equivalent spherical SphericalSkyRegion instance.

Attributes Documentation

area
bounding_box

Bounding box (RegionBoundingBox).

center

The center pixel position as a PixCoord.

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).

Parameters:
originarray_like, optional

The (x, y) pixel position of the origin of the displayed image.

**kwargsdict

Any keyword arguments accepted by Circle. These keywords will override any visual meta attributes of this region.

Returns:
artistCircle

A matplotlib circle patch.

contains(pixcoord)[source]

Check whether a position or positions fall inside the region.

Parameters:
pixcoordPixCoord

The position or positions to check.

rotate(center, angle)[source]

Rotate the region.

Positive angle corresponds to counter-clockwise rotation.

Parameters:
centerPixCoord

The rotation center point.

angleAngle

The rotation angle.

Returns:
regionCirclePixelRegion

The rotated region (which is an independent copy).

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 the subpixels keyword), 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. If subpixels=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 into subpixels ** 2 subpixels.

Returns:
maskRegionMask

A mask for the region.

to_sky(wcs)[source]

Return a region defined in sky coordinates.

Parameters:
wcsWCS

The world coordinate system transformation to use to convert from pixels to sky coordinates.

Returns:
sky_regionSkyRegion

The sky region.

to_spherical_sky(wcs=None, include_boundary_distortions=False, discretize_kwargs=None)[source]

Convert to an equivalent spherical SphericalSkyRegion instance.

Parameters:
wcsWCS instance, optional

The world coordinate system transformation to use to convert between sky and pixel coordinates. Required if transforming with boundary distortions (if include_boundary_distortions is True). Ignored if boundary distortions not included.

include_boundary_distortionsbool, optional

If True, accounts for boundary 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.

discretize_kwargsdict, optional

Optional keyword arguments to pass to discretize_boundary() method if including boundary distortions.

Returns:
spherical_sky_regionSphericalSkyRegion

A spherical sky region, with an equivalent shape (if include_boundary_distortions is False), or a discretized polygon of the boundary (if include_boundary_distortions is True).