Conversation
| try: | ||
| cov_index_map = fits.read_ext_data('COV') | ||
| except (OSError, KeyError): | ||
| except (OSError, KeyError, ValueError): |
There was a problem hiding this comment.
What is the situation here? It is a fits file but doesn't have the 'COV' extension?
| hdu = self.fits_object[extension] | ||
| if use_fitsio: | ||
| if use_rustfits: | ||
| return isinstance(hdu, (rustfits.CompressedImageHDU, rustfits.ImageHDU)) |
There was a problem hiding this comment.
You can just check rustfits.ImageHDU
| return {} | ||
| else: | ||
| hdr = copy.copy(metadata) | ||
| for reserved in FITS_RESERVED: |
There was a problem hiding this comment.
rustfits will ignore protected fits header keys when you write to a header from an existing FITSHeader using the update method, but not when writing from a dict, so it is correct to skip protected keys.
rustfits provides rustfits.is_protected_key(name) for the above, which could replace your check against FITS_RESERVED.
Note, if this metadata was itself created from a rustfits FITSHeader, you can do header.to_dict(skip_protected=True) to provide the clean dict.
It probably makes sense to provide a method to clean a dict of protected keys so you don't need the loop.
There was a problem hiding this comment.
Because of the way that the tests do reading/writing, and there's no way to directly create a rustfits header in python, sometimes this code gets a rustfits header and sometimes a dict. But I will make use of the is_protected_key().
There was a problem hiding this comment.
Hmm. I don't want to loop over all keys ... just the protected ones. I just don't know how to do this without a bunch more special cases.
There was a problem hiding this comment.
There is no need to change what you are doing, I was just giving information, sorry to imply otherwise
Here is what rustfits does
| except (OSError, UnicodeDecodeError, ValueError): | ||
| pass | ||
| # UnicodeDecodeError occurs when trying to read an hdf5 file as if it's FITS | ||
| # ValueError occurs from rustfits when trying to read an hdf5 file as if it's FITS |
There was a problem hiding this comment.
What actual error is raised? I'm guessing it is ValueError because it tries to parse the primary header and finds the wrong values in the first bytes, but I want to see if a different error might be more appropriate to raise.
There was a problem hiding this comment.
So the following code snippet raises ValueError because it can't access extension 0. If the file nothing.notfits is not there then it raises an OSError (as expected). If the file isn't a fits (e.g. touch nothing.notfits) then rustfits will happily "open" the file but won't raise (ValueError) until it tries to access an extension. Should it be checking that it's a valid fits file on open?
with rustfits.FITS("nothing.notfits") as f:
print(f[0])
There was a problem hiding this comment.
rustfits.FITS should do eager header parsing on open. It is true that fitsio was lazy
There was a problem hiding this comment.
But it doesn’t parse the header on an empty file?
There was a problem hiding this comment.
sounds like a bug, investigating
There was a problem hiding this comment.
this is fixed and will be in the next release
No description provided.