CirclePixelRegion

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

Bases: regions.PixelRegion

A circle defined using pixel coordinates.

Parameters
centerPixCoord

Center position

radiusfloat

Radius

metaRegionMeta object, optional

A dictionary which stores the meta attributes of this region.

visualRegionVisual object, optional

A dictionary which stores the visual meta attributes of this region.

Examples

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

x, y = 6, 6
radius = 5.5

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

center = PixCoord(x=x, y=y)
reg = CirclePixelRegion(center=center, radius=radius)
patch = reg.as_artist(facecolor='none', edgecolor='red', lw=2)
ax.add_patch(patch)

plt.xlim(0, 15)
plt.ylim(0, 15)
ax.set_aspect('equal')

(Source code, png, hires.png, pdf)

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

Attributes Summary

area

Region area (float).

bounding_box

Bounding box (BoundingBox).

center

Descriptor class for PixelRegion which takes a scalar PixCoord object.

radius

Descriptor class for PixelRegion which takes a scalar python/numpy number.

Methods Summary

as_artist(self[, origin])

Matplotlib patch object for this region (matplotlib.patches.Circle)

contains(self, pixcoord)

Checks whether a position or positions fall inside the region.

rotate(self, center, angle)

Make a rotated region.

to_mask(self[, mode, subpixels])

Returns a mask for the aperture.

to_sky(self, wcs)

Returns a region defined in sky coordinates.

Attributes Documentation

area

Region area (float).

bounding_box

Bounding box (BoundingBox).

center

Descriptor class for PixelRegion which takes a scalar PixCoord object.

radius

Descriptor class for PixelRegion which takes a scalar python/numpy number.

Methods Documentation

as_artist(self, origin=0, 0, **kwargs)[source]

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. Default is (0, 0).

kwargsdict

All keywords that a Circle object accepts

Returns
patchCircle

Matplotlib circle patch

contains(self, pixcoord)[source]

Checks whether a position or positions fall inside the region.

Parameters
pixcoordPixCoord

The position or positions to check.

rotate(self, center, angle)[source]

Make a rotated region.

Rotates counter-clockwise for positive angle.

Parameters
centerPixCoord

Rotation center point

angleAngle

Rotation angle

Returns
regionCirclePixelRegion

Rotated region (an independent copy)

to_mask(self, mode='center', subpixels=1)[source]

Returns a mask for the aperture.

Parameters
mode{ ‘center’ | ‘exact’ | ‘subpixels’}, optional
The following modes are available:
  • 'center': returns 1 for pixels where the center is in the region, and 0 otherwise.

  • 'exact': returns a value between 0 and 1 giving the fractional level of overlap of the pixel with the region.

  • 'subpixels': A pixel is divided into subpixels and the center of each subpixel is tested (a subpixel is either completely in or out of the region). Returns a value between 0 and 1 giving the fractional level of overlap of the subpixels with the region. With subpixels set to 1, this method is equivalent to 'center'.

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
maskMask

A region mask object.

to_sky(self, wcs)[source]

Returns a region defined in sky coordinates.

Parameters
wcsWCS instance

The world coordinate system transformation to assume

Returns
sky_regionSkyRegion object.