无法使用PyFIT从fits文件读取原始数据

2024-10-03 09:21:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图打开一个.fits文件,并使用pyFITS模块for Python2.7从中读取数据。下面是我运行的代码片段,试图从文件中获取数据:

location = raw_input("Locaiton of FITS file: ") """user input location for the file"""
hdulist = pyfits.open(location) """opens the .fits file (works properly)"""

print(repr(hdulist[0].header)) """printed values shown below, works properly"""
pyfits.getdata(location, hdulist[0].header['TOTVALS']) """does NOT work"""

我知道文件被正确打开;当我运行print(repr(hdulist[0].header))时,控制台显示

^{pr2}$

然后打印出来

SIMPLE  =                    T / file does conform to FITS standard             
BITPIX  =                   32 / number of bits per data pixel                  
NAXIS   =                    2 / number of data axes                            
NAXIS1  =                 4096 / length of data axis 1                          
NAXIS2  =                 4096 / length of data axis 2                          
EXTEND  =                    T / FITS dataset may contain extensions            
COMMENT   FITS (Flexible Image Transport System) format is defined in 'Astronomy
COMMENT   and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H 
DATE    = '2014-01-27T07:17:01'                                                 
DATE-OBS= '2014-01-27T06:34:10.00'                                              
TELESCOP= 'SDO/HMI'                                                             
INSTRUME= 'HMI_SIDE1'                                                           
WAVELNTH= 6173.0                                                                
CAMERA  =                    1                                                  
BUNIT   = 'Gauss'                                                               
ORIGIN  = 'SDO/JSOC-SDP'                                                        
CONTENT = 'MAGNETOGRAM'                                                         
QUALITY =                 1024                                                  
QUALLEV1=           1073741824                                                  
HISTORY Polynomial Coefficients used for Doppler velocity correction: 8.071746e+
HISTORY 01 5.340511e-03 -2.036568e-06 -7.976842e-10                             
COMMENT De-rotation: ON; Un-distortion: ON; Re-centering: ON; Re-sizing: OFF; co
COMMENT rrection for cosmic-ray hits; dpath=/home/jsoc/cvs/Development/JSOC/proj
COMMENT /lev1.5_hmi/apps/; linearity=1 with coefficients updated on 2014/01/15; 
COMMENT smooth=1; propagate eclipse bit from level 1; use of larger crop radius 
COMMENT look-up tables                                                          
BLD_VERS= '-802'                                                                
HCAMID  =                    2                                                  
SOURCE  = 'hmi.lev1_nrt[:#57580483,#57580411,#57580338,#57580272,#57580184,#575'
TOTVALS =             12841850                                                  
DATAVALS=             12841850    

...remaining values omitted...

当我尝试pyfits.getdata(location, hdulist[0].header['TOTVALS'])时,问题就出现了。返回的错误消息是

Traceback (most recent call last):
  File "C:\Users\User\Desktop\openFITS.py", line 34, in <module>
    pyfits.getdata(location,hdulist[0].header['TOTVALS'])
  File "C:\Python27\lib\site-packages\pyfits\convenience.py", line 181, in getdata
    hdu = hdulist[extidx]
  File "C:\Python27\lib\site-packages\pyfits\hdu\hdulist.py", line 166, in __getitem__
    return super(HDUList, self).__getitem__(idx)
IndexError: list index out of range

print(len(hdulist))返回1;因此我知道索引0不应该超出范围。因此,问题是为什么我不能从hdulist中获取头“TOTVALS”中的原始数据,尽管看起来其他的一切都很好。在

提前感谢您的帮助!在


Tags: ofinfordataoncommentlocationfile