Skip to content

Commit 2e72595

Browse files
committed
TST: Update test_as_mpl_selector to accept rotated regions
1 parent 327d327 commit 2e72595

File tree

5 files changed

+28
-18
lines changed

5 files changed

+28
-18
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ New Features
5959

6060
- Added the DS9 'boxcircle' point symbol. [#387]
6161

62+
- Enable rotation of the ``as_mpl_selector`` widgets for rectangular
63+
and ellipse regions with matplotlib versions supporting this. [#390]
64+
6265
- Added the ability to add and subtract ``PixCoord`` objects. [#396]
6366

6467
- Added an ``origin`` keyword to ``PolygonPixelRegion`` to allow

regions/shapes/ellipse.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def as_mpl_selector(self, ax, active=True, sync=True, callback=None,
280280
if hasattr(self, '_mpl_selector'):
281281
raise AttributeError('Cannot attach more than one selector to a region.')
282282

283-
if self.angle.value != 0 and not hasattr(EllipseSelector, '_rotation'):
283+
if self.angle.value != 0 and not hasattr(EllipseSelector, 'rotation'):
284284
raise NotImplementedError('Cannot create matplotlib selector for rotated ellipse.')
285285

286286
if sync:
@@ -307,8 +307,7 @@ def sync_callback(*args, **kwargs):
307307
xy0[1], self.center.y + self.height / 2)
308308

309309
if self.angle.value != 0:
310-
self._mpl_selector._set_corner_width_rotation(xy0, self.width, self.height,
311-
self.angle.to_value('radian'))
310+
self._mpl_selector.rotation = self.angle.to_value('radian')
312311

313312
self._mpl_selector.set_active(active)
314313
self._mpl_selector_callback = callback

regions/shapes/rectangle.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def as_mpl_selector(self, ax, active=True, sync=True, callback=None,
276276
if hasattr(self, '_mpl_selector'):
277277
raise AttributeError('Cannot attach more than one selector to a region.')
278278

279-
if self.angle.value != 0 and not hasattr(RectangleSelector, '_rotation'):
279+
if self.angle.value != 0 and not hasattr(RectangleSelector, 'rotation'):
280280
raise NotImplementedError('Cannot create matplotlib selector for rotated rectangle.')
281281

282282
if sync:
@@ -303,8 +303,7 @@ def sync_callback(*args, **kwargs):
303303
xy0[1], self.center.y + self.height / 2)
304304

305305
if self.angle.value != 0:
306-
self._mpl_selector._set_corner_width_rotation(xy0, self.width, self.height,
307-
self.angle.to_value('radian'))
306+
self._mpl_selector.rotation = self.angle.to_value('radian')
308307

309308
self._mpl_selector.set_active(active)
310309
self._mpl_selector_callback = callback

regions/shapes/tests/test_ellipse.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,16 @@ def update_mask(reg):
129129
# For now this will only work with unrotated ellipses. Once this
130130
# works with rotated ellipses, the following exception check can
131131
# be removed as well as the ``angle=0 * u.deg`` in the call to
132-
# copy() below.
133-
with pytest.raises(NotImplementedError,
134-
match=('Cannot create matplotlib selector for rotated ellipse.')):
135-
self.reg.as_mpl_selector(ax)
132+
# copy() below - should (hopefully) be implemented with mpl 3.6.
133+
if MPL_VERSION < 36:
134+
with pytest.raises(NotImplementedError,
135+
match=('Cannot create matplotlib selector for rotated ellipse.')):
136+
self.reg.as_mpl_selector(ax)
137+
angle = 0 * u.deg
138+
else:
139+
angle = self.reg.angle
136140

137-
region = self.reg.copy(angle=0 * u.deg)
141+
region = self.reg.copy(angle=angle)
138142

139143
selector = region.as_mpl_selector(ax, callback=update_mask, sync=sync)
140144

@@ -160,7 +164,7 @@ def update_mask(reg):
160164
assert_allclose(region.center.y, 4)
161165
assert_allclose(region.width, 4)
162166
assert_allclose(region.height, 3)
163-
assert_quantity_allclose(region.angle, 0 * u.deg)
167+
assert_quantity_allclose(region.angle, angle)
164168

165169
assert_equal(mask, 0)
166170

regions/shapes/tests/test_rectangle.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,17 @@ def update_mask(reg):
135135
# For now this will only work with unrotated rectangles. Once
136136
# this works with rotated rectangles, the following exception
137137
# check can be removed as well as the ``angle=0 * u.deg`` in the
138-
# call to copy() below.
139-
with pytest.raises(NotImplementedError,
140-
match=('Cannot create matplotlib selector for rotated rectangle.')):
141-
self.reg.as_mpl_selector(ax)
138+
# copy() below - should (hopefully) be implemented with mpl 3.6.
139+
if MPL_VERSION < 36:
140+
with pytest.raises(NotImplementedError,
141+
match=('Cannot create matplotlib selector for rotated rectangle.')):
142+
self.reg.as_mpl_selector(ax)
142143

143-
region = self.reg.copy(angle=0 * u.deg)
144+
angle = 0 * u.deg
145+
else:
146+
angle = self.reg.angle
147+
148+
region = self.reg.copy(angle=angle)
144149

145150
selector = region.as_mpl_selector(ax, callback=update_mask, sync=sync)
146151

@@ -164,7 +169,7 @@ def update_mask(reg):
164169
assert_allclose(region.center.y, 4)
165170
assert_allclose(region.width, 4)
166171
assert_allclose(region.height, 3)
167-
assert_quantity_allclose(region.angle, 0 * u.deg)
172+
assert_quantity_allclose(region.angle, angle)
168173

169174
assert_equal(mask, 0)
170175

0 commit comments

Comments
 (0)