leejjoon/pyregion — Issue #11: Error displaying a circle in equatorial coordiantes at the galactic origin
Author: joshualande
Created: 2012-01-17 23:41:28+00:00
State: open

I ran into a bug when trying to display a circle defined in equatorial coordinates centered at the galactic origin.

I have attached a very simple example below which demonstrates the bug.

I first define a fits header centered on the galactic origin. I then create a region file which defines a circle centered on the galactic origin in equatorial coordinates. When I try to plot this circle, it does not appear.

When I displace the circle slightly from the galactic origin, it displays correctly.

Any help on this issue would be greatly appreciated.

Code attached below:

```
import pyfits, pywcsgrid2
import matplotlib.pyplot as plt
import numpy as np
from pylab import savefig
import pyregion

l,b=0,0

# This is the ra,dec of l,b=0,0 - fails
ra,dec=266.404497776,-28.9364329295

# This is 'almost' the ra,dec of l,b=0,0 - works
# ra,dec=266.40,-28.93

values = [
["NAXIS", 2, ],
["NAXIS1", 10, ],
["NAXIS2", 10, ],
["CTYPE1", 'GLON-ZEA' ],
["CTYPE2", 'GLAT-ZEA' ],
["CRPIX1", 5.5, ],
["CRPIX2", 5.5, ],
["CRVAL1", l, ],
["CRVAL2", b, ],
["CDELT1", 0.1, ],
["CDELT2", -0.1, ],
]

cards = [pyfits.Card(*i) for i in values]
header=pyfits.Header(cards=cards)

ax=pywcsgrid2.subplot(111, header=header)

# overlay a white image
ax.imshow(np.zeros((10,10)), origin="lower",
cmap=plt.cm.gray_r)
ax.grid()

region_string="fk5; circle(%s, %s, 0.5000)" % (ra,dec)
reg = pyregion.parse(region_string).as_imagecoord(header)

patch_list, artist_list = reg.get_mpl_patches_texts()
for p in patch_list: ax.add_patch(p)

savefig('example.png')
```