简体   繁体   English

无法使用PyFITS从拟合文件读取原始数据

[英]Cannot read raw data from a fits file using PyFITS

I'm trying to open a .fits file and read data from it using the pyFITS module for Python 2.7. 我正在尝试使用Python 2.7的pyFITS模块打开.fits文件并从中读取数据。 Below is the code snippet which I'm running to try to attain the data from the file: 下面是我正在尝试从文件中获取数据的代码片段:

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"""

I know that the file's being opened properly; 我知道文件正在正确打开; when I run print(repr(hdulist[0].header)) , the console shows 当我运行print(repr(hdulist[0].header)) ,控制台显示

Warning (from warnings module):
  File "C:\Python27\lib\site-packages\pyfits\verify.py", line 69
    warnings.warn(u'Output verification result:')
UserWarning: Output verification result:

Warning (from warnings module):
  File "C:\Python27\lib\site-packages\pyfits\verify.py", line 73
    warnings.warn(line, VerifyWarning)
VerifyWarning: Card 'CRDER1' is not FITS standard (invalid value string: nan).  Fixed 'CRDER1' card to meet the FITS standard.

Warning (from warnings module):
  File "C:\Python27\lib\site-packages\pyfits\verify.py", line 74
    warnings.warn(u'Note: PyFITS uses zero-based indexing.\n')
UserWarning: Note: PyFITS uses zero-based indexing.


Warning (from warnings module):
  File "C:\Python27\lib\site-packages\pyfits\verify.py", line 69
    warnings.warn(u'Output verification result:')
UserWarning: Output verification result:

Warning (from warnings module):
  File "C:\Python27\lib\site-packages\pyfits\verify.py", line 73
    warnings.warn(line, VerifyWarning)
VerifyWarning: Card 'CRDER2' is not FITS standard (invalid value string: nan).  Fixed 'CRDER2' card to meet the FITS standard.

Warning (from warnings module):
  File "C:\Python27\lib\site-packages\pyfits\verify.py", line 74
    warnings.warn(u'Note: PyFITS uses zero-based indexing.\n')
UserWarning: Note: PyFITS uses zero-based indexing.


Warning (from warnings module):
  File "C:\Python27\lib\site-packages\pyfits\verify.py", line 69
    warnings.warn(u'Output verification result:')
UserWarning: Output verification result:

Warning (from warnings module):
  File "C:\Python27\lib\site-packages\pyfits\verify.py", line 73
    warnings.warn(line, VerifyWarning)
VerifyWarning: Card 'CSYSER1' is not FITS standard (invalid value string: nan).  Fixed 'CSYSER1' card to meet the FITS standard.

Warning (from warnings module):
  File "C:\Python27\lib\site-packages\pyfits\verify.py", line 74
    warnings.warn(u'Note: PyFITS uses zero-based indexing.\n')
UserWarning: Note: PyFITS uses zero-based indexing.


Warning (from warnings module):
  File "C:\Python27\lib\site-packages\pyfits\verify.py", line 69
    warnings.warn(u'Output verification result:')
UserWarning: Output verification result:

Warning (from warnings module):
  File "C:\Python27\lib\site-packages\pyfits\verify.py", line 73
    warnings.warn(line, VerifyWarning)
VerifyWarning: Card 'CSYSER2' is not FITS standard (invalid value string: nan).  Fixed 'CSYSER2' card to meet the FITS standard.

Warning (from warnings module):
  File "C:\Python27\lib\site-packages\pyfits\verify.py", line 74
    warnings.warn(u'Note: PyFITS uses zero-based indexing.\n')
UserWarning: Note: PyFITS uses zero-based indexing.

and then prints 然后打印

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...

The problem arises when I try pyfits.getdata(location, hdulist[0].header['TOTVALS']) . 当我尝试pyfits.getdata(location, hdulist[0].header['TOTVALS'])时,就会出现问题。 The error message returned is 返回的错误消息是

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)) returns 1; print(len(hdulist))返回1; so I know that the index 0 shouldn't be out of range. 因此我知道索引0不应超出范围。 Thus, the question is why I can't get the raw data in the header 'TOTVALS' from the hdulist, even though it seems that everything else is working fine. 因此,问题是为什么我似乎无法从hdulist的标头“ TOTVALS”中获取原始数据,即使其他一切似乎都工作正常。

Thanks in advance for your help! 在此先感谢您的帮助!

The header you printed shows that the value of TOTVALS is 12841850. 您打印的标题显示TOTVALS值为12841850。

You're trying to return the data from the 12841850th HDU. 您正在尝试从12841850th HDU返回数据。 See: http://pyfits.readthedocs.org/en/v3.2.0/api_docs/api_files.html#getdata 请参阅: http : //pyfits.readthedocs.org/en/v3.2.0/api_docs/api_files.html#getdata

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM