Skip to content

changed verify('fix') to verify('fix+warn') when printing fits cards - #5054

Merged
pllim merged 4 commits into
astropy:masterfrom
griffin-h:fits-fix
Dec 2, 2016
Merged

pllim merged 4 commits into
astropy:masterfrom
griffin-h:fits-fix

Conversation

@griffin-h

Copy link
Copy Markdown
Contributor

Printing a fits header with an invalid keyword currently raises a VerifyError on the first try (see #887). This causes problems when headers are converted to strings inside of other functions, because those functions don't catch that error. For example, astropy.wcs.WCS(hdr) crashes when hdr has an invalid keyword, even if that keyword is unnecessary for the WCS object. (This is because WCS copies the header by converting to a string and back.) This pull request changes the self.verify('fix') call inside self.image for header cards to self.verify('warn') so that a warning is still shown but other higher-level functions will be able to continue.

@griffin-h

Copy link
Copy Markdown
Contributor Author

The behavior I was actually looking for is fix+warn, so the card is fixed if possible but an exception is not raised if it can't be fixed (which happens only when the header keyword is invalid). I fixed this in the most recent commit, and now it passes all the unit tests.

@saimn

saimn commented Jun 23, 2016

Copy link
Copy Markdown
Contributor

👍 on doing something for this issue (see also #3668, #887). cc @embray ;-)

We had again this issue recently with a FITS file containing an illegal 'IRAF-B/P'keyword. The first time I print the header it fails with a VerifyError, and the second time it is well printed (because the first time the problematic card has been "verified"). As a consequence fitsheader fails to print the header.

VerifyError: 
Verification reported errors:
Unfixable error: Illegal keyword name 'IRAF-B/P'
Note: PyFITS uses zero-based indexing.

Ideally the default behavior could be configurable ? Currently it is possible to change it only when writing a file.

@griffin-h griffin-h changed the title changed verify('fix') to verify('warn') when printing fits cards changed verify('fix') to verify('fix+warn') when printing fits cards Jun 23, 2016
Comment thread CHANGES.rst Outdated
- Made TFORMx keyword check more flexible in test of compressed images to
enable copatibility of the test with cfitsio 3.380. [#4646]

- Converting a header card to a string now calls ``self.verify('warn')``

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code has fix+warn

@embray

embray commented Aug 16, 2016

Copy link
Copy Markdown
Member

The real problem here is deeper problems with the verification system that I've groaned about before, but don't have a clear solution to offer.

Part of the problem with this is that Card.image is not just used when printing, but also when writing to a physical file. So you need a solution that will allow invalid headers to at least be printable (which I agree should be possible) but that will not allow invalid FITS files to be written.

@embray

embray commented Aug 16, 2016

Copy link
Copy Markdown
Member

I think probably the call to self.verify should be moved out of the image property altogether. It's actually kind of bad when a property has side-effects (there are exceptions of course, and plenty of good exceptions even in io.fits, but this I think is not one of them).

I think there probably are reasons that verify() is called there, but maybe for whatever those reasons were maybe the verify() call should happen closer to the specific interfaces where it matters (e.g. printing, writing to a file, etc.)

@pllim pllim added this to the v1.3.0 milestone Dec 2, 2016
@pllim

pllim commented Dec 2, 2016

Copy link
Copy Markdown
Member

Merging this one. If someone wants to revisit the deeper problems mentioned, it can be a new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants