M

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.

MontagePy.main modules: mDiff

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, mDiffi, which computes the difference between two images.

Visit Building a Mosaic with Montage to see how mDiff 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.

In [1]:
from MontagePy.main import mDiff, mViewer

help(mDiff)
Help on built-in function mDiff in module MontagePy.main:

mDiff(...)
    mDiff subtracts one image from another (both already in the same projection).
    
    Parameters
    ----------
    input_file1 : str
        First input file for differencing.
    input_file2 : str
        Second input file for differencing.  Files have to already have the same projection.
    output_file : str
        Output difference image.
    template_file : str
        FITS header file used to define the desired output.
    noAreas : bool, optional
        Do not look for or create area images as part of the differencing.
    factor : float, optional
        Optional scale factor to apply to the second image before subtracting.
    debug : int, optional
        Debugging output level.
    
    
    Returns
    -------
    status : int
        Return status (0: OK, 1:ERROR).
    msg : str
        Return message (for errors).
    time : float
        Total processing time (sec).
    min_pixel : float
        Smallest pixel value in either input.
    max_pixel : float
        Largest pixel value in either input.
    min_diff : float
        Smallest difference pixel (absolute).
    max_diff : float
        Largest difference pixel (absolute).

mDiff Example

Here, two Spitzer Space Telescope IRAC images have been tranformed to a common projection (using mProject). They have similar but not identical sky coverage and originally had slightly different rotations.

mDiff gives us the difference image of the above two. In Montage, this difference is primarily used to determine background offsets by fitting the difference with a plane. Below we stretch the difference to show the noise level and illustrate any residual effects of sky structure. Most noticeble are the bright stars in the lower left and the brightest areas in the galaxies, particularly the center of M51b. However, these are not much brighter than the noise and instrumental data collection effects, so fitting the difference with a plane (mFitplane) gives an reasonable measure of the image background difference, especially if the larger excursions from the plane are excluded in the fit.

In [2]:
rtn = mDiff('IRAC/projected/hdu0_SPITZER_I2_5504000_0000_6_E8758134_maic.fits', 
            'IRAC/projected/hdu0_SPITZER_I2_5504256_0000_6_E8757228_maic.fits',
            'work/IRAC/irac_diff.fits',
            'IRAC/M51.hdr',
             noAreas=True)
print(rtn)
{'status': '0', 'time': 1.0, 'min_pixel': -0.33841609954833984, 'max_pixel': 269.2658386230469, 'min_diff': 1.4901161193847656e-08, 'max_diff': 142.27021026611328}

  The difference image looks like this:

In [3]:
from IPython.display import Image

rtn = mViewer("-ct 1 -gray work/IRAC/irac_diff.fits \
               -2s max gaussian-log -out work/IRAC/irac_diff.png",
              "", mode=2)

Image(filename='work/IRAC/irac_diff.png')
Out[3]:

 

mDiff Error Handling

If mDiff 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:

In [4]:
rtn = mDiff('IRAC/projected/unknown.fits', 
            'IRAC/projected/hdu0_SPITZER_I2_5504256_0000_6_E8757228_maic.fits',
            'work/IRAC/irac_diff.fits',
            'IRAC/M51.hdr',
             noAreas=True)
print(rtn)
{'status': '1', 'msg': b'Image file IRAC/projected/unknown.fits missing or invalid FITS'}

 

Classic Montage: mDiff as a Stand-Alone Program

mDiff Unix/Windows Command-line Arguments

mDiff can also be run as a command-line tool in Linux, OS X, and Windows:

Usage: mDiff [-d level] [-n(o-areas)] [-z factor] [-s statusfile] in1.fits in2.fits out.fits hdr.template

 

If you are writing in C/C++, mDiff can be accessed as a library function:

/*-***********************************************************************/
/*                                                                       */
/*  mDiff                                                                */
/*                                                                       */
/*  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, mDiff, is used as part of a background                  */
/*  correction mechanism.  Pairwise, images that overlap are differenced */
/*  and the difference images fit with a surface (usually a plane).      */
/*  These planes are analyzed, and a correction determined for each      */
/*  input image (by mBgModel).                                           */
/*                                                                       */
/*   char  *input_file1    First input file for differencing             */
/*   char  *input_file2    Second input file for differencing. Files     */
/*                         have to already have the same projection      */
/*                                                                       */
/*   char  *output_file    Output difference image                       */
/*                                                                       */
/*   char  *template_file  FITS header file used to define the desired   */
/*                         output region                                 */
/*                                                                       */
/*   int    noAreas        Do not look for or create area images as part */
/*                         of the differencing                           */
/*                                                                       */
/*   double factor         Optional scale factor to apply to the second  */
/*                         image before subtracting                      */
/*                                                                       */
/*   int    debug          Debugging output level                        */
/*                                                                       */
/*                                                                       */
/*************************************************************************/

struct mDiffReturn *mDiff(char *input_file1, char *input_file2, char *ofile, char *template_file, 
                          int noAreasin, double fact, int debugin)

Return Structure

struct mDiffReturn
{
   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)   
   double min_pixel;     // Minimum pixel value in either input (absolute)
   double max_pixel;     // Maximum pixel value in either input (absolute)
   double min_diff;      // Minimum pixel value in difference
   double max_diff;      // Maximum pixel value in difference
};