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, mOverlaps, which is used to determine the set of overlap areas for a collection of images.
Visit Building a Mosaic with Montage to see how mOverlaps 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 mOverlaps, mViewer
help(mOverlaps)
In a test region near M17 we have 48 J-band images. Here we use mOverlaps to determine which of these overlap and by how much.
rtn = mOverlaps("M17/pimages.tbl", "work/M17/diffs.tbl")
print(rtn)
Here is the output
import os
import numpy as np
import pandas as pd
from astropy.io import ascii
ipactable = ascii.read('work/M17/diffs.tbl').to_pandas()
ipactable
and here is a coverage map illustrating the overlaps:
from IPython.display import Image
rtn = mViewer("-color black -imginfo M17/pimages.tbl \
-ct 1 -gray M17/mosaic.fits -2s max gaussian-log \
-out work/M17/mosaic.png",
"", mode=2)
Image(filename='work/M17/mosaic.png')
If mDiff 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 specifies a table that doesn't exist:
rtn = mOverlaps("M17/unknown.tbl", "work/M17/diffs.tbl")
print(rtn)
mOverlaps can also be run as a command-line tool in Linux, OS X, and Windows:
Usage: mOverlaps [-e] [-d level] [-s statusfile] images.tbl diffs.tbl
If you are writing in C/C++, mOverlaps can be accessed as a library function:
/*-***********************************************************************/ /* */ /* mOverlaps */ /* */ /* Given a list of images, determines which ones overlap. This program */ /* assumes that the images are relatively small (i.e. not all-sky) and */ /* determines if there is overlap by going around the outside of each */ /* to see if any of the edge pixels are inside the other. */ /* */ /* char *tblfile Image metadata file */ /* char *difftbl Output table of overlap areas */ /* */ /* int quickmode Use faster but fairly accurate overlap check */ /* rather than full geometry calculation */ /* */ /* int debug Debugging output level */ /* */ /*************************************************************************/ struct mOverlapsReturn *mOverlaps(char *tblfile, char *difftbl, int quickmode, int debug)
Return Structure
struct mOverlapsReturn { 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 overlaps. };