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: mShrink

mShrink allows us to shrink (or expand) an image by an arbitrary factor. Often used in conjuction with visualization, shrinking images is also useful when making mosaics of very large areas at reduced visualization as the shrinking process is much faster than than reprojection and shrinking first saves time.

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

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

mShrink(...)
    mShrink is a utility program for making smaller versions of a FITS file by averaging NxN blocks of pixels spatially.  N can be fractional.
    
    Parameters
    ----------
    infile : str
        Input FITS file.
    output_file : str
        Subimage output FITS file.
    shrinkFactor : float
        Scale factor for spatial shrinking.  Can be any positive real number.
    hdu : int, optional
        Optional HDU offset for input file.
    fixedSize : bool, optional
        Alternate mode: shrink so the output fits in this many pixels.
    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).

mShrink Example

The principle parameters for mShrink are the input and output files and the scale factor. If the 'fixedSize' parameter is set, the shrinkFactor parameter instead represents the full output size in pixels.

In [2]:
rtn = mShrink('M17/mosaic.fits', 'work/M17/mosaic_small.fits', 3.5)

print(rtn)
{'status': '0', 'time': 1.0}

Before and After

The original image and the 3.5x shrunken one:

In [4]:
from IPython.display import Image, display, HTML

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

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

display(HTML("<table><tr><td><img src='work/mosaic_shrink.png'></td> \
                         <td><img src='work/mosaic_small.png'></td></tr></table>"))

 

Error Handling

If mShrink 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 [5]:
rtn = mShrink('M17/unknown.fits', 'work/M17/mosaic_small.fits', 3.5)

print(rtn)
{'status': '1', 'msg': b'Image file M17/unknown.fits missing or invalid FITS'}

 

Using Montage Standalone

mShrink Unix/Windows Command-line Arguments

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

Usage: mShrink [-f(ixed-size)] [-d level] [-h hdu] [-s statusfile] in.fits out.fits factor

 

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

/*-***********************************************************************/
/*                                                                       */
/*  mShrink                                                              */
/*                                                                       */
/*  Montage is a set of general reprojection / coordinate-transform /    */
/*  mosaicking programs.  Any number of input images can be merged into  */
/*  an output FITS file.                                                 */
/*                                                                       */
/*  This module, mShrink, is a utility program for making smaller        */
/*  versions of a FITS file by averaging NxN blocks of pixels.           */
/*                                                                       */
/*   char  *infile         Input FITS file                               */
/*   char  *output_file    Shrunken output FITS file                     */
/*                                                                       */
/*   double shrinkFactor   Scale factor for spatial shrinking.  Can be   */
/*                         any positive real number                      */
/*                                                                       */
/*   int    hdu            Optional HDU offset for input file            */
/*   int    fixedSize      Alternate mode: shrink so the output fits     */
/*                         in this many pixels                           */
/*                                                                       */
/*   int    debug          Debugging output level                        */
/*                                                                       */
/*************************************************************************/

struct mShrinkReturn *mShrink(char *input_file, char *output_file, double shrinkFactor, int hduin, int fixedSize, int debug)

Return Structure

struct mShrinkReturn
{
   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)   
};