-
-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding support for rotating mpl selectors of Ellipse,RectanglePixelRegion #390
base: main
Are you sure you want to change the base?
Conversation
de37303
to
f9545ad
Compare
And of course existing and new tests would need a setup with matplotlib/matplotlib#19864 to test the actual functionality, but at least I could get started with •3 on my local installation. |
Yes, and if we are going to rely on |
Maybe it's worth waiting if |
Yes, that sounds good. I just realized that matplotlib/matplotlib#19864 is still a draft PR. Perhaps it's worth contacting the author about exposing those attributes and also the potential bug with the bounding box offset. |
Yes, also just noticed it had been marked ready for review and then changed back to draft. |
Now mpl has a competing PR for enabling rotation in matplotlib/matplotlib#20839; haven't got to compare the two in detail or checked if this PR will work with the other approach, but maybe it's best to wait a while which one comes out on top. |
Updated to the API from matplotlib/matplotlib#20839 now; the extents of the mask on a rotated selector have slightly changed now at the % level (see test outcomes for the |
e41198d
to
f38f2cb
Compare
Seems azure no longer provides a py36 on macOS. |
Could you rebase this? Also, can we add support for circles? |
@keflavich You want to rotate a circle? 🤔 |
If it's rotated around a bbox corner – but that will still require support on the matplotlib first. Or is it about adding a |
ha, no, sorry, I don't want to rotate a circle =) but it does deserve to have its own selector. Sorry, that is a different issue. |
f38f2cb
to
3bff348
Compare
No CI tests except RTD? |
That's odd. Do you have |
(you may need to pull the latest version of main and then rebase) |
I just checked I have the 581e81a version of https://github.com/dhomeier/regions/blob/3bff348e1596620e968438abeb04ed40ec7e9a0f/.github/workflows/ci_tests.yml (literally rebased an hour ago or so...) |
3bff348
to
2ebeaca
Compare
One more upstream commit – strange... |
I've finally gotten to play with this a little more, and the rotation selector works in that it rotates the region... but it doesn't follow the cursor. Example: from spectral_cube import SpectralCube
from regions import PixCoord, EllipsePixelRegion
import pylab as pl
cube = SpectralCube.read('http://www.astropy.org/astropy-data/l1448/l1448_13co.fits')
fig = pl.figure()
ax = fig.gca()
pl.imshow(cube.max(axis=0).value)
ellipse = EllipsePixelRegion(center=PixCoord(x=66, y=33), width=21, height=10,
angle=-23*u.deg, visual={'color': 'yellow'})
selector = ellipse.as_mpl_selector(ax) when I press Also, there's no visual indicator about whether I'm in rotate or stretch mode; it would be nice to switch the corners to angled arrows or something that indicates we're rotating. That might be an upstream request. If these issues are entirely upstream, though, I'd recommend merging this and noting that there are some UI issues, |
IIRC, this feature requires |
2ebeaca
to
0dce5a8
Compare
@@ -59,6 +59,9 @@ New Features | |||
|
|||
- Added the DS9 'boxcircle' point symbol. [#387] | |||
|
|||
- Enable rotation of the ``as_mpl_selector`` widgets for rectangular | |||
and ellipse regions with matplotlib versions supporting this. [#390] | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will need to be be moved to version 0.8.
MPL_VERSION = 10 * int(MPL_VERSION[0]) + int(MPL_VERSION[1]) | ||
except ImportError: | ||
HAS_MATPLOTLIB = False | ||
MPL_VER_STR = 'None' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to streamline the matplotilb version checking? Something like what astropy uses for numpy version checks (see https://github.com/astropy/astropy/blob/main/astropy/utils/compat/numpycompat.py)?
from astropy.utils import minversion
MPL_LT_3_6 = not minversion(matplotlib, '3.6')
and then use it the code with:
if MPL_LT_3_6:
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for reviewing; will look into it.
Want to check first if this can be made to work with matplotlib/matplotlib#21945, which I've just reopened as matplotlib/matplotlib#26833 – unfortunately switching to display coordinates seems to break not just rotation but our existing resize and move operations; getting errors about self.height = ymax - ymin
in _update_from_mpl_selector
being set to negative values...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Let me know when this is ready for a (final?) review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dhomeier - what is needed at this point (here and on the matplotlib side) so that we can move ahead with this?
The blocking problem is that with the change to display coordinates as described in #390 (comment) any interaction (not even rotation, just normal move/resize) on y coordinates runs into wildly off vertical coordinates, quickly raising exceptions
Even in the initial display the outline (unfortunately not drawn in the exported plot) does not match the handles but extends higher up (where the mask has moved in the next picture, after just clicking inside the region). |
This is part 1 of a follow-up to #317 to support
as_mpl_selector
for rotated regions and rotating them, if the matplotlib version allows this (currently this needs the changes from matplotlib/matplotlib#19864 for the added functionality). Points for discussion:_rotate
and_rect_properties
to determine the geometry of the rotated shapes; I do not see a public method to conveniently access the rotation angle, and getting the correct position and width/height fromextents
or others is convoluted at minimum.EllipsePixelRegion
becomes offset from the bounding box, while the mask area seems positioned correctly. My understanding is that this is still drawn incorrectly from mpl'swidgets.py
, possibly because_draw_shape
is also not using the correctly transformed centre, but I haven't found a way to correct for that yet (if the error really is on the mpl side).test_as_mpl_selector
or as a new one? I guess this would also need to use theax.figure.canvas.callbacks.process
for aKeyEvent('key_press_event', ax.figure.canvas, 'r')
– pointers how to use this are welcome.