1
我試圖WCS轉換爲使用astropy像素,但是當我嘗試在圖像閱讀:Astropy WCS:「IOError:標題缺少END卡。」
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://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.*
我面前的時候得到這個錯誤只使用fits.open()
,但能夠通過添加"ignore_missing_end=True"
來解決問題。但是,"ignore_missing_end"
似乎不是wcs類的參數。如何用astropy.wcs.wcs
讀取圖像?
我想'WCS'初始化可以採取一個已經打開的文件作爲參數,而不是一個文件名,那麼你可以嘗試,對於首發。雖然「缺少END卡」錯誤提示可能存在格式不正確的文件,所以您也可以嘗試使用ignore_missing_end = True打開它,就像您之前所做的一樣,然後寫出新的文件副本。有時候可以修復文件中的小格式問題。 – Iguananaut