I am tying to get the physical sky coordinates of a given pixel from within a python script. I would like to use astropy's WCS, but I'll do anything from within python.
I have tried these two snippets of code.
from astropy.io import fits
from astropy.wcs import WCS
def astropymethod1(img):
# from http://astropy.readthedocs.org/en/latest/wcs/
w = WCS(img)
lon, lat = w.all_pix2world( 100., 100., 1)
print lon, lat
def astropymethod2(img):
# from http://astropy.readthedocs.org/en/latest/wcs/
hdu = fits.open(img)
w = WCS(hdu[0].header)
lon, lat = w.wcs_pix2world(100., 100., 1)
print lon, lat
The issues are I get an error the first time I try to use WCS and the result is only ever the pixel values I put in.
WARNING: FITSFixedWarning: The WCS transformation has more axes (2) than the image it is associated with (0) [astropy.wcs.wcs]
The problem is that you have a multi-extension FITS file. Here's an example session showing how you can get access to the appropriate WCS:
So you probably want to redefine your method: