[AstroPy] astropy.io

Daniel Evans d.f.evans at keele.ac.uk
Fri Jan 12 05:14:36 EST 2018


Diego,

It turns out a useful trick here is to get Python to point out a traceback
for the warnings, to show where they originate from - I've only just learnt
this myself, trying to follow your problem. See
https://stackoverflow.com/questions/22373927/get-traceback-of-warnings for
instructions on how to do this.

I can indeed reproduce your issue - i.e. that verification is performed
despite explicitly setting verify='ignore'.

Having got the traceback out, the issue originates when the checksum of the
HDUList is calculated. This involves converting each card in the header to
a string, and when such an action is performed on a card, the card will
self-verify if this has not already been done - line 506 of
astropy/io/fits/card.py:

if self._image and not self._verified:
  self.verify('fix+warn')

I've added this info to the relevant github issue (
https://github.com/astropy/astropy/issues/7043), though I'll have to leave
it up to others to work out the solution.

Regards,
Daniel


On 11 January 2018 at 22:39, Diego Farias <dnfarias at uc.cl> wrote:

> 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
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
> https://mail.python.org/mailman/listinfo/astropy
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20180112/73515ff2/attachment-0001.html>


More information about the AstroPy mailing list