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, mHdr, which creates an image header template from location and size information.
Visit Building a Mosaic with Montage to see how mHdr 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 mHdr, mViewer
help(mHdr)
Much of the Montage processing keys off a FITS header template. Sometimes these headers are extracted from a reference file (mGetHdr). Sometimes they are generated as a bounding box around a catalog of sources or other images (mMakeHdr) and sometimes there are just created manually with an editor.
mHdr can be used to build a simple (TAN projection) header given a location (coordinates or object name) and size.
To use mHdr with object names you must have a working network connection. Name resolution is done via a remote service. Width and height are in degrees and there are overrides for pixel scale (1 arcsecond by default), coordinate system (Equatorial J2000 by default) and rotation.
rtn = mHdr("M17", 1.0, 1.0, 'work/M17/M17.hdr')
print(rtn)
The output header looks like this:
with open("work/M17/M17.hdr", "r") as file:
for line in file:
print(line, end='')
If mHdr 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 unsupported dataset:
rtn = mHdr("dummy object", 1., 1., "output/bad.hdr")
print(rtn)
mHdr can also be run as a command-line tool in Linux, OS X, and Windows:
Usage: mHdr [-c system] [-e equinox] [-h height(deg)] [-p pixsize(arcsec)] [-r rotation] [-t 2mass-band] object|location width(deg) outfile (object/location must be a single argument string)
If you are writing in C/C++, mHdr can be accessed as a library function:
/*-***********************************************************************/ /* */ /* mHdr -- Create a header template file from location, size, resolution */ /* and rotation inputs. In order to support object name lookup for the */ /* location string argument, this service must have a network connection */ /* available. */ /* */ /* char *locstr A (quoted if necessary) string containing */ /* a coordinate or the name of an object on */ /* the sky */ /* */ /* double width Image width in degrees */ /* double height Image height in degrees */ /* */ /* char *outfile Output FITS header file */ /* */ /* char *csys Coordinate system string (e.g. 'EquJ', */ /* 'Galactic', etc. Fairly forgiving. */ /* */ /* double equinox Coordinate system equinox (e.g. 2000.0) */ /* double resolution Image pixel resolution (in arcsec) */ /* double rotation Image rotation on the sky */ /* */ /* char *band2MASS Optional argument when mosaicking 2MASS, adds */ /* proper MAGZP value */ /* */ /* int debug Debugging output level */ /* */ /*************************************************************************/ struct mHdrReturn *mHdr(char *locstr, double width, double height, char *outfile, char *csys, double equinox, double resolution, double rotation, char *band2MASS, int debug)
Return Structure
struct mHdrReturn { 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 lines in output file. };