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, mFitExec, which fits planes to a set of images (most often overlap differences).
Visit Building a Mosaic with Montage to see how mFitExec 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 mFitExec, mViewer
help(mFitExec)
mFitExec is a general utility for fitting a set of image differences with a plane. It's most common use is in 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).
mFitExec is part of the first approach. It runs mFitplane on difference file from the input list and stores the result in a table. This table will usually be handed to mBgModel to determine what corrections to make to each image to minimize background differences.
At this point in the processing, we already have a set of "like" images (same projection), have made a list of all the overlaps (normally using mOverlaps) and generated difference images. mFitExec loops over these images and fits a plane to each one.
rtn = mFitExec('M17/diffs.tbl',
'work/M17/fits.tbl',
'M17/diffs')
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 os
import numpy as np
import pandas as pd
from astropy.io import ascii
ipactable = ascii.read('work/M17/fits.tbl').to_pandas()
ipactable
If mFitExec 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 = mFitExec('M17/unknown.tbl',
'work/M17/fits.tbl',
'M17/diffs')
print(rtn)
mFitExec can also be run as a command-line tool in Linux, OS X, and Windows:
Usage: mFitExec [-d] [-l(evel-only)] [-s statusfile] diffs.tbl fits.tbl diffdir
If you are writing in C/C++, mFitExec can be accessed as a library function:
/*-*****************************************************************/ /* */ /* mFitExec */ /* */ /* After mDiffExec has been run using the table of overlaps found */ /* by mOverlaps, use this executive to run mFitplane on each of */ /* the differences. Write the fits to a file to be used by */ /* mBModel. */ /* */ /* char *tblfile Table file list of images to fit. */ /* char *fitfile Table file for output difference fits info. */ /* char *diffdir Directory for temporary output diff files. */ /* int levelOnly Flag to fit level of diff only, not slopes. */ /* int debug Debug flag. */ /* */ /*******************************************************************/ struct mFitExecReturn *mFitExec(char *tblfile, char *fitfile, char *diffdir, int levelOnly, int debugin)
Return Structure
struct mFitExecReturn { 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 failed; // Number of fits to differences that failed int warning; // Number of fits to differences that produced warnings int missing; // Number of missing difference images };