PointPixelRegion¶
- class regions.PointPixelRegion(center, meta=None, visual=None)[source]¶
Bases:
PixelRegionA point position in pixel coordinates.
- Parameters:
- center
PixCoord The position of the point.
- 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 regions import PixCoord, PointPixelRegion, RegionVisual import matplotlib.pyplot as plt fig, ax = plt.subplots(1, 1) regs = [] regs.append(PointPixelRegion(PixCoord(2, 2), visual=RegionVisual(marker='D'))) regs.append(PointPixelRegion(PixCoord(2, 3), visual=RegionVisual(marker='+'))) regs.append(PointPixelRegion(PixCoord(3, 3), visual=RegionVisual(marker='^'))) regs.append(PointPixelRegion(PixCoord(3, 2), visual=RegionVisual(marker='*'))) regs.append(PointPixelRegion(PixCoord(2, 4), visual=RegionVisual(marker='x'))) regs.append(PointPixelRegion(PixCoord(4, 2))) for reg in regs: reg.plot(ax=ax) ax.set_xlim(0, 6) ax.set_ylim(0, 6) ax.set_aspect('equal')
(
Source code,png,hires.png,pdf,svg)
Attributes Summary
The exact analytical area of the region shape.
The minimal bounding box (in integer pixel coordinates) that contains the region.
The point pixel position as a
PixCoord.The meta attributes as a
RegionMetaThe visual attributes as a
RegionVisual.Methods Summary
as_artist([origin])Return a matplotlib Line2D object for this region (
matplotlib.lines.Line2D).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
SphericalSkyRegioninstance.Attributes Documentation
- area¶
- bounding_box¶
- meta¶
The meta attributes as a
RegionMeta
- visual¶
The visual attributes as a
RegionVisual.
Methods Documentation
- as_artist(origin=(0, 0), **kwargs)[source]¶
Return a matplotlib Line2D object for this region (
matplotlib.lines.Line2D).
- 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
PointPixelRegion 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_spherical_sky(wcs=None, include_boundary_distortions=False, discretize_kwargs=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 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.
- 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