-1

我目前正在尝试显示此适合图像,但我不断遇到不同的错误。起初它无法打印标题中的非 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”。任何帮助或参考将不胜感激,谢谢!

4

1 回答 1

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
于 2018-07-19T15:17:41.757 回答