[AstroPy] pyfits extension naming issue

Craig Allen callen at gemini.edu
Thu Jul 8 16:52:14 EDT 2010


Pardon me if this is not the best list for this but I figured it's a
good place to start.  The issue is with pyfits... we want to rename the
extension in memory, that is, assign or change the EXNAME and EXTVER
keys for that extension.  We can easilly manipulate the header to do so,
but "pyfits.info()" does not reflect the change, further, picking out
the extension with the HDULists' "[]" operator doesn't work, complaining
of missing properties.

After investigation we found that this was because two HDU members are
not set, "name" and "_extver".  The main use case, btw, is that we have
raw data in which the SCI extensions are not named, and when loading
this into our AstroData IO abstraction (based on pyfits but providing
some higher level abstractions wrt the contained dataset), we want to
automatically name these extensions.  The following function therefore
"works".

def setExtname(self, name, ver = None):
	# trimmed some irrelevant code        
        if True:
            hdu = self.hdulist[1]
            nheader = hdu.header
            nheader.update("extname", name, "added by AstroData")
            nheader.update("extver", ver, "added by AstroData")
            hdu.name = name
            hdu._extver = ver
            # print "AD553:", repr(hdu.__class__)

The only other way I found to get the system to recognize this is
creating new HDUs from scratch (or writing the change and reloading the
file).  I like this much better, but:

(1) comments
(2) directions to the proper way to do this which I missed
(3) how should pyfits handle this if it does not already?

thanks
-craig
callen at gemini.edu






More information about the AstroPy mailing list