Montage Montage is an astronomical image toolkit with components for reprojection, background matching, coaddition and visualization of FITS files. It can be used as a set of command-line tools (Linux, OS X and Windows), C library calls (Linux and OS X) and as Python binary extension modules.
The Montage source is written in ANSI-C and code can be downloaded from GitHub ( https://github.com/Caltech-IPAC/Montage ). The Python package can be installed from PyPI ("</i>pip install MontagePy"). The package has no external dependencies. See http://montage.ipac.caltech.edu/ for details on the design and applications of Montage.
The Montage modules are generally used as steps in a workflow to create a mosaic of a set of input images. These steps are: determine the geometry of the mosaic on the sky, reproject the images to a common frame and spatial sampling; rectify the backgrounds to a common level, and coadd the images into a mosaic. This page illustrates the use of one Montage module, mBgExec, which is used to modify the backgrounds for a set of images.
Visit Building a Mosaic with Montage to see how mBgExec is used as part of a workflow to creage a mosaic (or the one shot version if you just want to see the commands). See the complete list of Montage Notebooks here.
from MontagePy.main import mBgExec, mViewer
help(mBgExec)
If we coadd a set of reprojected 2MASS images after reprojection but without doing anything about the backgrounds, the differences in background levels are obvious:
from IPython.display import Image
mViewer('-color black -imginfo M17/rimages.tbl \
-ct 1 -gray M17/uncorrected.fits -2s max gaussian-log \
-out work/M17/uncorrected.png',
'', mode=2)
Image(filename='work/M17/uncorrected.png')
Through the background modeling, we can derive a set of corrections to the individual images (the "id" in this table is a reference to the images metadata table shown as an overlay above).
import pandas as pd
from astropy.io import ascii
ipactable = ascii.read('M17/corrections.tbl').to_pandas()
ipactable
With mBgExec, we can apply these corrections to the original image:
rtn = mBgExec('M17/projected',
'M17/pimages.tbl',
'M17/corrections.tbl',
'work/M17/corrected')
print(rtn)
and after coadding the corrected images together, we get:
mViewer('-color black -imginfo M17/rimages.tbl \
-ct 1 -gray M17/mosaic.fits -2s max gaussian-log \
-out work/mosaic_bgexec.png',
'', mode=2)
Image(filename='work/mosaic_bgexec.png')
Montage functions return JSON structures. They always include a status (0: success; 1: error) and a variable number of informational parameters.
If mBgExec encounters an error, the return structure will just have two elements: a status of 1 ("error") and a message string that tries to diagnose the reason for the error.
For instance, if the user asks for an invalid file:
rtn = mBgExec('M17/projected',
'M17/unknown.tbl',
'M17/corrections.tbl',
"work/M17/corrected")
print(rtn)
mBgExec can also be run as a command-line tool in Linux, OS X, and Windows:
Usage: mBgExec [-p projdir] [-s statusfile] [-d] [-n(o-areas)] images.tbl corrections.tbl corrdir
If you are writing in C/C++, mBgExec can be accessed as a library function:
/*-*****************************************************************/ /* */ /* mBgExec */ /* */ /* Take the background correction determined for each image and */ /* subtract it using mBackground. */ /* */ /* char *path Path to images to be background-corrected */ /* char *tblfile Table file list of images to correct */ /* char *fitfile Table of background levels/slopes */ /* char *corrdir Directory for corrected images */ /* int noAreas Flag indicating there are no area images. */ /* int debug Debug flag. */ /* */ /*******************************************************************/ struct mBgExecReturn *mBgExec(char *path, char *tblfile, char *fitfile, char *corrdir, int noAreas, int debug)
Return Structure
struct mBgExecReturn { int status; // Return status (0: OK, 1:ERROR) char msg [1024]; // Return message (for error return) char json[4096]; // Return parameters as JSON string int count; // Number of images int nocorrection; // Number of images for which there was no correction int failed; // Number of images where correction failed };