[AstroPy] Capturing pyfits warnings

Jim Vickroy Jim.Vickroy@noaa....
Tue Sep 14 13:12:20 CDT 2010


Bridgman, William T. wrote:
> I tried using the Exceptions & Warning class
>
> try:
>      fimg=pyfits.open(dfile)
> except Warning as w:
>      print w.filename, w.message
> finally:
>      fimg.close()
>
> and it still doesn't grab it.  I get the warning:
>
> Warning: File may have been truncated: actual file length (2102784) is  
> smaller than the expected size (4213440)
>
> I've done limited work with the Exceptions class, and until now,  
> nothing with the Warnings class so I'm probably missing something.
>
> Tom
>   

Take a look at http://www.doughellmann.com/PyMOTW/warnings/ which 
discusses how to convert a warning to an exception.  -- jv

> On Sep 14, 2010, at 10:24 AM, Jim Vickroy wrote:
>
>   
>> --_000_4C8F85BA8070609noaagov_
>> Content-Type: text/plain; charset="iso-8859-1"
>> Content-Transfer-Encoding: quoted-printable
>>
>> 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<mailto: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<mailto: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 =3D 'my.fit'
>>>>>
>>>>> try:
>>>>>           
>> ...     HDUs =3D 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 c
>>     
>
> --
> 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
>   

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/astropy/attachments/20100914/845c7053/attachment.html 


More information about the AstroPy mailing list