leejjoon / pywcsgrid2

astromonical fits image for python matplotlib
http://leejjoon.github.com/pywcsgrid2/
MIT License
25 stars 13 forks source link

How to draw circles directly onto a plot #3

Open pywcsgrid2fanboy opened 13 years ago

pywcsgrid2fanboy commented 13 years ago

First of all, I would like to say that I really love pywcsgrid2. Very nice job. This module is great.

This is more a question than an issue, but is there a nice way to plot objects (like circles, ellipses, ...) without having to first create a ds9 region file? Ideally, I would like some way to give in an ra, dec, size (and possible second size & angle) and having it add the object at the right spot in the sky.

Thanks,

leejjoon commented 13 years ago

As pywcsgrid2 is just an extension to matplotlib, you can do those things using the matplotlib commands. For example,

import matplotlib.patches as mpatches

ax = subplot(111)
el1 = mpatches.Ellipse(xy=(0.5, 0.5), width=0.3, height=0.2, angle=20)
ax.add_patch(el1)

However, the api documentation for those things are not well exposed somehow.

For example, if you want to draw something in "fk5" coordinate, you may do something like

el1 = mpatches.Ellipse(xy=(291., 14.), width=0.4, height=0.4, angle=0,
                       fc="none") # these should be in degree.
ax["fk5"].add_patch(el1)

Since sky-coordinates are curved, I think it is often best to draw something in the image coordinate.

-JJ

pywcsgrid2fanboy commented 13 years ago

Thanks. I didn't realize that the add_patch function would take the ellipse's xy coordinates as sky coordinates. This feature is very nice!

pywcsgrid2fanboy commented 13 years ago

Thanks for your help.

I just now understood your point about image vs sky coordinates. May ask one more question? What I am really interested in is plotting an ellipse in image coordinates (it is an error elipse defined in a non-curved coordinate system). But I want to place it at a given position in the sky and I want to define its angle relative to celestial north.

This is trivial to do with a ds9 region file

"fk5; ellipse(ra,dec,r1,r2,theta)"

But if possible I would like to avoid having to create these temporary files and avoid using pyregion/pyparsing.

Is there a way to directly plot this object. In particular, I think I need some way to look up the pixel coordinates for a given sky coordinate. And I need to be able to get the angle to relative to celestial north.

Thanks in advance for any help you may give.

leejjoon commented 13 years ago

Conversion between the pixel coordinates and the sky coordinates are done by "pywcs" package using the header information. "pyregion" includes some helper routines for this. Some of these routines may go into "pywcsgrid2" or "axisartist" toolkits in the future. For now, I don't think there is any easy way of doing this without "pyregion" (although other packages may provide these functionality).

I'm going to label this as "wishlist".

-JJ