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 = pyfits.open(originalFile)
OriginalHeader = OriginalHDUList[0].header



HDUList = pyfits.open(fileName, mode = 'update')
HDUList[0].header = OriginalHeader
print HDUList[0].header
HDUList.flush()

No comments:

Post a Comment