astropy/astropy — pull request #2053 by barentsen (2014-02-06 16:11:23+00:00)
Title: wcslint and wcs.validate raise an unexpected NameError exception

I encountered an unexpected NameError exception when using `wcslint` to validate real data. The problem can be reproduced using the following code:

```python
from astropy.io import fits
from astropy import wcs
h = fits.Header()
h['RADESYSA'] = 'ICRS'
h['PV2_1'] = 1.0
hdu = fits.PrimaryHDU([[0]], header=h)
hdulist = fits.HDUList([hdu])
wcs.validate(hdulist)
```

Which raises the following error:

```python
ERROR: NameError: global name '__warningregistry__' is not defined [astropy.wcs.wcs]
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
in ()
----> 1 wcs.validate(hdulist)

/local/home/gb/dev/astropy/astropy/wcs/wcs.pyc in validate(source)
2020 hdu_results.append(wcs_results)
2021
-> 2022 del __warningregistry__
2023
2024 with warnings.catch_warnings(record=True) as warning_lines:

NameError: global name '__warningregistry__' is not defined
```

The problem can be traced back to the fact that `find_all_wcs()` returns two WCS objects for the given HDU, causing `del __warningregistry__` to be executed twice.

The attached pull request circumvents the exception, but it does not solve the fact that `find_all_wcs` returns two WCS objects and that the validation routine does not yield any warning about the faulty WCS?

An example of real data on which the issue is encountered is available here: http://star.herts.ac.uk/~gb/tmp/astropy/wcslint-fails-on-this-image.fits.gz