Skip to content
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

Improve shape classes and MPL plotting #85

Merged
merged 12 commits into from
Nov 30, 2016

Conversation

cdeil
Copy link
Member

@cdeil cdeil commented Nov 28, 2016

This PR:

  • Removes sky region as_patch and plot as discussed in SkyCircleRegion matplotlib plot issue #76 and Fix plotting of SkyCircleRegion #77
  • Group XYZRegion class tests in TestXYZRegion classes
  • Implement EllipsePixelRegion.as_patch (and add example to docstring)
  • Implement RectanglePixelRegion.as_patch (and add example to docstring)
  • Change to major / minor argument order in ellipse to be consistent with MPL / ds9 / photutils
  • Change to width / height argument order in rectangle to be consistent with MPL / ds9 / photutils
  • Add tests for pixel region as_patch methods
  • Updates the region MPL plot examples in the docs (to address SkyCircleRegion matplotlib plot issue #76)
  • Updates docs matplotlib plotting section with more info / examples

We usually have two classes per file in `regions.shapes` at the moment.
One for the pixel, one for the sky region.

IMO it's better to have tests clearly grouped per class,
as much as possible, I find that easier to maintain.
xy = self.center.x, self.center.y
width = 2 * self.major
height = 2 * self.minor
# TODO: think about how to map major / minor / angle to MPL parameters.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@larrybradley @astrofrog - OK if I change the argument order for ellipse to major / minor?
This seems more natural to me and is more in line with http://photutils.readthedocs.io/en/latest/api/photutils.EllipticalAperture.html .

What about the angle passed to MPL.
Does anyone know if it's OK as defined here?
I was looking at this for guidance:
http://photutils.readthedocs.io/en/latest/_modules/photutils/aperture/ellipse.html#EllipticalAperture.plot

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for rectangle ... I'll go ahead and follow the lead of MPL and photutils and change to width/height argument order:
http://photutils.readthedocs.io/en/latest/api/photutils.RectangularAperture.html
Let me know if you disagree.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure where you changed the major/minor order, but what you have here is correct for the ellipse. Photutils defines the theta as the counterclockwise rotation of the semimajor axis from the x axis. This is the same for the EllipsePixelRegion.

https://github.com/cdeil/regions/blob/387c5a60a699bffdf3546c620cf6396fd5a9d06c/regions/shapes/ellipse.py#L25

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any changes to rectangle. photutils.RectangularAperture is correct as defined, where the width side is along the x axis for theta=0 and theta increases counterclockwise.

Note that the all of these plots require the "normal" display convention where the (0, 0) pixel is at the lower left (i.e. origin='lower'). Otherwise the rotation angle will be in the opposite direction.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@larrybradley - Thank you. I've fixed added two more commits here that fix up the rectangle as_patch and added a plot to the docstring for rectangle and ellipse. Docstring updates are deferred to #86

@cdeil cdeil changed the title MPL region plotting Improve shape classes and MPL plotting Nov 29, 2016
assert_allclose(patch.xy, (3, 4))
assert_allclose(patch.get_width(), 4)
assert_allclose(patch.get_height(), 3)
assert_allclose(patch._angle, 5)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@astrofrog @larrybradley - I couldn't find a public attribute or method to get at the angle in a matplotlib.patches.Rectangle. Does it exist!?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cdeil I looked in the matplotlib source code and there's no public attribute or method (that's odd), only the _angle attribute.

@cdeil
Copy link
Member Author

cdeil commented Nov 29, 2016

@astrofrog - Is this a bug in pytest_arraydiff?
https://travis-ci.org/astropy/regions/jobs/179802570#L1056
Or am I doing something wrong?
I don't see this locally, must be a different version?

@cdeil
Copy link
Member Author

cdeil commented Nov 29, 2016

@astrofrog @larrybradley - This is ready for final review.

@cdeil
Copy link
Member Author

cdeil commented Nov 30, 2016

The np.savetxt fails with fmt are a known numpy bug:
numpy/numpy#4053 (comment)
I'll change to bytes literal now.
@astrofrog - Might even be worth converting fmt to bytes in pytest-arraydiff if users pass bytes, to spare other users the trouble of running into this issue.

@cdeil
Copy link
Member Author

cdeil commented Nov 30, 2016

Concerning matplotlib.patches.Rectangle.angle, I've filed this feature request:
matplotlib/matplotlib#7536
For now, I'll uncomment that assert on _angle and leave a TODO comment and reference to that MPL issue.

@cdeil cdeil mentioned this pull request Nov 30, 2016
3 tasks
@cdeil cdeil merged commit b882238 into astropy:master Nov 30, 2016
@cdeil cdeil mentioned this pull request Nov 30, 2016
@joleroi
Copy link
Contributor

joleroi commented Nov 30, 2016

I lost track of all the plotting discussion, however the current state of the compound regions example plot does not look satisfactory at all, does it?

http://astropy-regions.readthedocs.io/en/latest/getting_started.html#compounds

As far as I understand, @cdeil does not want to merge #77.

I just now merged #85, which fixes this issue.

I don't think we want to ever merge this PR, but it contains useful discussion concerning plotting of sky regions. So I'm keeping it open for now, and I'm moving it to the 0.3 milestone.

So how are we going to improve the plotting issue?

@cdeil
Copy link
Member Author

cdeil commented Nov 30, 2016

@joleroi and I discussed this over lunch. The plot isn't incorrect, it just plots pixel regions.

I agree it's confusing for illustrating compounds, the points and regions should be consistently in pixels or in sky, or there could even be one example for each.

Also, there should be an illustration of the differences between pixel and sky regions further up in the docs.

I don't have time, and I think we should start by implementing our polygon classes, and only then come back to docs / testing for sky regions.

But like I said in #63, if someone has time to make a pull request to improve regions this week, great! If not, we'll try to do it in the coming months.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants