[AstroPy] Capturing pyfits warnings

Jim Vickroy Jim.Vickroy@noaa....
Tue Sep 14 09:24:58 CDT 2010


Bridgman, William T. wrote:
> I'm trying to get an inventory of all the FITS files I'm storing  
> locally, to track down duplicates and determine data gaps in covering  
> certain phenomena.
>
> I'm getting a warning from pyfits about file size mismatches.  Is  
> there an elegant way to capture this message, or a warning code, that  
> I can save with the file inventory record for generating a summary  
> report?
>
> I see some items in the pyfits doc on capturing this with the warnings  
> module but it seems more focussed on logging.  It is unclear how I  
> would capture the warning information as a separate variable to save  
> with the inventory dictionary.
>
> Thanks,
> Tom
> --
> Dr. William T."Tom" Bridgman               Scientific Visualization  
> Studio
> Global Science & Technology, Inc.          NASA/Goddard Space Flight  
> Center
> Email: William.T.Bridgman@nasa.gov         Code 610.3
> Phone: 301-286-1346                        Greenbelt, MD 20771
> FAX:   301-286-1634                        http://svs.gsfc.nasa.gov/
>
>
>
>
> _______________________________________________
> AstroPy mailing list
> AstroPy@scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy
>   
Does this work for you?

 >>> import sys
 >>> sys.version
'2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)]'
 >>> import pyfits
 >>> pyfits.__version__
'2.2.2'
 >>> source = 'my.fit'
 >>>
 >>> try:
...     HDUs = pyfits.open(source)
... except IOError as error:
...    # do whatever you wish with the captured *error* ...
...     print error.message
...     print error.filename
...     print error.errno
...     print error.args
...     print error.strerror
... finally:
...     HDUs.close()
...    
Header missing END card.
None
None
('Header missing END card.',)
None
 >>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/astropy/attachments/20100914/c96b0dc6/attachment.html 


More information about the AstroPy mailing list