[AstroPy] Read FITS headers without loading data
garyb at physics.upenn.edu
Mon Sep 8 11:58:12 EDT 2014
Thanks for setting me straight Erik.
Typically 60 extensions per FITS files. Each is a binary table of cataloged objects from one CCD of a mosaic camera. So there are many keywords in the header and perhaps I am just seeing the processing time for this.
On Sep 8, 2014, at 11:14 AM, Erik Bray <embray at stsci.edu> wrote:
> On 09/08/2014 10:40 AM, Gary Bernstein wrote:
>> 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.
> No, it doesn't touch the data when just reading headers. The difference depends
> largely on what you're doing with the headers, though in general it's due to the
> fact that CFITSIO is written in C while PyFITS is written in pure Python, and
> does a lot more to parse headers into an in-memory data structure.
> That said, how many headers are in this file? It shouldn't take "10's of
> seconds" though again that might depend in part on what you're doing.
> AstroPy mailing list
> AstroPy at scipy.org
More information about the AstroPy