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, mFitplane, which fits a plane to an image (most often an overlap difference but sometimes for background removal).
Visit Building a Mosaic with Montage to see how mFitplane 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 mFitplane, mBackground, mViewer
help(mFitplane)
mFitplane least-squares fits a plane to an image. It iterates a little to exclude the larger excursions (i.e., bright stars, dropouts). The results (a plane) can be used either directly to subtract a background from an image or, with fits to a set of difference images, to model a global set of background corrections to minimize differences.
rtn = mFitplane('M17/raw/2mass-atlas-990502s-j1430080.fits')
print(rtn)
There is no side effect; all of the output is in the above return structure.
from IPython.display import HTML, display
mBackground('M17/raw/2mass-atlas-990502s-j1430080.fits',
'work/M17/2mass-atlas-990502s-j1430080_fitplane.fits',
-0.00016525931270827687,
0.002731437131331532,
152.3555451225345,
noAreas=True)
mViewer('-ct 1 -gray M17/raw/2mass-atlas-990502s-j1430080.fits \
min max gaussian-log -out work/M17/2mass-atlas-990502s-j1430080.png',
'', mode=2)
rtn = mViewer('-ct 1 -gray work/M17/2mass-atlas-990502s-j1430080_fitplane.fits \
min max gaussian-log -out work/M17/2mass-atlas-990502s-j1430080_fitplane.png',
'', mode=2)
display(HTML("<table><tr><td><img src='work/M17/2mass-atlas-990502s-j1430080.png'></td> \
<td><img src='work/M17/2mass-atlas-990502s-j1430080_fitplane.png'></td></tr></table>"))
The difference is subtle, as is not surprising. The image on the left is somewhat darker at the top than it is at the bottom whereas the one on the right is more uniform in its background from top to bottom.
If mFitplane 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 an image that doesn't exist:
rtn = mFitplane('M17/raw/unknown.fits')
print(rtn)
mFitplane can also be run as a command-line tool in Linux, OS X, and Windows:
Usage: mFitplane [-b border] [-d level] [-s statusfile] [-l(evel-only)] in.fits
If you are writing in C/C++, mFitplane can be accessed as a library function:
/*-***********************************************************************/ /* */ /* mFitplane */ /* */ /* 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, mFitplane, is used in conjuction with mDiff and */ /* mBgModel to determine how overlapping images relate to each */ /* other. It is assumed that difference images have matching structure */ /* information and that what is left when you difference them is just */ /* the relative offsets, slopes, etc. By fitting the difference image, */ /* we obtain the 'correction' that needs to be applied to one or the */ /* other (or in part to both) to bring them together. */ /* */ /* char *input_file FITS file for plane fitting */ /* int levelOnly Only fit for level difference not a full */ /* plane with slopes */ /* int border Exclude a pixel border from the fitting */ /* int debug Debugging output level */ /* */ /*************************************************************************/ struct mFitplaneReturn *mFitplane(char *input_file, int levelOnly, int border, int debug)
Return Structure
struct mFitplaneReturn { 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 a; // Plane fit coefficient for X axis. double b; // Plane fit coefficient for Y axis. double c; // Plane fit constant offset. double crpix1; // X-axis pixel coordinate for center of region. double crpix2; // Y-axis pixel coordinate for center of region. double xmin; // Minimum X-axis value. double xmax; // Maximum X-axis value. double ymin; // Minimum Y-axis value. double ymax; // Maximum Y-axis value. double xcenter; // Center X location. double ycenter; // Center Y location. int npixel; // Total number of pixels fit. double rms; // RMS of fit (pixels with large offset values were excluded in fit). double boxx; // Rectanguar bounding box X center. double boxy; // Rectanguar bounding box Y center. double boxwidth; // Rectanguar bounding box width. double boxheight; // Rectanguar bounding box height. double boxang; // Rectanguar bounding box rotation angle. };