EllipsePixelRegion

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

Bases: regions.PixelRegion

An ellipse in pixel coordinates.

Parameters:
center : PixCoord

The position of the center of the ellipse.

width : float

The width of the ellipse (before rotation) in pixels

height : float

The height of the ellipse (before rotation) in pixels

angle : Quantity, optional

The rotation angle of the ellipse, 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.modeling.models import Ellipse2D
from astropy.coordinates import Angle
from regions import PixCoord, EllipsePixelRegion
import matplotlib.pyplot as plt
x0, y0 = 15, 10
a, b = 8, 5
theta = Angle(30, 'deg')
e = Ellipse2D(amplitude=100., x_0=x0, y_0=y0, a=a, b=b, theta=theta.radian)
y, x = np.mgrid[0:20, 0:30]
fig, ax = plt.subplots(1, 1)
ax.imshow(e(x, y), origin='lower', interpolation='none', cmap='Greys_r')

center = PixCoord(x=x0, y=y0)
reg = EllipsePixelRegion(center=center, width=2*a, height=2*b, angle=theta)
patch = reg.as_artist(facecolor='none', edgecolor='red', lw=2)
ax.add_patch(patch)

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

../_images/regions-EllipsePixelRegion-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 elliptical region.
center Descriptor class for PixelRegion which takes a scalar PixCoord object.
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.Ellipse).
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

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 elliptical region.

center

Descriptor class for PixelRegion which takes a scalar PixCoord object.

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

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 Ellipse object accepts

Returns:
patch : Ellipse

Matplotlib ellipse 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 : EllipsePixelRegion

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