Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
width : `~astropy.units.Quantity`
The width of the ellipse (before rotation) as an angle
height : `~astropy.units.Quantity`
The height of the ellipse (before rotation) as an angle
angle : `~astropy.units.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 longitude axis
of the celestial coordinates.
meta : `~regions.RegionMeta` object, optional
A dictionary which stores the meta attributes of this region.
visual : `~regions.RegionVisual` object, optional
A dictionary which stores the visual meta attributes of this region.
"""
_params = ('center', 'width', 'height', 'angle')
center = ScalarSky('center')
width = QuantityLength('width')
height = QuantityLength('height')
angle = QuantityLength('angle')
def __init__(self, center, width, height, angle=0. * u.deg, meta=None, visual=None):
self.center = center
self.width = width
self.height = height
self.angle = angle
self.meta = meta or RegionMeta()
self.visual = visual or RegionVisual()
def to_pixel(self, wcs):
center, scale, north_angle = skycoord_to_pixel_scale_angle(self.center, wcs)
# FIXME: The following line is needed to get a scalar PixCoord
center = PixCoord(float(center.x), float(center.y))
height = self.height.to('deg').value * scale
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)
"""
_params = ('center', 'width', 'height', 'angle')
center = ScalarPix('center')
width = ScalarLength('width')
height = ScalarLength('height')
angle = QuantityLength('angle')
def __init__(self, center, width, height, angle=0. * u.deg, meta=None,
visual=None):
self.center = center
self.width = width
self.height = height
self.angle = angle
self.meta = meta or RegionMeta()
self.visual = visual or RegionVisual()
@property
def area(self):
"""Region area (float)"""
return math.pi / 4 * self.width * self.height
def contains(self, pixcoord):
Parameters
----------
center : `~astropy.coordinates.SkyCoord`
The position of the center of the annulus.
inner_radius : `~astropy.units.Quantity`
The inner radius of the annulus in angular units
outer_radius : `~astropy.units.Quantity`
The outer radius of the annulus in angular units
meta : `~regions.RegionMeta` object, optional
A dictionary which stores the meta attributes of this region.
visual : `~regions.RegionVisual` object, optional
A dictionary which stores the visual meta attributes of this region.
"""
_params = ("center", "inner_radius", "outer_radius")
center = ScalarSky("center")
inner_radius = QuantityLength("inner_radius")
outer_radius = QuantityLength("outer_radius")
def __init__(self, center, inner_radius, outer_radius, meta=None, visual=None):
self.center = center
self.inner_radius = inner_radius
self.outer_radius = outer_radius
self.meta = meta or RegionMeta()
self.visual = visual or RegionVisual()
def to_pixel(self, wcs):
center, scale, _ = skycoord_to_pixel_scale_angle(self.center, wcs)
# FIXME: The following line is needed to get a scalar PixCoord
center = PixCoord(float(center.x), float(center.y))
inner_radius = self.inner_radius.to("deg").value * scale
outer_radius = self.outer_radius.to("deg").value * scale
return CircleAnnulusPixelRegion(
A circle defined using sky coordinates.
Parameters
----------
center : `~astropy.coordinates.SkyCoord`
Center position
radius : `~astropy.units.Quantity`
Radius in angular units
meta : `~regions.RegionMeta` object, optional
A dictionary which stores the meta attributes of this region.
visual : `~regions.RegionVisual` object, optional
A dictionary which stores the visual meta attributes of this region.
"""
_params = ('center', 'radius')
center = ScalarSky('center')
radius = QuantityLength("radius")
def __init__(self, center, radius, meta=None, visual=None):
self.center = center
self.radius = radius
self.meta = meta or RegionMeta()
self.visual = visual or RegionVisual()
def to_pixel(self, wcs):
center, scale, _ = skycoord_to_pixel_scale_angle(self.center, wcs)
radius = self.radius.to('deg').value * scale
return CirclePixelRegion(center, radius, self.meta, self.visual)
class AsymmetricAnnulusSkyRegion(SkyRegion):
"""Helper class for asymmetric annuli sky regions.
Used for ellipse and rectangle annuli below.
"""
_params = (
"center",
"inner_width",
"inner_height",
"outer_width",
"outer_height",
"angle",
)
center = ScalarSky("center")
inner_width = QuantityLength("inner_width")
outer_width = QuantityLength("outer_width")
inner_height = QuantityLength("inner_height")
outer_height = QuantityLength("outer_height")
angle = QuantityLength("angle")
def __init__(
self,
center,
inner_width,
outer_width,
inner_height,
outer_height,
angle=0 * u.deg,
meta=None,
visual=None,
):
self.center = center
class AsymmetricAnnulusSkyRegion(SkyRegion):
"""Helper class for asymmetric annuli sky regions.
Used for ellipse and rectangle annuli below.
"""
_params = (
"center",
"inner_width",
"inner_height",
"outer_width",
"outer_height",
"angle",
)
center = ScalarSky("center")
inner_width = QuantityLength("inner_width")
outer_width = QuantityLength("outer_width")
inner_height = QuantityLength("inner_height")
outer_height = QuantityLength("outer_height")
angle = QuantityLength("angle")
def __init__(
self,
center,
inner_width,
outer_width,
inner_height,
outer_height,
angle=0 * u.deg,
meta=None,
visual=None,
):
width : `~astropy.units.Quantity`
The width of the rectangle (before rotation) as an angle
height : `~astropy.units.Quantity`
The height of the rectangle (before rotation) as an angle
angle : `~astropy.units.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 longitude axis
of the celestial coordinates.
meta : `~regions.RegionMeta` object, optional
A dictionary which stores the meta attributes of this region.
visual : `~regions.RegionVisual` object, optional
A dictionary which stores the visual meta attributes of this region.
"""
_params = ('center', 'width', 'height', 'angle')
center = ScalarSky('center')
width = QuantityLength('width')
height = QuantityLength('height')
angle = QuantityLength('angle')
def __init__(self, center, width, height, angle=0 * u.deg, meta=None, visual=None):
self.center = center
self.width = width
self.height = height
self.angle = angle
self.meta = meta or {}
self.visual = visual or {}
def to_pixel(self, wcs):
center, scale, north_angle = skycoord_to_pixel_scale_angle(self.center, wcs)
# FIXME: The following line is needed to get a scalar PixCoord
center = PixCoord(float(center.x), float(center.y))
width = self.width.to('deg').value * scale
Used for ellipse and rectangle annuli below.
"""
_params = (
"center",
"inner_width",
"inner_height",
"outer_width",
"outer_height",
"angle",
)
center = ScalarSky("center")
inner_width = QuantityLength("inner_width")
outer_width = QuantityLength("outer_width")
inner_height = QuantityLength("inner_height")
outer_height = QuantityLength("outer_height")
angle = QuantityLength("angle")
def __init__(
self,
center,
inner_width,
outer_width,
inner_height,
outer_height,
angle=0 * u.deg,
meta=None,
visual=None,
):
self.center = center
self.inner_width = inner_width
self.outer_width = outer_width
Used for ellipse and rectangle annuli below.
"""
_params = (
"center",
"inner_width",
"inner_height",
"outer_width",
"outer_height",
"angle",
)
center = ScalarSky("center")
inner_width = QuantityLength("inner_width")
outer_width = QuantityLength("outer_width")
inner_height = QuantityLength("inner_height")
outer_height = QuantityLength("outer_height")
angle = QuantityLength("angle")
def __init__(
self,
center,
inner_width,
outer_width,
inner_height,
outer_height,
angle=0 * u.deg,
meta=None,
visual=None,
):
self.center = center
self.inner_width = inner_width
self.outer_width = outer_width
self.inner_height = inner_height
"""Helper class for asymmetric annuli sky regions.
Used for ellipse and rectangle annuli below.
"""
_params = (
"center",
"inner_width",
"inner_height",
"outer_width",
"outer_height",
"angle",
)
center = ScalarSky("center")
inner_width = QuantityLength("inner_width")
outer_width = QuantityLength("outer_width")
inner_height = QuantityLength("inner_height")
outer_height = QuantityLength("outer_height")
angle = QuantityLength("angle")
def __init__(
self,
center,
inner_width,
outer_width,
inner_height,
outer_height,
angle=0 * u.deg,
meta=None,
visual=None,
):
self.center = center
self.inner_width = inner_width