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.

Behavior of 'fitsopen' for a non-standard FITS file

See original GitHub issue

AstroPy v2.0 Test file used :- io/fits/tests/data/test0.fits (Contains 4 Image extensions)

Background

I was trying to generate a non-standard FITS file to test the compliance fixing fixing of fitscheck script. which is why I tried to delete a required keyword EXTEND from PrimaryHDU. This was not possible because astropy tries hard to not let such a thing happen. This is what I tried :-

>>> import astropy.io.fits as pf
>>> hlist = pf.open('./data/test0.fits', mode='update')
>>> del hlist[0].header['EXTEND']
>>> hlist.writeto('./data/test0.fits', output_verify='ignore', overwrite=True)
>>> hlist.close(output_verify='ignore') # Will call fits/cards.py:image

and

>>> import astropy.io.fits as pf
>>> hlist = pf.open('./data/test0.fits', mode='update')
>>> del hlist[0].header['EXTEND']
>>> hlist.flush(output_verify='ignore') # Will call fits/cards.py:image

As mentioned in the comment fits/cards.py:image has a hardcoded call to _Verify.verify with option to fix+warn. Hence I think it is not possible to generate a non-standard file via astropy.

The Issue

I replaced the EXTEND card by a blank using a text editor and opened it again.

>>> import astropy.io.fits as pf
>>> hlist = pf.open('./data/test0.fits', mode='update')
>>> hlist[0].header['EXTEND']
True

The original file remains the same.

  • IMO since it fixes the standard violation while opening but that is not reflected in the actual file, there is no way to know if the original file is actually FITS compliant.
  • fitscheck script checks compliance by first opening the file (when the keyword is already added!) and then checking for compliance. (One of the tests include checking for EXTEND keyword which will obviously return True now). Which is why it too can’t detect that EXTEND is missing.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:15 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
MSeifert04commented, Mar 16, 2017

This may seem unexpected, but as usual with io.fits there must be a good reason why it is done.

@saimn optimistic or sarcastic? 😄

1reaction
saimncommented, Mar 16, 2017

@MSeifert04 - Just realistic, from my experience there is always a good reason 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

FITS File Handling (astropy.io.fits)
When opening a file with memmap=True , because of how mmap works this means that when the HDU data is accessed (i.e., hdul[0]....
Read more >
astropy.io.fits FAQ
There are non-standard conventions supported by Astropy/PyFITS that are not supported by CFITSIO and possibly vice-versa. You may have hit one of those...
Read more >
astropy.io.fits FAQ
How do I create a multi-extension FITS file from scratch? ... astropy.io.fits.open has an option to access the data portion of an HDU...
Read more >
Yorick Standard Library - LLNL Software Portal
DOCUMENT fits - an introduction to Yorick interface to FITS files. ... format as FITS): - It is still possible to produce a...
Read more >
pyfits 3.4 - PyPI
(CNSHD744730) Standard FITS files support extension HDU's of types TABLE, IMAGE, BINTABLE, and A3DTABLE. Accessing a nonstandard extension from a FITS file will ......
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