spacetelescope/PyFITS — pull request #46 by embray (2013-12-17 23:10:32+00:00)
Title: FITS File Writing Performance

Hi. Here is what I do.

import pyfits as pf
hdulist = pf.open("mainfile.fits")
data = hdulist[0].data
header = hdulist[0].header

...some commands to get some header information...

Loop over X:
Loop over Y:
cut = data[ ... : ... , .... : ....]
some header keyword calculations
pf.writeto("newname", cut, header)

Now, the program generates ~1000 small images and takes 8.5 seconds to do so. If I modify the above code to say,
pf.writeto("newname", cut)

Notice, header not being supplied. This time, it is 2.4 seconds. Why is the header writing part so intense? Am I doing something wrong?