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, mProjectQL, which is one of the modules used to reproject images.
Visit Building a Mosaic with Montage to see how mProjectQL 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 mProjectQL, mViewer
help(mProjectQL)
mProjectQL is one of four modules focused on the task of reprojecting an astronomical image. It is by far the fastest of the reprojection options but is not strictly flux conserving (the "QL" stands for "quick look"). The algorithm does not calculate exact pixel overlaps but instead is base on the reprojected locatons of a set of sample points within each pixel.
In spite of this, the algorithm produces output that is usually more than adequate for science analysis, with fluxes indistinguishable from mProject or mProjectPP. It is usually best to start with mProjectQL and analyze the result to determine whether it is accurate enough for your needs.
mProjectQL has a number of extra controls for things like excluding a border (image borders often have bad pixels). But the basic inputs are a FITS image and a FITS header describing the output image we want. In all cases, the only output is a FITS image with the data from the input resampled to the output header pixel space.
The input FITS header (actually an ASCII file that looks like a FITS header but with newlines and unpadded line lengths) can be produced in a number of ways. There are Montage tools to take an image list (or point source list) and determine a bounding box (mMakeHdr) or just a location and size (mHdr). You can also pull the header off another file (mGetHdr) if you want to build a matching mosaic from other data. Or you can just create the output header by hand (e.g., a simple all-sky Aitoff projection).
Here we have pulled the header from the input image and edited it by hand to modify the rotation by 30 degrees.
rtn = mProjectQL('M17/raw/2mass-atlas-990502s-j1340186.fits',
'work/M17/2mass-atlas-990502s-j1340186_projectQL.fits',
'M17/rotated.hdr')
print(rtn)
Here are the original image and the reprojected one:
from IPython.display import Image
rtn = mViewer("-ct 1 -gray M17/raw/2mass-atlas-990502s-j1340186.fits \
-2s max gaussian-log -out work/M17/2mass-atlas-990502s-j1340186.png",
"", mode=2)
print(rtn)
Image(filename='work/M17/2mass-atlas-990502s-j1340186.png')
rtn = mViewer("-ct 1 -gray work/M17/2mass-atlas-990502s-j1340186_project.fits \
-2s max gaussian-log -out work/M17/2mass-atlas-990502s-j1340186_projectQL.png",
"", mode=2)
print(rtn)
Image(filename='work/M17/2mass-atlas-990502s-j1340186_projectQL.png')
If mProjectQL 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 image that doesn't exist:
rtn = mProjectQL('M17/raw/unknown.fits',
'work/M17/2mass-atlas-990502s-j1340186_project.fits',
'M17/rotated.hdr')
print(rtn)
mProjectQL can also be run as a command-line tool in Linux, OS X, and Windows:
Usage: mProjectQL [-d level][-s statusfile][-h hdu][-x scale][-w weightfile][-W fixed-weight][-t threshold][-X(expand)][-b border-string][-f(ull-region)] in.fits out.fits hdr.template
If you are writing in C/C++ on Linux or OSX, mProjectQL can be accessed as a library function:
/*-***********************************************************************/ /* */ /* mProjectQL */ /* */ /* Montage is a set of general reprojection / coordinate-transform / */ /* mosaicking programs. Any number of input images can be merged into */ /* an output FITS file. The attributes of the input are read from the */ /* input files; the attributes of the output are read a combination of */ /* the command line and a FITS header template file. */ /* */ /* This module, mProject, processes a single input image and */ /* projects it onto the output space. Other Montage modules do this */ /* with full flux-conserving accuracy but pay the price in speed. */ /* This module produces a quick approximation which is nevertheless */ /* adquate even for some science applications. */ /* */ /* Each output pixel is project to the input pixel space and its value */ /* approximated based on surrounding input pixels via interpolation. */ /* Unlike the other modules, no area file is generated since no */ /* overlap areas are determined. When coadding overlapping images */ /* later, this will effect the accuracy of edge pixels but this cannot */ /* be helped. */ /* */ /* The input can come from from arbitrarily disparate sources. It is */ /* assumed that the flux scales in the input images match, but this is */ /* not required (leading to some interesting combinations). */ /* */ /* char *input_file FITS file to reproject */ /* char *output_file Reprojected FITS file */ /* char *template_file FITS header file used to define the desired */ /* output */ /* */ /* int hdu Optional HDU offset for input file */ /* int interp Interpolation scheme for value lookup. */ /* Currently NEAREST of LANCZOS. */ /* */ /* char *weight_file Optional pixel weight FITS file (must match */ /* input) */ /* */ /* double fixedWeight A weight value used for all pixels */ /* double threshold Pixels with values below this level treated */ /* as blank */ /* */ /* char *borderstr Optional string that contains either a border */ /* width or comma-separated 'x1,y1,x2,y2, ...' */ /* pairs defining a pixel region polygon where */ /* we keep only the data inside. */ /* */ /* double fluxScale Scale factor applied to all pixels */ /* */ /* int expand Expand output image area to include all of */ /* the input pixels */ /* */ /* int fullRegion Do not 'shrink-wrap' output area to non-blank */ /* int noAreas In the interest of speed, generation of area */ /* images is turned off. This turns it back on. */ /* pixels */ /* */ /* int debug Debugging output level */ /* */ /*************************************************************************/ struct mProjectQLReturn *mProjectQL(char *input_file, char *ofile, char *template_file, int hduin, int interp, char *weight_file, double fixedWeight, double threshold, char *borderstr, double fluxScale, int expand, int fullRegion, int noAreas, int debugin)
Return Structure
struct mProjectQLReturn { int status; // Return status (0: OK, 1:ERROR) char msg [1024]; // Return message (for error return) char json[4096]; // Return parameters as JSON string double time; // Run time (sec) };