[AstroPy] astropy.io

Diego Farias dnfarias at uc.cl
Thu Jan 11 17:39:41 EST 2018


Hi Pythoners,

I have posted this as an issue on github also, but I think it could be
forgotten because it is a reply to another open issue.

While using astropy.io on images with several HIERARCH cards (e.g.,
HIERARCH ESO INS RETA2 ROT = 0.0), which are Not-STANDARD FITS format, I
encounter with a possible bug: if I do for example

hdulist = fits.open(IMAGE,mode='update')
hdulist[0].header.set('DISPAXIS', '1')
hdulist.close(output_verify = 'ignore')

It should prevent to print any warning message, but instead I get warning
and ALSO fixes:

WARNING: VerifyWarning: Verification reported errors:
[astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'ESO INS IMAGE DISTOR1' is not FITS standard
(invalid value string: '7.771690e-06 / distortion coefficient').  Fixed
'ESO INS IMAGE DISTOR1' card to meet the FITS standard.
[astropy.io.fits.verify]
WARNING: VerifyWarning: Note: astropy.io.fits uses zero-based indexing.
 [astropy.io.fits.verify]
....

etc. The same strange behavior happened to someone else, so I think it
could be a bug. I'm trying to trace where this happens, and the 'ignore'
option it is used correctly once to verify in hdulist.py
(astropy/io/fits/hdu) at

def flush (self, output_verify='fix', verbose=False):
        self.verify(option=output_verify)

( def close uses flush so ..) and this is good, it does not print a thing.
The bug appears in the last line of the same method
       .
       .
       .
        elif self._file.mode == 'update':
            self._flush_update()

in self._flush_update(). If I search in this method, I could trace the
'bug' to

    def _flush_update(self):
        """Implements flushing changes to a file in update mode."""

        for hdu in self:
             hdu._prewriteto(checksum=hdu._output_checksum, inplace=True)


the hdu._prewriteto line. In this method, the warning appears after the
return

    def _prewriteto(self, checksum=False, inplace=False):
        if self._scale_back:
            self._scale_internal(BITPIX2DTYPE[self._orig_bitpix],
                                 blank=self._orig_blank)
        self.update_header()
        if not inplace and self._data_needs_rescale:
            # Go ahead and load the scaled image data and update the header
            # with the correct post-rescaling headers
            _ = self.data

        return super(_ImageBaseHDU, self)._prewriteto(checksum, inplace)

but my python knowledge is too short to fix this by myself (yet). So if you
have any idea please share.

Sorry for the long message and thanks in advance,

Diego
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20180111/2a99f618/attachment.html>


More information about the AstroPy mailing list