Hack a FITs Image Header
Asked Answered
L

6

5

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?

Leonaleonanie answered 8/2, 2010 at 11:18 Comment(0)
L
2

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.

Leonaleonanie answered 12/2, 2010 at 10:27 Comment(0)
T
5

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.

Thoreau answered 15/7, 2016 at 17:59 Comment(0)
B
4

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' 
Budgie answered 12/1, 2016 at 11:0 Comment(0)
L
2

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.

Leonaleonanie answered 12/2, 2010 at 10:27 Comment(0)
G
1

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.

Godric answered 8/2, 2010 at 11:26 Comment(1)
Yes, it is used by Astronomers.Leonaleonanie
G
1

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.

Giuseppinagiustina answered 23/6, 2010 at 3:43 Comment(0)
A
0

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.

Advocation answered 10/2, 2010 at 6:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.