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, mDiffFitExec, which differences and fits a set of image pairs (image overlaps).
Visit Building a Mosaic with Montage to see how mDiffFitExec 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 mDiffFitExec, mViewer
help(mDiffFitExec)
mDiffFitExec is a general utility for generating and fitting a set of image differences. It's most common use is as part of the process of evaluating overlap area in a set of images as part of background rectification. That process consists of taking the output of the overlaps calculation (mOverlaps) and for each overlap pair doing the difference (mDiff), fitting it to determine offset between those two images (mFitplane).
There are two ways to do this in bulk. We can either generate all the differences first, then fit them all or we can loop over the differences, generating and fitting that difference before moving on to the next. This first approach uses more disks space as all the differences have to be stored in between steps. The second can clean up as it goes.
Obviously the second approach is preferable unless you want to keep the differences (possibly for quality evaluation).
mDiffFitExec is an instantiation of the second approach. It runs mDiff on every pair in the input list and then fits it with a plane.
At this point in the processing, we already have a set of "like" images (same projection), and have made a list of all the overlaps (normally using mOverlaps). mDiffFitExec loops over these differences, generating each difference (in a working directory) and fitting a plane to it.
mDiffFitExec cleans up the working files as it goes.
rtn = mDiffFitExec('M17/projected',
'M17/diffs.tbl',
'M17/M17.hdr',
'M17/diffs',
'work/M17/fits.tbl')
print(rtn)
The output is a set of planes representing the difference between two original images. This set will be sent to mBgModel for modelling into a set of corrections to the original images to bring the backgrounds in line.
import numpy as np
import pandas as pd
from astropy.io import ascii
ipactable = ascii.read('work/M17/fits.tbl').to_pandas()
ipactable
If mDiffFitExec 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 = mDiffFitExec('M17/projected',
'M17/unknown.tbl',
'M17/M17.hdr',
'M17/diffs',
'work/M17/fits.tbl')
print(rtn)
mDiffFitExec can also be run as a command-line tool in Linux, OS X, and Windows:
Usage: mDiffFitExec [-d] [-l(evel-only)] [-n(o-areas)] [-p projdir] [-s statusfile] diffs.tbl template.hdr diffdir fits.tbl
If you are writing in C/C++, mDiffFitExec can be accessed as a library function:
/*-*****************************************************************/ /* */ /* mDiffFitExec */ /* */ /* This routine combines the mDiff and mFit functionality and */ /* optionally discards the difference images as it goes (to */ /* minimize the file space needed). It uses the table of */ /* oerlaps found by mOverlaps, running mDiff, then mFitplane */ /* on the difference images. These fits are written to an */ /* output file which is then used by mBgModel. */ /* */ /* char *path Path to images to be diffed. */ /* char *tblfile Table file list of images to diff. */ /* char *template FITS header file used to define the desired */ /* output. */ /* */ /* char *diffdir Directory for temporary output diff files. */ /* char *fitfile Table file for output difference fits info. */ /* int keepAll Flag to keep temporary diff images. */ /* int levelOnly Flag to fit level of diff only, not slopes. */ /* int noAreas Flag indicating there are no area images. */ /* int debug Debug flag. */ /* */ /*******************************************************************/ struct mDiffFitExecReturn *mDiffFitExec(char *path, char *tblfile, char *template, char *diffdir, char *fitfile, int keepAll, int levelOnly, int noAreas, int debugin)
Return Structure
struct mDiffFitExecReturn { 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 differences int diff_failed; // Number of differences that failed int fit_failed; // Number of fits to differences that failed int warning; // Number of fits to differences that produced warnings };