简体   繁体   中英

Cannot open file with PyFITS

I've got some .fit files containing images from a CCD camera and I can't seem to open them using PyFITS. I'm a complete newbie with PyFITS so I don't know what (if any) options I have. Here's what I'm trying:

import pyfits

hdulist = pyfits.open('apex5_1_90s.fit')

Which returns the error:

Traceback (most recent call last):
  File "\\uol.le.ac.uk\root\staff\home\l\lvh8\Desktop Files\Prototype Data\spextract.py", line 3, in <module>
    hdulist = pyfits.open('apex5_1_90s.fit')#, ignore_missing_end=True)
  File "C:\Python27\lib\site-packages\pyfits\hdu\hdulist.py", line 118, in fitsopen
    return HDUList.fromfile(name, mode, memmap, save_backup, **kwargs)
  File "C:\Python27\lib\site-packages\pyfits\hdu\hdulist.py", line 250, in fromfile
    save_backup=save_backup, **kwargs)
  File "C:\Python27\lib\site-packages\pyfits\hdu\hdulist.py", line 803, in _readfrom
    hdu = _BaseHDU.readfrom(ffo, **kwargs)
  File "C:\Python27\lib\site-packages\pyfits\hdu\base.py", line 299, in readfrom
    hdr = Header.fromfile(fileobj, endcard=not ignore_missing_end)
  File "C:\Python27\lib\site-packages\pyfits\header.py", line 476, in fromfile
    raise IOError('Header missing END card.')
IOError: Header missing END card.

If on the other hand I try:

import pyfits

hdulist = pyfits.open('apex5_1_90s.fit', ignore_missing_end=True)

I get told:

Error validating header for HDU #1 (note: PyFITS uses zero-based indexing).
    Header size is not multiple of 2880: 1920
There may be extra bytes after the last HDU or the file is corrupted.

I don't really know what this means and I've no idea what I can do about it, so any help would be greatly appreciated!

It's seems that your file is corrupted or have some issues with header. Are you sure you have a valid FITS file? Based on PyFITS documentation:

Problem with the FITS format is that, as old as it is, there are many conventions that appear in files from certain sources that do not meet the FITS standard. And yet they are so common-place that it is necessary to support them in any FITS readers. CONTINUE cards are one such example.

(...) If PyFITS is having trouble opening a file, a good way to rule out whether not the problem is with PyFITS is to run the file through the fitsverify . If the file is malformatted, fitsverify will output errors and warnings. If fitsverify confirms no problems with a file, and PyFITS is still having trouble opening it (...) then it's likely there is a bug in PyFITS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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