Repository navigation
Check that the SIMPLE card is present - #10895
Conversation
|
Do we really need the I still have an interface in mind for how I would like to better manage FITS standard verification (whether I will ever have time to try to implement it is another story, admittedly). In other words, I would rather see this implemented within a verification framework (which currently does not exist in a consistent manner). In the meantime, instead of an |
| @classmethod | ||
| def _readfrom(cls, fileobj=None, data=None, mode=None, memmap=None, | ||
| cache=True, lazy_load_hdus=True, **kwargs): | ||
| cache=True, lazy_load_hdus=True, ignore_missing_simple=False, |
There was a problem hiding this comment.
Per my previous comment I'm not sure we even need an option for this; absent a more generic "verification" framework I don't think there's ever any reason not to check this and not to consider it an error if the SIMPLE keyword is missing.
|
TL;DR +1 to adding this (I believe it has been requested in the past), but I think we can make it even simpler (no pun intended :) |
|
I very much agree with @embray's overall approval and suggestions. I'd say the underlying policy question is how differently we want to treat different levels of standard violations. Per the current standard (§ 4.4.1.1) a minimum requirement is actually having and per this PR various violations of this standard would be treated as
The latter two should probably be treated as the same level, and as pointed out in #10895 (comment) as Then it remains open if the first case should be treated as a more serious violation (so perhaps we could still stick with two kwargs, one to allow general nonstandard HDUs including Final question: how does this go along with the still existing astropy/astropy/io/fits/connect.py Lines 53 to 57 in 2fa4824 e.g., will fits.open(open(filename, mode='rb'), ignore_missing_simple=True)work as well? |
|
Re |
Yes maybe, but at this stage of the parsing using the verification system is not really an option. It would be great to refactor the verification system, but it's a quite lot of work, unlikely to happen soon ;).
I choose |
Yep, I guess you got the answer ;).
Yes this one is handled later by the verification system, where we also fix some common issues like using strings instead of integers (for NAXIS).
The code you are pointing is only to detect FITS file for the unified IO (i.e. with |
dhomeier
left a comment
There was a problem hiding this comment.
Thanks for the updates, apart from the comments on the last test this looks good to go!
|
@embray @dhomeier : So, I guess the main point remaining is whether to keep |
Not sure how feasible that is if there are, as it seems, lots of them even coming out of major pipelines, where people have little control of the format they get. Can any of our FITS utilities fix it without requiring an expert user? Then I'd vote for that option, but otherwise I am fine with offering the kwarg in The non-ascii test issue should still be resolved. |
|
I checked and the non-ASCII case is tested by |
Yes, +1 |
|
It seems there are still issues with the treatment of invalid headers: This behaviour is not affected by this PR and rather belongs in a separate issue, but probably confirms the need for a more consistent verification framework @embray pointed out. |
I'm not so sure. Of all the crazy, bogus, busted FITS files I've seen, I have never seen one like that. It should just not be treated as a valid FITS file. |
|
Also, if I had the opportunity to overhaul the FITS verification framework I would also remove the |
Maybe I misinterpreted some comments in the earlier discussion like #3941 (comment) when I concluded that they were not even uncommon.
I think some possibilities to make this support slightly less "official" could be
|
|
@dhomeier You raise some good points. My thinking was that the string It's also a standard violation that can easily be "fixed", as we do with other violations, so long as the rest of the file "looks like" a FITS file (e.g., the first 80 bytes at least parses as a valid header card of some kind). My other concern about adding an explicit option for this is I would rather see it handled in the context of a more general validation framework that also has the ability to fix simple errors like this as long as the rest of the file is readable. Years ago I started on that project but never completed it, and I think it would have to be resurrected from the ground up. It consisted of two layers:
TL;DR, absent time to resurrect and complete that work though, I agree it would be unfair to say "no new arguments can be added to |
9b0c7b8 to
40e138a
Compare
|
(Rebased and moved the changelog entry to 4.3). I would have been happy to remove this option, but it seems we now agree on keeping it, and we could indeed deprecate/remove it if one day there is a better verification system. So I think it's good to go now ? |
|
This PR triggered a CI failure in Vaex, fix in vaexio/vaex#1490 Our header had: Our header/value was aligned to the right with spaces, I couldn't find that in the spec/rfc that it had to be that way, but in case it does not, this check might have been too strict. |
|
SIMPLE is a mandatory keyword so it's value must be in Byte 30: (from the FITS standard, https://fits.gsfc.nasa.gov/fits_standard.html) RFC 4047 also specifies the magic number : (https://datatracker.ietf.org/doc/html/rfc4047) |
|
Thanks, then it was simply an error on our side! |
|
It was actually a good question, finding the justification was not so easy ;) |
|
Yeah, good to have this sorted out, thanks for that! |
|
I have a similar issue where the first 30 bytes of some external data are instead of the expected so I got Don't get me wrong I completely agree that the file I have is non-standard, but it seems to me that this check is overly strict if our goal is just to be sure that we're dealing with a FITS file. Keeping in mind this philosophy: astropy/docs/io/fits/usage/verification.rst Lines 8 to 15 in c6cafcb I believe we could make a much better attempt at finding a SIMPLE card before giving up. Instead of: astropy/astropy/io/fits/hdu/hdulist.py Lines 1084 to 1085 in c6cafcb Why not something like: match_sig = re.match(rb"SIMPLE *= *[T|F]", simple)
|
|
I like that, a warning would be nice though so that people are aware the fits image is not created according to the standard. |
|
Sorry for the delay, last 2 weeks have been quite busy. |
|
No worries, take your time. Correct me if I'm wrong, but from what I can tell the main goals here were that, when Maybe I understood it incorrectly and the goal here is specifically to discourage the usage of non-standard Either way, even if this behaviour isn't changed, could we at least include a suggestion to use |
|
This is a significant break in backwards compatibility for our code that processes archival data that cannot be easily changed. We will have to update hundreds of lines of code -- every fits.open we have in 11 different packages -- in order to set ignore_missing_simple=True. Would it at least be possible to make True the default value to preserve handling for files that can be read as FITS? |
|
It is not impossible to add a config item to control this, though it does add to code complexity... @melanieclarke , can you please open a new issue and link to this one? Thanks. |



Fixes #3941, fixes #7569.
With this
fits.openwill check that aSIMPLEcard is present at the beginning of file, which allows to directly raise a better error when opening a file that is not FITS. Theignore_missing_simpleoption can be used to deactivate this behavior.@dhomeier - requesting your review since you have been interested in FITS lately ;). cc @embray if you want to have a look.