我目前正在尝试显示此合适的图片,但是我一直遇到不同的错误。起初它无法在标头中打印非ASCII字符,所以我继续删除它们(它们看起来像标头中的空白,它开始为',但没有用另一个'将其关闭),所以我想通了就是这样,然后放另一个'将其关闭(?),特别是在“ BUNIT”部分和“ INSTRU”部分)。这就是我要显示图像的方式:
from astropy.io import fits
from astropy import wcs
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_axes(111, projection=wcs.WCS('uwc.fits'))
ax.imshow(fits.getdata('uwc.fits'))
这是我删除整个BUNIT和INSTRU东西后的标题的样子:
SIMPLE = T / FILE IN FITS FORMAT
BITPIX = 16 / SIZE OF PIXELS
NAXIS = 3 / NUMBER OF AXES
NAXIS1 = 181 /
NAXIS2 = 91 /
NAXIS3 = 1 /
BSCALE = .831495E-02 / REAL = TAPE*BSCALE+BZERO
BZERO = .319702E+02 / ZERO CORRECTION
BUNIT = ' ' / UNITS OF BRIGHTNESS
DATAMAX = .302206E+03 / MAXIMUM DATA VALUE IN FILE
DATAMIN = .319702E+02 / MINIMUM DATA VALUE IN FILE
BLANK = -15751 / BLANK VALUE (C279 HEX)
OBJECT = 'C Band (0.16-0.2' / IMAGE NAME
DATE = '05/02/89' / DATE
DATOBS = ' ' / DATE OBJECT OBSERVED
INSTRU = ' ' / INSTRUMENT
OBSERV = ' ' / NAME OF OBSERVER
ORIGIN = 'PENN STATE' / TAPE ORIGIN
CTYPE1 = 'GLON-AIT' /
CRVAL1 = .000000 /
CRPIX1 = 91.000010 /
CDELT1 = -1.800000 /
CROTA1 = .000000 /
CTYPE2 = 'GLAT-AIT' /
CRVAL2 = .000000 /
CRPIX2 = 46.000000 /
CDELT2 = 1.800000 /
CROTA2 = .000000 /
CTYPE3 = ' ' /
CRVAL3 = .000000 /
CRPIX3 = .000000 /
CDELT3 = .000000 /
CROTA3 = .000000 /
END
然后又有另一个错误。具体来说,它看起来像这样:
SingularMatrixError: ERROR 3 in wcsset() at line 2218 of file
cextern/wcslib/C/wcs.c:
Linear transformation matrix is singular.
ERROR 3 in linset() at line 638 of file cextern/wcslib/C/lin.c:
PCi_ja matrix is singular.
<Figure size 432x288 with 0 Axes>
我不知道此错误的含义,也不知道如何修复标头。我曾尝试删除整个CTYPE3到CROTA3的部分,但没有成功,因为出现了*之后的“ TypeError:from_bounds()参数必须是可迭代的,而不是int”。任何帮助或参考这里将不胜感激,谢谢!!
答案 0 :(得分:2)
您可以通过WCS
参数告诉naxis
使用哪个轴:
In [1]: from astropy.wcs import WCS
In [2]: from astropy.io import fits
In [3]: hdr = fits.Header.fromstring('''
...: SIMPLE = T / FILE IN FITS FORMAT
...: BITPIX = 16 / SIZE OF PIXELS
...: NAXIS = 3 / NUMBER OF AXES
...: NAXIS1 = 181 /
...: NAXIS2 = 91 /
...: NAXIS3 = 1 /
...: BSCALE = .831495E-02 / REAL = TAPE*BSCALE+BZERO
...: BZERO = .319702E+02 / ZERO CORRECTION
...: BUNIT = ' ' / UNITS OF BRIGHTNESS
...: DATAMAX = .302206E+03 / MAXIMUM DATA VALUE IN FILE
...: DATAMIN = .319702E+02 / MINIMUM DATA VALUE IN FILE
...: BLANK = -15751 / BLANK VALUE (C279 HEX)
...: OBJECT = 'C Band (0.16-0.2' / IMAGE NAME
...: DATE = '05/02/89' / DATE
...: DATOBS = ' ' / DATE OBJECT OBSERVED
...: INSTRU = ' ' / INSTRUMENT
...: OBSERV = ' ' / NAME OF OBSERVER
...: ORIGIN = 'PENN STATE' / TAPE ORIGIN
...: CTYPE1 = 'GLON-AIT' /
...: CRVAL1 = .000000 /
...: CRPIX1 = 91.000010 /
...: CDELT1 = -1.800000 /
...: CROTA1 = .000000 /
...: CTYPE2 = 'GLAT-AIT' /
...: CRVAL2 = .000000 /
...: CRPIX2 = 46.000000 /
...: CDELT2 = 1.800000 /
...: CROTA2 = .000000 /
...: CTYPE3 = ' ' /
...: CRVAL3 = .000000 /
...: CRPIX3 = .000000 /
...: CDELT3 = .000000 /
...: CROTA3 = .000000 /
...: END
...: ''', sep='\n')
In [4]: WCS(hdr, naxis=(1,2))
Out[4]:
WCS Keywords
Number of WCS axes: 2
CTYPE : 'GLON-AIT' 'GLAT-AIT'
CRVAL : 0.0 0.0
CRPIX : 91.00001 46.0
NAXIS : 181 91 1