Image arithmetic - anjavdl/PHY517_AST443 GitHub Wiki
Processing astronomical images requires a number of arithmetic steps such as subtracting one image from another, taking the mean (or the median) of a series of images, determining the mean pixel count value, etc. In operations on more than one image, the operation is usually defined on a per-pixel basis, i.e. taking the difference between two images means to return the difference in counts for every pixel.
Many software packages exist for these kind of tasks. We introduce three methods in the course: python, pyraf, and ftools. Python is the most versatile, since it relies on reading the image data into numpy arrays, but requires the most programming of the three. Pyraf and ftools are conceptually simpler, but limited to certain operations. However, they are much easier to call e.g. for moderate numbers of images. In particular, ftools can be called directly from a Linux / Unix command line.
Python
With the astropy
and numpy
packages, python
is extremely versatile for working with astronomical images. See the FITS files in python tutorial.
FTOOLS
HEASARC provides a lot of basic utilities for manipulating FITS images and tables:
https://heasarc.gsfc.nasa.gov/ftools/ftools_menu.html
https://heasarc.gsfc.nasa.gov/lheasoft/ftools/headas/heatools.html
Here we will mainly use ftpixcalc and ftstat.
You can use ftpixcalc
for image arithmetic right on the command line, e.g.
ftpixcalc out.fits "(a-b)" a=img1.fits b=img2.fits
takes the difference between img1.fits
and img2.fits
, and writes the result to out.fits
. Note that you can use any letter as identifier except for "f" and "t".
An easy way to take the average of a number of images is through a line like this:
ftpixcalc out.fits "(a+b+c+d)/4" a=img1.fits b=img2.fits c=img3.fits d=img4.fits
It's also possible to take the median:
ftpixcalc out.fits bitpix=-32 "MEDIAN({a,b,c})" a=img1.fits b=img2.fits c=img3.fits
ftstat
prints out statistics about an object:
ftstat img1.fits
It can even do sigma-clipping on the fly:
ftstat img1.fits centroid=NO clip=YES sigma=5.0
The description for ftools tasks can be viewed through fthelp
, e.g.
fthelp ftstat
or on the web (see links above).