Wednesday, February 13, 2013

Pyfits: quickly overwriting a .fits header

I had some .fits files that lost their header information during analysis. Here's a quick kludge I coded up to retrieve the original header and overwrite it for a single file.

import pyfits 
import sys

fileName = sys.argv[1]

originalFile = "../data/SDSS/r/"+fileName[:-4]+"fit.gz"
OriginalHDUList =
OriginalHeader = OriginalHDUList[0].header

HDUList =, mode = 'update')
HDUList[0].header = OriginalHeader
print HDUList[0].header

No comments:

Post a Comment