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

There are a few situations where you may need to create an image:

  • A blank image to be used as a drawing surface for overlays (catalog symbols, coordinate grid, etc.
  • An image for a wavelength where we don't have image data, generated from a catalog. This might be used, for instance, in making a color composite with other wavelengths.
  • A coverage map or mask made from image metadata.

And there are bound to be others.

mMakeImg can produce all of the above. The input is an image header template and a collection of datasets with controls on how they are to be rendered: image background (level, slope and noise); catalog source data (scaled by magnitude, either gaussian PSF or uniform disk) or image metadata (filled boxes). There is even a mechanism for creating a true image from a raw file of pixel values.

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

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

mMakeImg(...)
    mMakeImg creates FITS images using synthetic data (sloping background, catalogs, coverage info, etc.
    
    Parameters
    ----------
    template_file : str
        Header template describing the image (and to be part of it).
    output_file : str
        Output FITS file.
    layout : str, optional
        JSON structure alternative input to all parameters below.
    mode : int, optional
        0: JSON file, 1: JSON, 2: command string.
    debug : int, optional
        Debugging output level.
    
    
    Returns
    -------
    status : int
        Return status (0: OK, 1:ERROR).
    msg : str
        Return message (for errors).
    srccnt : int
        Number of catalog sources included.
    imgcnt : int
        Number of image regions included.

Example

The number of arguments to mMakeImg is a little large for a standard keyword list so we also be using a JSON rendering of the parameters as the driver. This could be in the form of a file but we will use a JSON string.

Here we create the JSON as a simple string (note the triple quotes which let us make this a multi-line with embedded quotes, etc.) Since this is an active notebook, you can modify this as you like to adjust the final image.

In [2]:
imgjson = """
{ 
   "background": 
   { 
      "noise" : 0.001, 
      "bg11"  : 0.0, 
      "bg1N"  : 0.0, 
      "bgNN"  : 0.0, 
      "bgN1"  : 0.0 
   }, 
 
   "datasets": 
   [ 
      { 
         "type"   : "catalog", 
         "file"   : "SDSS/fp_2mass.tbl", 
         "column" : "j_m", 
         "width"  :  5.0, 
         "csys"   : "Equ J2000", 
         "refval" :  16.0, 
         "mode"   : "mag", 
         "shape"  : "gaussian" 
      }, 
      { 
         "type"   : "imginfo", 
         "file"   : "SDSS/irsmap.tbl", 
         "refval" :  0.2 
      } 
   ] 
}
"""

All of the input options are handled by the above JSON, so the arguments to the call are just that JSON structure and the name of the new output image file:

In [3]:
rtn = mMakeImg('SDSS/SDSS.hdr', 'work/mMakeImg.fits', mode=1, layout=imgjson)

print(rtn)
{'status': '0', 'srccnt': 290, 'imgcnt': 3138}

Here is the resultant image. You wouldn't normally mix all these kinds of data in one place; the catalog simulated image and the image metadata coverage density are usually generated for different purposes.

In [4]:
from IPython.display import Image

mViewer("-ct 1 -gray work/mMakeImg.fits -2s max gaussian-log", 
        "work/mMakeImg.png",
         mode=2)

Image(filename='work/mMakeImg.png')
Out[4]:

 

Error Handling

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 header that doesn't exist:

In [5]:
rtn = mMakeImg('SDSS/unknown.hdr', 'work/mMakeImg.fits', mode=1, layout=imgjson)

print(rtn)
{'status': '1', 'msg': b'Template file [SDSS/unknown.hdr] not found.'}

 

Classic Montage: mMakeImg as a Stand-Alone Program

mMakeImg Unix/Windows Command-line Arguments

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

Usage: mMakeImg [-d level] [-r(eplace)] [-n noise_level] [-b bg1 bg2 bg3 bg4] [-t tbl col width epoch refmag] [-f(lat-sources)] [-i imagetbl] [-a array.txt] template.hdr out.fits (-t args can be repeated)

 

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

/*-****************************************************************************************/
/*                                                                                        */
/*  mMakeImg -- A point source image generation program                                   */
/*                                                                                        */
/*  A general output FITS image is defined and its pixels are then populated from a table */
/*  of point sources.  The source fluxes from the table are distributed based on a        */
/*  source-specific point-spread function.                                                */
/*                                                                                        */
/*   char     *template_file Header template describing the image (and to be part of it). */
/*   char     *output_file   Output FITS file.                                            */
/*                                                                                        */
/*   char     *layout        Command string or JSON string.  If given, overrides all the  */
/*                           parameters below except 'debug' since the JSON covers all    */
/*                           the same parameters. If null or an empty string, we expect   */
/*                           at least some of the below. JSON and parameter mode can't    */
/*                           be mixed.                                                    */
/*                                                                                        */
/*   int       debug         Debugging flag.                                              */
/*                                                                                        */
/*  The parsed command string / JSON contains some subset of the following parameters:    */
/*                                                                                        */
/*   double    noise         Additive noise level.                                        */
/*   double    bg1           Background value for pixel (1,1).                            */
/*   double    bg2           Background value for pixel (NAXIS1, 1).                      */
/*   double    bg3           Background value for pixel (NAXIS1, NAXIS2).                 */
/*   double    bg4           Background value for pixel (1, NAXIS2).                      */
/*                                                                                        */
/*   int       ncat          Table file(s) with coordinates and source magnitudes.        */
/*   char    **cat_file      Table file(s) with coordinates and source magnitudes.        */
/*   char    **colname       Magnitude column in cat_file.                                */
/*   double   *width         'PSF' (gaussian) width for catalog sources.                  */
/*   int      *flat          Use uniform brightness rather than gaussian drop-off.        */
/*   double   *ref           Reference magnitude for scaling catalog sources.             */
/*   int      *ismag         Boolean: Are the reference value and values magnitudes.      */
/*   int      *sys           Coordinate system ID (EQUJ:0, EQUB:1, ECLJ:2, ECLB:3, GAL:4, */
/*                           SGAL:5)                                                      */
/*   double   *epoch         Epoch for coordinates in catalog table.                      */
/*                                                                                        */
/*   int       nimage        Table file(s) with coordinates and source magnitudes.        */
/*   char    **image_file    Image metadata (four corners) tables (region fill).          */
/*   double   *refval        Fill values to use for image areas.                          */
/*                                                                                        */
/*   char     *arrayfile     ASCII file with pixel value array.                           */
/*                                                                                        */
/*   int       replace       Boolean: if true replace pixel values instead of adding      */
/*                           (applies to both catalogs and image lists).                  */
/*                                                                                        */
/******************************************************************************************/

struct mMakeImgReturn  *mMakeImg(char *template_file, char *output_file, char *layout, int mode, int debug)

Return Structure

struct mMakeImgReturn
{
   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    srccnt;        // Number of catalog sources
   int    imgcnt;        // Number of overlay images
};