[AstroPy] what changed in astropy.io.fits?

Eduardo Bañados Torres eebanado at uc.cl
Mon Sep 2 10:39:08 EDT 2013


Hi all,

I recently upgraded to astropy version '0.3.dev5121'. I tried to run one of
my old codes and it failed because was using hdr.has_key('CDELT1'). And now
seems that the header does not have that attribute anymore: AttributeError:
'CompImageHeader' object has no attribute 'has_key'

If I use the old pyfits I don't get any error.
Trying to understand what happened, I open the same file using
astropy.io.fits and pyfits 2.3.2 and found that the hdu objects were
different, they had different number of Cards and different formats.

I solved my original problem replacing
if hdr.has_key('CDELT1'): by if 'CDELT1' in hdr.keys():

However I am still puzzled by the other changes I see in the HDUs, and I
wonder if they have some other implications.

Here is a code showing that the HDUs are different using astropy.fits and
pyfits (I think the problem should be independent of the image used so I am
not attaching it)

================
from astropy.io import fits
import pyfits

imgname = 'image.fits'

hdu1 = pyfits.open(imgname)
hdu2 = fits.open(imgname)

hdr1 = hdu1[1].header
hdr2 = hdu2[1].header

print "hdu1 == hdu2? ", hdu1 == hdu2
print hdu1.info()
print hdu2.info()
================

The output is:

hdu1 == hdu2?  False
Filename: image.fits
No.    Name         Type      Cards   Dimensions   Format
0    PRIMARY     PrimaryHDU       6  ()            int16
1                CompImageHDU   172  (1200, 1200)  float32
None
Filename: image.fits
No.    Name         Type      Cards   Dimensions   Format
0    PRIMARY     PrimaryHDU       6   ()           int16
1                CompImageHDU    174   (1200, 1200)   int16
None


The Cards number changes from 172 to 174 and the Format from float32 to
int16. And the attributes of the headers are different

Cheers,

-- 
Eduardo Bañados
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20130902/f27700b9/attachment.html>


More information about the AstroPy mailing list