Adding Keywords to FITS Headers

This post might clarify any issues people may have had when trying to add keywords to their FITS image headers. These lines should appear in order at some point in your code but do not necessarily have to be all in a row. Note that this may not give correct ra/dec readouts with flattened plate constants.

>>> from import fits
### You must open the FITS file in ‘update’ mode in order to make any lasting changes to the file
>>> hdulist =‘yourFile’, mode = ‘update’)
### This will be necessary to find the central pixel values of your image
>>> im = fits.getdata(‘yourfile’)
### The hdu has two components – header and data – so we use .header to access the header
>>> hdu = hdulist[0].header
### The FITS header acts like a dictionary, with each entry having a ‘KEYWORD’ and value
>>> hdu.set(‘KEYWORD’, ‘value’)
### The .set() function updates the value of an existing keyword or creates a new entry if it can’t be found
### Input all necessary entries with this format
### The .close() function is necessary to save any changes you may have made to the file
>>> hdulist.close()

-Alex M.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s