Skip to content

Commit

Permalink
Merge 937196e into 95b4408
Browse files Browse the repository at this point in the history
  • Loading branch information
joleroi committed May 4, 2016
2 parents 95b4408 + 937196e commit 9802f42
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 27 deletions.
61 changes: 61 additions & 0 deletions regions/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,36 @@ def to_shapely(self):
"""
raise NotImplementedError("")

@abc.abstractmethod
def as_patch(self, **kwargs):
"""Convert to mpl patch
Returns
-------
patch : `~matplotlib.patches.Patch`
Matplotlib patch
"""
raise NotImplementedError

def plot(self, ax=None, **kwargs):
"""
Calls as_patch method forwarding all kwargs and adds patch
to given axis.
Parameters
----------
ax : `~matplotlib.axes`, optional
Axis
"""
import matplotlib.pyplot as plt

ax = plt.gca() if ax is None else ax

patch = self.as_patch(**kwargs)
ax.add_patch(patch)

return ax


@six.add_metaclass(abc.ABCMeta)
class SkyRegion(Region):
Expand Down Expand Up @@ -244,3 +274,34 @@ def to_pixel(self, wcs, mode='local', tolerance=None):
The tolerance for the ``'full'`` mode described above.
"""
raise NotImplementedError("")

@abc.abstractmethod
def as_patch(self, ax, **kwargs):
"""Convert to mpl patch using a given wcs axis
Parameters
----------
ax : `~astropy.wcsaxes.WCSAxes`
WCS axis object
Returns
-------
patch : `~matplotlib.patches.Patch`
Matplotlib patch
"""
raise NotImplementedError

def plot(self, ax=None, **kwargs):
"""
Calls as_patch method forwarding all kwargs and adds patch
to given wcs axis.
Parameters
----------
ax : `~astropy.wcsaxes.WCSAxes`
WCS axis object
"""
patch = self.as_patch(ax, **kwargs)
ax.add_patch(patch)

return ax
26 changes: 2 additions & 24 deletions regions/shapes/circle.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,7 @@ def to_mask(self, mode='center'):
# TODO: needs to be implemented
raise NotImplementedError("")

def to_mpl_patch(self, **kwargs):
"""Convert to mpl patch.
Returns
-------
patch : `~matplotlib.mpatches.Circle`
Matplotlib patch
"""
def as_patch(self, **kwargs):
import matplotlib.patches as mpatches

patch = mpatches.Circle(self.center, self.radius, **kwargs)
Expand Down Expand Up @@ -134,22 +127,7 @@ def to_pixel(self, mywcs, mode='local', tolerance=None):

return CirclePixelRegion(pixel_positions, radius_pix)

def to_mpl_patch(self, ax, **kwargs):
"""Convert to mpl patch using a given wcs axis
Parameters
----------
ax : `~astropy.wcsaxes.WCSAxes`
WCS axis object
kwargs : dict
kwargs are forwarded to mpatches.Circle
Returns
-------
patch : `~matplotlib.mpatches.Circle`
Matplotlib patch
"""

def as_patch(self, ax, **kwargs):
import matplotlib.patches as mpatches

val = self.center.icrs
Expand Down
7 changes: 7 additions & 0 deletions regions/shapes/ellipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ def to_mask(self, mode='center'):
# TODO: needs to be implemented
raise NotImplementedError("")

def as_patch(self, **kwargs):
# TODO: needs to be implemented
raise NotImplementedError("")


class EllipseSkyRegion(SkyRegion):
Expand Down Expand Up @@ -92,3 +95,7 @@ def __contains__(self, skycoord):
def to_pixel(self, wcs, mode='local', tolerance=None):
# TODO: needs to be implemented
raise NotImplementedError("")

def as_patch(self, **kwargs):
# TODO: needs to be implemented
raise NotImplementedError("")
9 changes: 9 additions & 0 deletions regions/shapes/point.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def to_mask(self, mode='center'):
# TODO: needs to be implemented
raise NotImplementedError("")

def as_patch(self, **kwargs):
# TODO: needs to be implemented
raise NotImplementedError("")



class PointSkyRegion(SkyRegion):
Expand Down Expand Up @@ -68,3 +72,8 @@ def __contains__(self, skycoord):
def to_pixel(self, wcs, mode='local', tolerance=None):
# TODO: needs to be implemented
raise NotImplementedError("")

def as_patch(self, **kwargs):
# TODO: needs to be implemented
raise NotImplementedError("")

7 changes: 7 additions & 0 deletions regions/shapes/polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def to_mask(self, mode='center'):
# TODO: needs to be implemented
raise NotImplementedError("")

def as_patch(self, **kwargs):
# TODO: needs to be implemented
raise NotImplementedError("")


class PolygonSkyRegion(SkyRegion):
Expand Down Expand Up @@ -68,3 +71,7 @@ def __contains__(self, skycoord):
def to_pixel(self, wcs, mode='local', tolerance=None):
# TODO: needs to be implemented
raise NotImplementedError("")

def as_patch(self, **kwargs):
# TODO: needs to be implemented
raise NotImplementedError("")
2 changes: 1 addition & 1 deletion regions/shapes/rectangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class RectangleSkyRegion(SkyRegion):
def __init__(self, center, height, width, angle=0 * u.deg, meta=None, visual=None):
# TODO: use quantity_input to check that height, width, and angle are angles
self.center = center
self.height = minor
self.height = height
self.width = width
self.angle = angle
self.meta = meta or {}
Expand Down
5 changes: 3 additions & 2 deletions regions/shapes/tests/test_circle.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ def test_plot():
wcs = WCS(h)
fig = plt.figure()
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], projection=wcs)
p = c.to_mpl_patch(ax, alpha=0.6)
ax.add_patch(p)
p = c.as_patch(ax, alpha=0.6)

assert_allclose(p.center[0], skycoord.icrs.ra.value)
assert_allclose(p.center[1], skycoord.icrs.dec.value)
assert p.get_facecolor() == (1, 0, 0, 0.6)

c.plot(ax, alpha=0.6)

0 comments on commit 9802f42

Please sign in to comment.