[AstroPy] Read FITS headers without loading data

Gary Bernstein garyb at physics.upenn.edu
Mon Sep 8 10:40:05 EDT 2014


I would like to extract the header information from a large multi-extension FITS file using astropy.io.fits.  This runs very slowly, and I suspect because it is reading the data of each extension when the header is accessed e.g. via

import astropy.io.fits as pf
f = pf.open(‘mef.fits’)
for hdu in f:
    h = hdu.header
    … do stuff with header…

It is *much* faster using e.g. cfitsio utilities (<<1 second compared to 10’s of seconds for the above on a multiple-GB file).  Am I correct that the data is being loaded for each extension in the above method?  If so is there a workaround?  Neither using getheader nor (un)setting memmap seems to make a difference.


Thanks,
Gary Bernstein





More information about the AstroPy mailing list