Example Scripts

astLib is distributed with a number of example scripts, which may also be useful in their own right. To obtain a list of input parameters required by each script, simply run them from the command line, e.g.:

> python clipfits2png.py
Run: % clipfits2png.py <input .fits image> <RADeg> <decDeg> <clip size [arcmin]> <output .png> <.png size in pix> <cut per cent level [e.g. 99.5]> <matplotlib colour map name [e.g. hot | cool]>

Documentation for some of these scripts is provided below.


This script demonstrates some of the routines in the astImages and astWCS modules. It clips a square section at the input coordinates (decimal degrees) from a specified .fits image, and outputs an image in .png format. The output image is rotated and flipped using the image WCS information such that North is at the top, and East is at the left. For example:

> python clipfits2png.py image.fits 120.0 -35.0 3 test.png 400 99.5 hot

makes a 400 pixel square .png image (test.png) of a 3 arcmin square region centred at R.A=120.0, dec.=-35.0 degrees in image.fits. The image is scaled in intensity using a 99.5 per cent cut, and the 'hot' colormap from matplotlib is used.


One of Python's most attractive features is its simple database API and the ready availability of modules that allow it to connect to a number of different database servers. This script performs the same task as clipfits2png.py described above, but instead it takes as input a sqlite database file (sqlite3 is included as part of the standard Python library from version 2.5 onwards). The script uses WCS information to determine if any of the targets listed in the specified sqlite database table are located within each .fits image in the current directory. The database target table should have the following columns: object name, R.A. (decimal degrees), dec. (decimal degrees). For each target found in each image, a .png file is created and stored in the png_images directory. As an example of usage:

> python clipfits2png_sqlite.py example.db exampleTable 3 400 99.5 hot

will produce 400 pixel square .png images of 3' square dimensions, centred on all the targets that can be found in the table exampleTable in the example.db sqlite database file.

contour_clipfits2png.py and contour_clipfits2png_sqlite.py

As their names suggest, these scripts are similar to clipfits2png.py and clipfits2png_sqlite.py, except that they produce contour overlay images (e.g., X-ray contours over an optical image).

For example, to produce a single 3' square, 400 pixel on a side, contour overlay image called test.png, from an optical image called optical.fits and an X-ray image called x-ray.fits, for an object located at R.A.=120.0, dec.=-35.0 degrees:

> python contour_clipfits2png.py optical.fits x-ray.fits 120.0 -35.0 3 test.png 400

Similarly, to produce 3', 400 pixel on a side contour overlay plots for all objects listed in a sqlite database (as in the example given for clipfits2png_sqlite.py above), using a set of optical images located in a directory called optical, and a set of X-ray images located in a directory called x-ray:

> python contour_clipfits2png_sqlite.py example.db exampleTable 3 400 optical x-ray

The output images are stored in a directory called png_contour_images.