RectanglePixelRegion

class regions.RectanglePixelRegion(center, width, height, angle=<Quantity 0. deg>, meta=None, visual=None)[source]

Bases: regions.PixelRegion

A rectangle in pixel coordinates.

Parameters:
center : PixCoord

The position of the center of the rectangle.

width : float

The width of the rectangle (before rotation) in pixels

height : float

The height of the rectangle (before rotation) in pixels

angle : Quantity, optional

The rotation angle of the rectangle, measured anti-clockwise. If set to zero (the default), the width axis is lined up with the x axis.

meta : RegionMeta object, optional

A dictionary which stores the meta attributes of this region.

visual : RegionVisual object, optional

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

Examples

import numpy as np
from astropy.coordinates import Angle
from regions import PixCoord, RectanglePixelRegion
import matplotlib.pyplot as plt

x, y = 15, 10
width, height = 8, 5
angle = Angle(30, 'deg')

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

center = PixCoord(x=x, y=y)
reg = RectanglePixelRegion(center=center, width=width,
                           height=height, angle=angle)
patch = reg.as_artist(facecolor='none', edgecolor='red', lw=2)
ax.add_patch(patch)

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

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

../_images/regions-RectanglePixelRegion-1.png

Attributes Summary

angle Descriptor class for SkyRegion which takes a scalar Quantity object.
area Region area (float)
bounding_box The minimal bounding box (BoundingBox) enclosing the exact rectangular region.
center Descriptor class for PixelRegion which takes a scalar PixCoord object.
corners Return the x, y coordinate pairs that define the corners
height Descriptor class for PixelRegion which takes a scalar python/numpy number.
width 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.Rectangle).
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_polygon(self) Return a 4-cornered polygon equivalent to this rectangle
to_sky(self, wcs) Returns a region defined in sky coordinates.

Attributes Documentation

angle

Descriptor class for SkyRegion which takes a scalar Quantity object.

area

Region area (float)

bounding_box

The minimal bounding box (BoundingBox) enclosing the exact rectangular region.

center

Descriptor class for PixelRegion which takes a scalar PixCoord object.

corners

Return the x, y coordinate pairs that define the corners

height

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

width

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

Parameters:
origin : array_like, optional

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

kwargs : dict

All keywords that a Rectangle object accepts

Returns:
patch : Rectangle

Matplotlib circle patch

contains(self, pixcoord)[source]

Checks whether a position or positions fall inside the region.

Parameters:
pixcoord : PixCoord

The position or positions to check.

rotate(self, center, angle)[source]

Make a rotated region.

Rotates counter-clockwise for positive angle.

Parameters:
center : PixCoord

Rotation center point

angle : Angle

Rotation angle

Returns:
region : RectanglePixelRegion

Rotated region (an independent copy)

to_mask(self, mode='center', subpixels=5)[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'.
subpixels : int, optional

For the 'subpixel' mode, resample pixels by this factor in each dimension. That is, each pixel is divided into subpixels ** 2 subpixels.

Returns:
mask : Mask

A region mask object.

to_polygon(self)[source]

Return a 4-cornered polygon equivalent to this rectangle

to_sky(self, wcs)[source]

Returns a region defined in sky coordinates.

Parameters:
wcs : WCS instance

The world coordinate system transformation to assume

Returns:
sky_region : SkyRegion object.