imexam
imexam copied to clipboard
Provide way to fix fits file
I'm not sure whether this is an imexam or more a ginga issue, possibly both. I'm opening it first here as imexam is the layer the user interacts with:
In [10]: viewer.load_fits('flat.0038.fits')
2019-05-08 18:34:09,643 | E | ginga_viewer.py:633 (load_fits) | Exception loading image: VerifyError("Unparsable card (CD1_1), fix it first with .verify('fix').")
---------------------------------------------------------------------------
VerifyError Traceback (most recent call last)
/usr/local/lib/python3.7/site-packages/imexam/ginga_viewer.py in load_fits(self, fname, extver)
622 hdu = filedata[extver]
--> 623 image.load_hdu(hdu)
624 else:
/usr/local/lib/python3.7/site-packages/ginga/AstroImage.py in load_hdu(self, hdu, fobj, naxispath, inherit_primary_header)
125 ahdr = self.get_header()
--> 126 self.io.fromHDU(hdu, ahdr)
127
/usr/local/lib/python3.7/site-packages/ginga/util/io_fits.py in fromHDU(self, hdu, ahdr)
107 continue
--> 108 ahdr.set_card(card.keyword, card.value, comment=card.comment)
109 else:
/usr/local/lib/python3.7/site-packages/astropy/io/fits/card.py in value(self)
284 elif self._valuestring is not None or self._image:
--> 285 value = self._value = self._parse_value()
286 else:
/usr/local/lib/python3.7/site-packages/astropy/io/fits/card.py in _parse_value(self)
759 raise VerifyError("Unparsable card ({}), fix it first with "
--> 760 ".verify('fix').".format(self.keyword))
761
VerifyError: Unparsable card (CD1_1), fix it first with .verify('fix').
During handling of the above exception, another exception occurred:
Exception Traceback (most recent call last)
<ipython-input-10-184f17aeac92> in <module>()
----> 1 viewer.load_fits('flat.0038.fits')
/usr/local/lib/python3.7/site-packages/imexam/connect.py in load_fits(self, *args, **kwargs)
400 else:
401 self.exam._datafile = args[0]
--> 402 self.window.load_fits(*args, **kwargs)
403
404 def load_region(self, *args, **kwargs):
/usr/local/lib/python3.7/site-packages/imexam/ginga_viewer.py in load_fits(self, fname, extver)
632 except Exception as e:
633 self.logger.error("Exception loading image: {0}".format(repr(e)))
--> 634 raise Exception(repr(e))
635
636 def panto_image(self, x, y):
Exception: VerifyError("Unparsable card (CD1_1), fix it first with .verify('fix').")
This looks like an issue with the user FITS file, I'm not too inclined to apply 'fix' for them under the covers, it's probably good they get this error and fix, then resave the file, so that it's valid FITS. FWIW, imexam will also load any numpy array to either ginga or ds9, if you can open the fits file you can display the data array to the viewer with viewer.view(numpy_array_name)
.
I'm not proposing to "fix" it by default, and I could work around this as detailed in #170, but I would find it very useful to have a kwarg that would let me fix it on the fly when opening. Otherwise I agree that it would be nice if all fits files coming down from telescopes would follow the standard, but I'm afraid a world like that would probably is utopia.
okay, I'll add a parameter to the load_fits, but set it to not fix by default. Do you think fix
would work as the name?
what about verify_fits
with None
as default, and then the strings as options that can be passed to verify()
?