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

The Montage toolkit is primarily involved in reprojecting, background matching, and mosaicking astronomical images but it also has fairly sophisticated tools for image display (PNG/JPEG generation). This notebook entry shows the basics of using mViewer to create a full-color image from three wavelength bands that have already been reprojected and mosaicked.

In this example, we will focus on the image data but mViewer can also build visualizations where the image data is secondary or invisible.

In [1]:
from MontagePy.main import mViewer

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

mViewer(...)
    mViewer generates a JPEG image file with overlays from a FITS file (or a set of three FITS files in color).
    
    Parameters
    ----------
    cmdstr : str
        The command string (arguments or JSON).
    outFile : str
        Output PNG/JPEG.
    mode : int, optional
        Type of the command string: Type of the command string: 0 for JSON file, 1 for JSON, 2 for 'command' string.
    outFmt : str, optional
        'png' or 'jpeg'.
    fontFile : str, optional
        Font file for labeling (overrides default)
    debug : int, optional
        Debugging flag.
    
    
    Returns
    -------
    status : int
        Return status (0: OK, 1:ERROR).
    msg : str
        Return message (for errors).
    type : str
        'grayscale' or 'color'.
    nx : int
        Output image width.
    ny : int
        Output image height.
    grayminval : float
        Gray file: Minimum stretch data value.
    grayminpercent : float
        Gray file: Histogram percentile level for min stretch value.
    grayminsigma : float
        Gray file: 'Sigma' level for min stretch value.
    graymaxval : float
        Gray file: Maximum stretch data value.
    graymaxpercent : float
        Gray file: Histogram percentile level for max stretch value.
    graymaxsigma : float
        Gray file: 'Sigma' level for max stretch value.
    blueminval : float
        Blue file: Minimum stretch data value.
    blueminpercent : float
        Blue file: Histogram percentile level for min stretch value.
    blueminsigma : float
        Blue file: 'Sigma' level for min stretch value.
    bluemaxval : float
        Blue file: Maximum stretch data value.
    bluemaxpercent : float
        Blue file: Histogram percentile level for max stretch value.
    bluemaxsigma : float
        Blue file: 'Sigma' level for max stretch value.
    greenminval : float
        Green file: Minimum stretch data value.
    greenminpercent : float
        Green file: Histogram percentile level for min stretch value.
    greenminsigma : float
        Green file: 'Sigma' level for min stretch value.
    greenmaxval : float
        Green file: Maximum stretch data value.
    greenmaxpercent : float
        Green file: Histogram percentile level for max stretch value.
    greenmaxsigma : float
        Green file: 'Sigma' level for max stretch value.
    redminval : float
        Red file: Minimum stretch data value.
    redminpercent : float
        Red file: Histogram percentile level for min stretch value.
    redminsigma : float
        Red file: 'Sigma' level for min stretch value.
    redmaxval : float
        Red file: Maximum stretch data value.
    redmaxpercent : float
        Red file: Histogram percentile level for max stretch value.
    redmaxsigma : float
        Red file: 'Sigma' level for max stretch value.
    graydatamin : float
        Gray file: Minimum data value in file.
    graydatamax : float
        Gray file: Maximum data value in file.
    bdatamin : float
        Blue file: Minimum data value in file.
    bdatamax : float
        Blue file: Maximum data value in file.
    gdatamin : float
        Green file: Minimum data value in file.
    gdatamax : float
        Green file: Maximum data value in file.
    rdatamin : float
        Red file: Minimum data value in file.
    rdatamax : float
        Red file: Maximum data value in file.
    flipX : int
        1 if X axis was flipped (to better represent the sky).
    flipY : int
        1 if Y axis was flipped.
    colortable : int
        Grayscale color table used.
    bunit : str
        Data units from FITS header (assumed the same for color images).

Example

The number of arguments to mViewer is a little large for a standard keyword list so we use a couple of structured strings for control. For simple plots we have a brief syntax that is modeled on the stand-alone command line (see below). We'll show an example of that later. For more involved plots we use JSON.

Here we create the JSON as a simple string (note the triple quotes which let us make thisa multi-line with embedded quotes, etc.).

In [2]:
imgjson = """
{
   "image_type":"png",
   "true_color":1.50,
   "font_scale":1.1,

   "blue_file":
   {
      "fits_file":"SDSS/SDSS_u.fits",
      "stretch_min":"-0.1s",
      "stretch_max":"max",
      "stretch_mode":"gaussian-log"
   },

   "green_file":
   {
      "fits_file":"SDSS/SDSS_g.fits",
      "stretch_min":"-0.1s",
      "stretch_max":"max",
      "stretch_mode":"gaussian-log"
   },

   "red_file":
   {
      "fits_file":"SDSS/SDSS_r.fits",
      "stretch_min":"-0.1s",
      "stretch_max":"max",
      "stretch_mode":"gaussian-log"
   },

   "overlays":
   [
      {
         "type":"grid",
         "coord_sys":"Equ J2000",
         "color":"8080ff"
      },
      {
         "type":"imginfo",
         "data_file":"SDSS/irspeakup.tbl",
         "coord_sys":"Equ J2000",
         "color":"ff9090"
      },
      {
         "type":"catalog",
         "data_file":"SDSS/fp_2mass.tbl",
         "data_column":"j_m",
         "data_ref":16,
         "data_type":"mag",
         "symbol":"circle",
         "sym_size":1.0,
         "coord_sys":"Equ J2000",
         "color":"ffff00"
      }
   ]
}
"""

This defines a full-color image made with three Sloan Digital Sky Survey (SDSS) mosaics made from archive data, each with its own stretch, plus three overlays (a coordinate grid, the 2MASS catalog, and image metadata from the Spitzer Space Telescope).

There are additional controls for other overlays. See http://montage.ipac.caltech.edu/mViewer for details.

With this, it is simple to run mViewer:

In [4]:
rtn = mViewer(imgjson, 'work/SDSS/SDSS.png', mode=1)

print(rtn)
{'status': '0', 'type': b'color', 'nx': 1200, 'ny': 1200, 'grayminval': 0.0, 'grayminpercent': 0.0, 'grayminsigma': 0.0, 'graymaxval': 0.0, 'graymaxpercent': 0.0, 'graymaxsigma': 0.0, 'blueminval': 1660.948886289596, 'blueminpercent': 45.51304816901208, 'blueminsigma': -0.10000000000002897, 'bluemaxval': 18833.51097929482, 'bluemaxpercent': 100.0, 'bluemaxsigma': 7293.270993655378, 'greenminval': 612.1976698225872, 'greenminpercent': 43.049856485589686, 'greenminsigma': -0.1000000000000262, 'greenmaxval': 26276.085778495264, 'greenmaxpercent': 100.0, 'greenmaxsigma': 14790.776567073211, 'redminval': 896.9336930051037, 'redminpercent': 42.62543763181061, 'redminsigma': -0.10000000000000908, 'redmaxval': 20567.63987893109, 'redmaxpercent': 100.0, 'redmaxsigma': 6285.599891788824, 'graydatamin': 0.0, 'graydatamax': 0.0, 'bdatamin': 1650.1333317872777, 'bdatamax': 18833.51097929482, 'gdatamin': 608.5073366952034, 'gdatamax': 26276.085778495264, 'rdatamin': 890.1481250441316, 'rdatamax': 20567.63987893109, 'flipX': 0, 'flipY': 1, 'colortable': 0, 'bunit': b''}

The return contains details of the individual image stretching, image size, and so on.

Here is the output image:

In [5]:
from IPython.display import Image

Image(filename='work/SDSS/SDSS.png')
Out[5]: