[AstroPy] Capturing pyfits warnings

Bridgman, William T. william.t.bridgman@nasa....
Wed Sep 15 11:28:45 CDT 2010


Jim,

Beyond another package with a learning curve of limited use in our  
environment, probably not.  I occasionally use FV, but that is pretty  
stand-alone.

Because we work with so many datasets from a wide variety of missions  
(Earth/geospace/solar) and often *combine* them to tell stories, we  
have lots of packages installed - enough that we've had significant  
name collisions and path problems between them.

Tom
On Sep 15, 2010, at 11:09 AM, Jim Vickroy wrote:

> Please excuse this non-Python proposal, but would it be worth  
> considering FTOOLS (in particular fverify) to accomplish this task?   
> -- jv
>
> Bridgman, William T. wrote:
>>
>> try:
>> 	fimg=pyfits.open(dfile)
>> except:
>> 	whatever...
>>
>> header=fimg[0].header
>>
>> If warnings are warnings, this runs fine.
>>
>> If warnings are elevated to exceptions, the pyfits.open throws the
>> exception before loading fimg.  The fimg[0].header access fails.
>> Putting fimg[0].header access inside the try: block doesn't help
>> either (of course).
>>
>> Perhaps inside the except: block I could set warnings back from
>> exceptions to warnings and do pyfits.open again.  I don't know that
>> much about python innards, but this sounds like something that would
>> cause other weird (stack?) problems as I examine the 22,000+ FITS
>> files in our data area.
>>
>> Tom
>>
>>
>> On Sep 15, 2010, at 10:06 AM, jtaylor2@stsci.edu wrote:
>>
>>
>>> Tom,
>>>
>>>   I am not sure I understand exactly what is going on here, but if
>>> having the warnings module issue exceptions instead of warnings is
>>> causing another warning to be raised as an exception that you would
>>> like to remain as a warning, you can fix this by using
>>> filterwarnings and supplying a regular expression that matches just
>>> the warning that you want raised as an exception.  In your case
>>> something like:
>>>
>>> warnings.filterwarnings('error',message='.*Warning:  File may have
>>> been.*"')
>>>
>>>   If you contact me directly at jtaylor2@stsci.edu with more
>>> details, especially if you can point me to a fits file that is
>>> causing the problem, I may be able to be of more help.
>>>
>>>     Jim T.
>>>
>>
>> --
>> 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
>>
>

--
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/






More information about the AstroPy mailing list