Astropy WCS: "IOError: Header missing END card."
Astropy WCS: "IOError: Header missing END card."
我正在尝试使用 astropy 将 WCS 转换为像素,但是当我尝试读入图像时:
from astropy import wcs
w = wcs.WCS('image_file.fits')
我得到以下异常:
*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://whosebug.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.*
我以前只使用 fits.open()
时遇到过这个错误,但通过添加 "ignore_missing_end=True"
能够解决问题。但是,"ignore_missing_end"
似乎不是 wcs class 的参数。如何用astropy.wcs.wcs
读取图像?
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 that astropy.io.fits.open
也接受此函数。
然而,用 astropy.io.fits.Header
创建 WCS
非常容易。所以你可以打开文件,提取相关的头文件并自己创建 WCS:
from astropy.io import fits
from astropy.wcs import WCS
with fits.open('your_file.fits', mode='readonly', ignore_missing_end=True) as fitsfile:
# if you want the first extension, otherwise change the [0].
wcs = WCS(fitsfile[0].header)
# Now you can use your WCS, for example:
print(wcs)
我正在尝试使用 astropy 将 WCS 转换为像素,但是当我尝试读入图像时:
from astropy import wcs
w = wcs.WCS('image_file.fits')
我得到以下异常:
*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://whosebug.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.*
我以前只使用 fits.open()
时遇到过这个错误,但通过添加 "ignore_missing_end=True"
能够解决问题。但是,"ignore_missing_end"
似乎不是 wcs class 的参数。如何用astropy.wcs.wcs
读取图像?
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 that astropy.io.fits.open
也接受此函数。
然而,用 astropy.io.fits.Header
创建 WCS
非常容易。所以你可以打开文件,提取相关的头文件并自己创建 WCS:
from astropy.io import fits
from astropy.wcs import WCS
with fits.open('your_file.fits', mode='readonly', ignore_missing_end=True) as fitsfile:
# if you want the first extension, otherwise change the [0].
wcs = WCS(fitsfile[0].header)
# Now you can use your WCS, for example:
print(wcs)