Question

I need to change a few values in a couple of FITs image headers to fit with some test data I have. Therefore I'm trying to hack a FITs image header at the minute to run with the application.

However at the minute - I can't even see the header, never mind hack it. I run Ubuntu.

Can anyone advise some software to view the FITs - perhaps even hack it?

Was it helpful?

Solution 4

edhead seems to do the job very well. Only piece of software I have found that allows you to edit the header at the command line.

OTHER TIPS

If you are familiar with the python programming language, you could use the astropy module to view and manipulate fits files. Say you want to view the header of the file 'image.fits', then you do:

from astropy.io.fits import getheader

header = getheader('image.fits') # Load the data
print header                     # Print the header to screen

If you want to modify a particular key of the header, you do:

header['key'] = 'new_key' 

Kind of old, but I think the answer could use some updates and additional information.

View .fits file

My personal favorite GUI for viewing '.fits' files is DS9. Once installed you can view a file by typing ds9 /path/to/file.fits. Alternatively you can just use the menu in the GUI to load the image. Once you load the image in the viewer, you can view the header information by using the very top menu bar and going to 'File -> Display Header'. Unfortunately, I dont believe you can modify the header in DS9.

Modify fits header

For modifying the fits header, I found the easiest is to use astropy (a python package). Since you're using Ubuntu you should be able to download it via apt-get, so hopefully pretty easily. To actually edit the fits header, you can do the following in a python script, or from the interpreter (here's some additional help):

# Import the astropy fits tools
from astropy.io import fits

# Open the file header for viewing and load the header
hdulist = fits.open('yourfile.fits')
header = hdulist[0].header

# Print the header keys from the file to the terminal
header.keys

# Modify the key called 'NAXIS1' to have a value of 100
header['NAXIS1'] = '100'

# Modify the key called 'NAXIS1' and give it a comment
header['NAXIS1'] = ('100','This value has been modified!')

# Add a new key to the header
header.set('NEWKEY','50.5')

# Save the new file
hdulist.writeto('MyNewFile.fits')

# Make sure to close the file
hdulist.close()

You could also throw this in a loop for multiple file manipulation.

Is this the Flexible Image Transport System format used by Astronomers?

This site has some background information and further links, but explains that

Users must develop or obtain separate software to read and display the data from the FITS file. There are a number of different packages for particular applications and hardware, but there is no single standard package for all applications.

Still, you can use it for your own purposes.

As only 1/2 of the question was answered (editing the FITS headers), to view the images, I commonly use DS9 (aka SAOImage).

Also, if you're going to be editing a lot of FITS headers, I tend to go with either CFITSIO or Astro::FITS::Header

... and it's possible to edit FITS headers with any text editor, so long as you follow a few simple rules -- cards (key/value/comment sets) are always 80 characters long, and the FITS header is always a multiple of 2880 bytes. Depending on the file, there might be multiple headers, as the first header could declare the file to contain multiple images or tables.

The Sloan Digital Sky Survey developer web site has some libraries that should meet your needs.

FitsLib - A library for reading and manipulating FITS files on the Microsoft's .Net platform. FITS stands for flexible image transport system. FitsLib aims to provide an interface to the FITS file on the Dot Net Platform. It is built as an object oriented wrapper around the CFITSIO library's interface to the FITS files.

While FitsLib itself is designed for C# and the .NET Framework, you might be able to use it under Mono on your Ubuntu system. Or, perhaps you can use the CFITSIO library directly, which is written in C.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top