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, mBgModel, which is used to model the set of background corrections needed for a set of images.
Visit Building a Mosaic with Montage to see how mBgModel 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 mBgModel, mViewer
help(mBgModel)
Once we have determined and fit pairwise the overlaps between images in a set, we use mBgModel to determine the corrections we should make to minimize the overall background differences. The method used is a modified least-squares fitting for the set of correction coefficients using all the pixel-to-pixel differences in the overlap sets but with several approximations invoked to speed up the computational process.
We start with a set of pairwise differences, each fit with a plane and ignoring large excursions. The idea here is that in an overlap region two images (both flux-calibrated) will differ only by the levels (and maybe a little slope) in their backgrounds. Where the background varies more extremely, background matching is likely the be futile. We have seen this happen, for instance, in 2MASS images where airglow due to blobs of gas in the Earth's atmosphere sometimes contaminate images on an size scale similar to the images.
Normally, though, these fit background differences look like this ('plus' and 'minus' refer to row IDs in the input image metadata table):
import pandas as pd
from astropy.io import ascii
ipactable = ascii.read('M17/fits.tbl').to_pandas()
ipactable
mBgModel uses this data to model the corrections for the individual IDs:
rtn = mBgModel('M17/pimages.tbl', 'M17/fits.tbl', 'work/M17/corrections.tbl')
print(rtn)
ipactable = ascii.read('work/M17/corrections.tbl').to_pandas()
ipactable
Montage functions return JSON structures. They always include a status (0: success; 1: error) and a variable number of informational parameters.
If mBgModel 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 table file:
rtn = mBgModel('M17/unknown.tbl', 'M17/fits.tbl', 'work/M17/corrections.tbl')
print(rtn)
mBgModel can also be run as a command-line tool in Linux, OS X, and Windows:
Usage: mBgModel [-i niter] [-l(evel-only)] [-d level] [-a(ll-overlaps)] [-s statusfile] images.tbl fits.tbl corrections.tbl
If you are writing in C/C++, mBgModel can be accessed as a library function:
/*-***********************************************************************/ /* */ /* mBModel */ /* */ /* Given a set of image overlap difference fits (parameters on the */ /* planes fit to pairwise difference images between adjacent images) */ /* interatively determine the 'best' background adjustment for each */ /* image (assuming each image is changed to best match its neighbors */ /* with them remaining unchanged) uses these adjustments to modify */ /* each set of difference parameters, and iterate until the changes */ /* modifications become small enough. */ /* */ /* char *imgfile Reprojected image metadata list */ /* char *fitfile Set of image overlap difference fits */ /* char *corrtbl Output table of corrections for images */ /* in input list */ /* int noslope Only fit levels, not slopes */ /* int useall Use all the input differences (by default */ /* we exclude very small overlap areas) */ /* int niteration Number of iterations to run */ /* int debug Debugging output level */ /* */ /*************************************************************************/ struct mBgModelReturn *mBgModel(char *imgfile, char *fitfile, char *corrtbl, int noslope, int useall, int niter, int debug)
Return Structure
struct mBgModelReturn { int status; // Return status (0: OK, 1:ERROR) char msg [1024]; // Return message (for error return) char json[4096]; // Return parameters as JSON string };