EllipsePixelRegion¶
- class regions.EllipsePixelRegion(center, width, height, angle=<Quantity 0. deg>, meta=None, visual=None)[source]¶
Bases:
PixelRegionAn ellipse in pixel coordinates.
- Parameters:
- center
PixCoord The position of the center of the ellipse.
- widthfloat
The width of the ellipse (before rotation) in pixels.
- heightfloat
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
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
from astropy.coordinates import Angle from regions import PixCoord, EllipsePixelRegion import matplotlib.pyplot as plt fig, ax = plt.subplots(1, 1) reg = EllipsePixelRegion(PixCoord(15, 10), width=16, height=10, angle=Angle(30, 'deg')) patch = reg.plot(ax=ax, facecolor='none', edgecolor='red', lw=2, label='Ellipse') ax.legend(handles=(patch,), loc='upper center') ax.set_xlim(0, 30) ax.set_ylim(0, 20) ax.set_aspect('equal')
(
Source code,png,hires.png,pdf,svg)
Attributes Summary
The rotation angle measured anti-clockwise as a
astropy.units.Quantityangle.The exact analytical area of the region shape.
The minimal bounding box (
RegionBoundingBox) enclosing the exact elliptical region.The center pixel position as a
PixCoord.The height of the ellipse (before rotation) in pixels as a float.
The meta attributes as a
RegionMetaThe visual attributes as a
RegionVisual.The width of the ellipse (before rotation) in pixels as a float.
Methods Summary
as_artist([origin])Return a matplotlib patch object for the region (
matplotlib.patches.Ellipse).as_mpl_selector(ax[, active, sync, ...])Return a matplotlib editable widget for this region (
matplotlib.widgets.EllipseSelector).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_polygon([n_points])Return a
PolygonPixelRegionthat approximates this ellipse.to_sky(wcs)Return a region defined in sky coordinates.
to_spherical_sky([wcs, ...])Convert to an equivalent spherical
SphericalSkyRegioninstance.Attributes Documentation
- angle¶
The rotation angle measured anti-clockwise as a
astropy.units.Quantityangle.
- area¶
- bounding_box¶
The minimal bounding box (
RegionBoundingBox) enclosing the exact elliptical region.
- height¶
The height of the ellipse (before rotation) in pixels as a float.
- meta¶
The meta attributes as a
RegionMeta
- visual¶
The visual attributes as a
RegionVisual.
- width¶
The width of the ellipse (before rotation) in pixels as a float.
Methods Documentation
- as_artist(origin=(0, 0), **kwargs)[source]¶
Return a matplotlib patch object for the region (
matplotlib.patches.Ellipse).
- as_mpl_selector(ax, active=True, sync=True, callback=None, drag_from_anywhere=False, **kwargs)[source]¶
Return a matplotlib editable widget for this region (
matplotlib.widgets.EllipseSelector).- Parameters:
- ax
Axes The matplotlib axes to add the selector to.
- activebool, optional
Whether the selector should be active by default.
- syncbool, optional
If
True(the default), the region will be kept in sync with the selector. Otherwise, the selector will be initialized with the values from the region but the two will then be disconnected.- callbackcallable, optional
If specified, this function will be called every time the region is updated. This only has an effect if
syncisTrue. If a callback is set, it is called for the first time once the selector has been created.- drag_from_anywherebool, optional
If
True, the selector can be moved by clicking anywhere within its bounds, else only at the central anchor (only available with matplotlib 3.5 upwards; default:False).- **kwargsdict
Additional keyword arguments that are passed to
matplotlib.widgets.EllipseSelector.
- ax
- Returns:
- selector
matplotlib.widgets.EllipseSelector The matplotlib selector.
- selector
Notes
Once a selector has been created, you will need to keep a reference to it until you no longer need it. In addition, you can enable/disable the selector at any point by calling
selector.set_active(True)orselector.set_active(False).
- contains(pixcoord)[source]¶
Check whether a position or positions fall inside the region.
- Parameters:
- pixcoord
PixCoord The position or positions to check.
- pixcoord
- rotate(center, angle)[source]¶
Rotate the region.
Positive
anglecorresponds to counter-clockwise rotation.- Parameters:
- Returns:
- region
EllipsePixelRegion The rotated region (which is an independent copy).
- region
- to_mask(mode='center', subpixels=5)[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 ellipse.- Parameters:
- n_pointsint, optional
The number of polygon vertices. Default is 100.
- Returns:
- polygon
PolygonPixelRegion A polygon region approximating the ellipse.
- polygon
- to_sky(wcs)[source]¶
Return a region defined in sky coordinates.
- Parameters:
- wcs
WCS The world coordinate system transformation to use to convert from pixels to sky coordinates.
- wcs
- Returns:
- sky_region
SkyRegion The sky region.
- sky_region
Notes
The conversion between pixel and sky coordinates is an approximation. The pixel region shape is mapped to a sky region shape using the local pixel scale and angle at the region center. Projection effects over the extent of the region are not accounted for. The region shape type is always preserved (e.g., a
CirclePixelRegionconverts to aCircleSkyRegion).For WCS with distortions (e.g., SIP), the local Jacobian matrix of the WCS transformation is used to compute directional scale factors and angle. For WCS without distortions, a local pixel scale and angle are computed using offset-based methods.
- 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 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