from IPython.core.display import HTML
css_file = './styles/styles.css'
HTML(open(css_file, "r").read())
There are certain circumstances where we want to edit the information contained within the FITS header. For example, when reducing our data we may want to set the IMAGETYP or OBJECT entry to indicate whether a file is a DARK, FLAT, BIAS or LIGHT (science) frame.
This can be done, without copying the file, using Astropy's fits
library. The first step is to open the file in what is called "update" mode - which allows us to alter the file without making a copy:
from astropy.io import fits
hdu_list = fits.open('../../data/M51/dark1.fit',mode='update')
The fits.open
command returns a HDUList
object, which we store in the hdu_list
variable. Each FITS files can contain a number of HDUs. For simple image files, the data and header are usually in the Primary HDU, which is accessed using the normal slice notation hdu_list[0]
. The data and header are accessed like so:
data = hdu_list[0].data
header = hdu_list[0].header
print(header['IMAGETYP'])
Notice how the IMAGETYP FITS header entry is correctly set for this file. If we wanted to change the entry, it is very simple:
header['IMAGETYP'] = "DARK"
At the moment, our changes are not reflected in the file on the computer disk. To write the changes to disk we use the flush
member of the hdu_list
:
hdu_list.flush()
That's it! Using this method you can set the headers in your data to be anything you like.