[AstroPy] astropy/wcsaxes issue with regions that "wrap"
Phil Evans
pae9 at leicester.ac.uk
Thu Oct 6 11:07:50 EDT 2016
HI all,
I have a plotting issue with astropy/wcsaxes.
I'm plotting a FITS image (aitoff projection), and then overlaying a ds9
region file via pyregion. This all works fine, unless the region file
happens to "wrap around" the axes. If this happens, the "filled" parts
of the region are not those that lie inside the circle, instead they are
those that lie outside the circle (in RA),
For example, in the first image attached, the region is a circle, radius
46 degrees, centred on (29,11).
In the second image I've shifted it to (45,11), and again you can see
the issue. If the "right hand end" of the circle wraps around the edger
of the projection, the plotter is incorrectly choosing which points are
inside and outside the circle.
A stripped down version of the python script is below. I'm using
astropy1.2.1, wcsaxes 0.9 (i.e. latest versions from pip), and python
2.7.2. Am I doing somethng wrong, or is this a bug in
astropy/wcsaxes/matplotlib?
Thanks!
Phil
P.S. I realise that there is a "fix" which is to choose my origin such
that no regions wrap, but that is not going to be appropriate, or
necessarily even possible.
infile=args[0];
outStem=args[1]
hdu=fits.open(infile)[0]
wcs=WCS(hdu.header)
fig=plt.figure()
ax = WCSAxes(fig, [0.0, 0.0, 1.0, 1.0], wcs=wcs)
fig.add_axes(ax)
image=hdu.data
image[image<1e-6]=0
ax.imshow(image, cmap='gray_r', origin='lower', alpha=1.0,
norm=LogNorm(vmin=1e-6, clip=False))
lon=ax.coords['RA']
lat=ax.coords['Dec']
lon.set_major_formatter('hh:mm:ss')
lon.set_ticks(values=[0,30,60,90,120,150,180,210,240,270,300,330,360]*u.degree,
exclude_overlapping=False)
lat.set_ticks(spacing=30.0*u.degree)
lon.grid(color='black', alpha=1.0, linestyle='solid')
lat.grid(color='black', alpha=1.0, linestyle='solid')
r=pyregion.open(sunFile)
p, text_list = r.get_mpl_patches_texts()
p[0].set_facecolor('#CCCC00')
p[0].set_edgecolor('#CCCC00')
p[0].set_alpha(0.5)
p[0].set_transform(ax.get_transform('fk5'))
ax.add_patch(p[0])
plt.saveFig(outStem+".png", dpi=244)
--
-------------------------
Phil Evans,
Swift Development Scientist
X-ray and Observational Astronomy Group,
University of Leicester
Tel: +44 (0)116 252 5059
Mobile: +44 (0)7780 980240 (work)
Mobile: +44 (0)7974 977723 (personal)
pae9 at leicester.ac.uk
http://www.star.le.ac.uk/~pae9
http://www.swift.ac.uk
Follow me as a Swift scientist on Twitter: @swift_phil
http://www.star.le.ac.uk/~pae9/twitter
-------------- next part --------------
A non-text attachment was scrubbed...
Name: badplot_1.png
Type: image/png
Size: 427367 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/astropy/attachments/20161006/1946db97/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: badplot_2.png
Type: image/png
Size: 456809 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/astropy/attachments/20161006/1946db97/attachment-0001.png>
More information about the AstroPy
mailing list