I'm trying to convert WCS to pixels using astropy, but when I try to read in the image:
from astropy import wcs
w = wcs.WCS('image_file.fits')
I get the following Exception:
*WARNING: Unexpected extra padding at the end of the file. This padding may not be preserved when saving changes. [astropy.io.fits.header]
Traceback (most recent call last):
File "make_stamps.py", line 29, in <module>
w = wcs.WCS(image_file)
File "/Users/anaconda/lib/python2.7/site-packages/astropy/wcs/wcs.py", line 385, in __init__
fobj = fits.open(header)
Fhttp://stackoverflow.com/posts/41513868/editile "/Users/anaconda/lib/python2.7/site-packages/astropy/io/fits/hdu/hdulist.py", line 139, in fitsopen
return HDUList.fromfile(name, mode, memmap, save_backup, cache, **kwargs)
File "/Users/anaconda/lib/python2.7/site-packages/astropy/io/fits/hdu/hdulist.py", line 281, in fromfile
save_backup=save_backup, cache=cache, **kwargs)
File "/Users/anaconda/lib/python2.7/site-packages/astropy/io/fits/hdu/hdulist.py", line 839, in _readfrom
hdu = _BaseHDU.readfrom(ffo, **kwargs)
File "/Users/anaconda/lib/python2.7/site-packages/astropy/io/fits/hdu/base.py", line 423, in readfrom
**kwargs)
File "/Users/anaconda/lib/python2.7/site-packages/astropy/io/fits/hdu/base.py", line 483, in _readfrom_internal
header = Header.fromfile(data, endcard=not ignore_missing_end)
File "/Users/anaconda/lib/python2.7/site-packages/astropy/io/fits/header.py", line 451, in fromfile
padding)[2]
File "/Users/anaconda/lib/python2.7/site-packages/astropy/io/fits/header.py", line 520, in _from_blocks
raise IOError('Header missing END card.')
IOError: Header missing END card.*
I got this error before when using just fits.open()
but was able to solve the problem by adding "ignore_missing_end=True"
. But, "ignore_missing_end"
doesn't seem to be a argument of the wcs class. How can the image be read with astropy.wcs.wcs
?
That
astropy.wcs.WCS
can take a filename is just a convenience option so it's not really surprising that you can't pass (all) parameters thatastropy.io.fits.open
accepts to this function as well.However it's quite easy to create a
WCS
with aastropy.io.fits.Header
. So you can open the file, extract the relevant header and create the WCS yourself: