question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read some non-standard FITS files

See original GitHub issue

I’m trying to read a fits file and get its header and contents, but no matter what I do astropy gives me errors:

with fits.open(Path('J0721+7120_C_2014_02_18_pet_vis.fits').open('rb')) as f:
    f['PRIMARY'].header['RA']

---------------------------------------------------------------------------
VerifyError                               Traceback (most recent call last)
<ipython-input-44-e7947a571936> in <module>
      1 with fits.open(Path('J0721+7120_C_2014_02_18_pet_vis.fits').open('rb')) as f:
----> 2     f['PRIMARY'].header['RA']

~/anaconda3/lib/python3.7/site-packages/astropy/io/fits/header.py in __getitem__(self, key)
    152             return card.rawvalue
    153 
--> 154         value = card.value
    155         if value == UNDEFINED:
    156             return None

~/anaconda3/lib/python3.7/site-packages/astropy/io/fits/card.py in value(self)
    283             value = self._value
    284         elif self._valuestring is not None or self._image:
--> 285             value = self._value = self._parse_value()
    286         else:
    287             if self._keyword == '':

~/anaconda3/lib/python3.7/site-packages/astropy/io/fits/card.py in _parse_value(self)
    765         if m is None:
    766             raise VerifyError("Unparsable card ({}), fix it first with "
--> 767                               ".verify('fix').".format(self.keyword))
    768 
    769         if m.group('bool') is not None:

VerifyError: Unparsable card (RA), fix it first with .verify('fix').
with fits.open(Path('J0721+7120_C_2014_02_18_pet_vis.fits').open('rb')) as f:
    f.verify('fix')

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-43-ed0088ff4893> in <module>
      1 with fits.open(Path('J0721+7120_C_2014_02_18_pet_vis.fits').open('rb')) as f:
----> 2     f.verify('fix')

~/anaconda3/lib/python3.7/site-packages/astropy/io/fits/verify.py in verify(self, option)
     71             return
     72 
---> 73         errs = self._verify(opt)
     74 
     75         # Break the verify option into separate options related to reporting of

~/anaconda3/lib/python3.7/site-packages/astropy/io/fits/hdu/hdulist.py in _verify(self, option)
   1191 
   1192         # the first (0th) element must be a primary HDU
-> 1193         if len(self) > 0 and (not isinstance(self[0], PrimaryHDU)) and \
   1194                              (not isinstance(self[0], _NonstandardHDU)):
   1195             err_text = "HDUList's 0th element is not a primary HDU."

~/anaconda3/lib/python3.7/site-packages/astropy/io/fits/hdu/hdulist.py in __len__(self)
    226     def __len__(self):
    227         if not self._in_read_next_hdu:
--> 228             self.readall()
    229 
    230         return super().__len__()

~/anaconda3/lib/python3.7/site-packages/astropy/io/fits/hdu/hdulist.py in readall(self)
    767         Read data of all HDUs into memory.
    768         """
--> 769         while self._read_next_hdu():
    770             pass
    771 

~/anaconda3/lib/python3.7/site-packages/astropy/io/fits/hdu/hdulist.py in _read_next_hdu(self)
   1137                                 fileobj.seek(offset, os.SEEK_SET)
   1138 
-> 1139                         hdu = _BaseHDU.readfrom(fileobj, **kwargs)
   1140                     except EOFError:
   1141                         self._read_all = True

~/anaconda3/lib/python3.7/site-packages/astropy/io/fits/hdu/base.py in readfrom(cls, fileobj, checksum, ignore_missing_end, **kwargs)
    326         hdu = cls._readfrom_internal(fileobj, checksum=checksum,
    327                                      ignore_missing_end=ignore_missing_end,
--> 328                                      **kwargs)
    329 
    330         # If the checksum had to be checked the data may have already been read

~/anaconda3/lib/python3.7/site-packages/astropy/io/fits/hdu/base.py in _readfrom_internal(cls, data, header, checksum, ignore_missing_end, **kwargs)
    462                     del new_kwargs[key]
    463 
--> 464         hdu = cls(data=DELAYED, header=header, **new_kwargs)
    465 
    466         # One of these may be None, depending on whether the data came from a

~/anaconda3/lib/python3.7/site-packages/astropy/io/fits/hdu/table.py in __init__(self, data, header, name, uint, ver, character_as_bytes)
    851 
    852         super().__init__(data, header, name=name, uint=uint, ver=ver,
--> 853                          character_as_bytes=character_as_bytes)
    854 
    855     @classmethod

~/anaconda3/lib/python3.7/site-packages/astropy/io/fits/hdu/table.py in __init__(self, data, header, name, uint, ver, character_as_bytes)
    370         if not (isinstance(self._header[0], str) and
    371                 self._header[0].rstrip() == self._extension):
--> 372             self._header[0] = (self._extension, self._ext_comment)
    373 
    374         # Ensure that the correct EXTNAME is set on the new header if one was

TypeError: '_BasicHeader' object does not support item assignment

The example file can be downloaded from http://astrogeo.org/images/J0721+7120/J0721+7120_C_2014_02_18_pet_vis.fits.

astropy.__version__ = '3.2.1'

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
aplavincommented, Jul 18, 2019

Thanks a lot for that prompt response and fix! I installed latest astropy by running pip install git+https://github.com/astropy/astropy and it can read all the files from that dataset.

0reactions
saimncommented, Jul 17, 2019

@aplavin - See #9012 for a proposed fix.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error reading Solar Dynamics Observatory, HMI continuum ...
I am unable to read a FITS file with astropy.io.fits produced by the Solar Dynamics Observatory for the HMI continuum data product.
Read more >
Verification — Astropy v5.2
Since astropy is tolerant when reading a FITS file, no verify() is called on input. On output, verify() is called with the most...
Read more >
astropy.io.fits FAQ
PyFITS is a library written in, and for use with the Python programming language for reading, writing, and manipulating FITS formatted files.
Read more >
Problem with saving fits files in Pixinsight
I'm new to the software (previously used CCDStack, PS, Maxim) and I am having trouble saving a fits file in Pixinsight. For some...
Read more >
fits.readme - The IDL Astronomy User's Library - NASA
The READFITS/WRITEFITS software currently cannot read variable length binary ... READFITS() will read a disk FITS file into IDL data and header arrays....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found