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

mExamine is a utility function that allows the user to retrieve information on an image or a region in an image.

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

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

mExamine(...)
    mExamine returns file and optionally region statistics.
    
    Parameters
    ----------
    infile : str
        FITS file to examine.
    areaMode : int, optional
        Examine the image in general (0:NONE) a specific region with radius (1:AREA) or  perform aperture photometry out to a fixed radius (2:APPHOT).
    hdu : int, optional
        Optional HDU offset for input file.
    plane3 : int, optional
        If datacube, the plane index for dimension 3.
    plane4 : int, optional
        If datacube, the plane index for dimension 4.
    ra : float, optional
        RA for region statistics.
    dec : float, optional
        Dec for region statistics.
    radius : float, optional
        Radius for region statistics.
    locinpix : bool, optional
        The coordinates are actually in pixels.
    radinpix : bool, optional
        The radius is actually in pixels.
    debug : int, optional
        Debugging output level.
    
    
    Returns
    -------
    status : int
        Return status (0: OK, 1:ERROR).
    msg : str
        Return message (for errors).
    proj : str
        Image projection.
    csys : str
        Coordinate system.
    equinox : float
        Coordinate system equinox.
    naxis : int
        Number of axes.
    naxis1 : int
        First axis size.
    naxis2 : int
        Second axis size.
    naxis3 : int
        Third axis size (if it exists).
    naxis4 : int
        Fourth axis size (if it exists).
    crval1 : float
        Axis 1 sky reference value.
    crval2 : float
        Axis 2 sky reference value.
    crpix1 : float
        Axis 1 reference pixel.
    crpix2 : float
        Axis 2 reference pixel.
    cdelt1 : float
        Axis 1 pixel scale.
    cdelt2 : float
        Axis 2 pixel scale.
    crota2 : float
        Image rotation on sky.
    lonc : float
        Longitude of the image center.
    latc : float
        Latitude of the image center.
    ximgsize : float
        Axis 1 size on the sky.
    yimgsize : float
        Axis 2 size on the sky.
    rotequ : float
        Rotation of image relative to Equatorial North
    rac : float
        RA of the image center.
    decc : float
        Dec of the image center.
    ra1 : float
        RA of image corner 1
    dec1 : float
        Dec of image corner 1
    ra2 : float
        RA of image corner 2
    dec2 : float
        Dec of image corner 2
    ra3 : float
        RA of image corner 3
    dec3 : float
        Dec of image corner 3
    ra4 : float
        RA of image corner 4
    dec4 : float
        Dec of image corner 4
    radius : float
        Radius of the examine radius (in degrees).
    radpix : float
        Radius of the examine radius (in pixels).
    npixel : int
        Number of pixel in the examine area.
    nnull : int
        Number of null pixels in the examine area.
    aveflux : float
        Average flux.
    rmsflux : float
        RMS flux.
    fluxref : float
        Flux for center (reference) pixel.
    sigmaref : float
        Reference flux in units of RMS.
    xref : float
        Pixel X of reference.
    yref : float
        Pixel Y of reference.
    raref : float
        RA of reference.
    decref : float
        Dec of reference.
    fluxmin : float
        Flux of pixel with minimum value in examine area.
    sigmamin : float
        Min flux in units of RMS.
    xmin : float
        Pixel X of min.
    ymin : float
        Pixel Y of min.
    ramin : float
        RA of min pixel.
    decmin : float
        Dec of min pixel.
    fluxmax : float
        Flux of pixel with maximum value in examine area.
    sigmamax : float
        Max flux in units of RMS
    xmax : float
        Pixel X of max.
    ymax : float
        Pixel Y of max.
    ramax : float
        RA of max pixel.
    decmax : float
        Dec of m.n pixel.
    totalflux : float
        Aperture phtometry total flux.

Examples

The first example returns basic statistics on a whole image:

In [2]:
rtn = mExamine("M17/raw/2mass-atlas-990502s-j1340186.fits")

import pprint as pp
pp.pprint(rtn)
{'aveflux': 156.5580119941425,
 'cdelt1': -0.0002777777845,
 'cdelt2': 0.0002777777845,
 'crota2': 0.004616579845,
 'crpix1': 256.5,
 'crpix2': 512.5,
 'crval1': 274.8749176,
 'crval2': -16.03334721,
 'csys': b'EQUJ',
 'dec1': -16.175828813608888,
 'dec2': -16.175840403064864,
 'dec3': -15.891117891843425,
 'dec4': -15.891106318926342,
 'decc': -16.033347210000002,
 'decmax': -16.089586780475134,
 'decmin': -16.11097943591057,
 'decref': -16.033486087652506,
 'equinox': 2000.0,
 'fluxmax': 6242.35009765625,
 'fluxmin': 144.73329162597656,
 'fluxref': 150.5890655517578,
 'latc': -16.033069432216394,
 'lonc': 274.87491757671233,
 'naxis': 2,
 'naxis1': 512,
 'naxis2': 1024,
 'naxis3': 0,
 'naxis4': 1,
 'nnull': 4101,
 'npixel': 258043,
 'proj': b'SIN',
 'ra1': 274.94926115727543,
 'ra2': 274.8008871769028,
 'ra3': 274.80096897014977,
 'ra4': 274.9491312113628,
 'rac': 274.8749176,
 'radius': 0.1590092822480096,
 'radpix': 572.4334022399462,
 'ramax': 274.92739434540744,
 'ramin': 274.80191795811646,
 'raref': 274.8750621219222,
 'rmsflux': 65.05720507695393,
 'rotequ': 0.004616575003548314,
 'sigmamax': 93.54524342789446,
 'sigmamin': -0.18175881294283833,
 'sigmaref': -0.09174919880625412,
 'status': '0',
 'totalflux': 0.0,
 'ximgsize': 0.142222225664,
 'xmax': 75.0,
 'xmin': 509.0,
 'xref': 256.0,
 'yimgsize': 0.284444451328,
 'ymax': 310.0,
 'ymin': 233.0,
 'yref': 512.0}

The return structure contains the image world coordinate system information (pixel dimensions, coordinate system, projection, projection center coordinates, reference pixel coordinates, image rotation), and the location of the four corners of the image on the sky and the center of the image. It also contains a number of fluxes (mean, rms, min, max) with locations.

The alphabetic ordering in the Python dictionary printing tends to obscure some of the relationships. See the bottom of the page for the standard order and descriptions.

If we want a specific area, we can add a cone specification:

In [3]:
rtn = mExamine("M17/raw/2mass-atlas-990502s-j1340186.fits", 1,
               ra=274.8747874521937, 
               dec=-16.03329263885489,
               radius=0.003)

import pprint as pp
pp.pprint(rtn)
{'aveflux': 152.35101183255514,
 'cdelt1': -0.0002777777845,
 'cdelt2': 0.0002777777845,
 'crota2': 0.004616579845,
 'crpix1': 256.5,
 'crpix2': 512.5,
 'crval1': 274.8749176,
 'crval2': -16.03334721,
 'csys': b'EQUJ',
 'dec1': -16.175828813608888,
 'dec2': -16.175840403064864,
 'dec3': -15.891117891843425,
 'dec4': -15.891106318926342,
 'decc': -16.033347210000002,
 'decmax': -16.035152586843832,
 'decmin': -16.03431952904279,
 'decref': -16.03320833225072,
 'equinox': 2000.0,
 'fluxmax': 170.27047729492188,
 'fluxmin': 147.4551544189453,
 'fluxref': 151.26348876953125,
 'latc': -16.033069432216394,
 'lonc': 274.87491757671233,
 'naxis': 2,
 'naxis1': 512,
 'naxis2': 1024,
 'naxis3': 0,
 'naxis4': 1,
 'nnull': 0,
 'npixel': 576,
 'proj': b'SIN',
 'ra1': 274.94926115727543,
 'ra2': 274.8008871769028,
 'ra3': 274.80096897014977,
 'ra4': 274.9491312113628,
 'rac': 274.8749176,
 'radius': 0.003,
 'radpix': 10.799999738640006,
 'ramax': 274.8770854236674,
 'ramin': 274.8736170835646,
 'raref': 274.8747730782791,
 'rmsflux': 4.395256663493169,
 'rotequ': 0.004616575003548314,
 'sigmamax': 4.077000920379716,
 'sigmamin': -1.1138956808312548,
 'sigmaref': -0.24743107087620592,
 'status': '0',
 'totalflux': 0.0,
 'ximgsize': 0.142222225664,
 'xmax': 249.0,
 'xmin': 261.0,
 'xref': 257.0,
 'yimgsize': 0.284444451328,
 'ymax': 506.0,
 'ymin': 509.0,
 'yref': 513.0}

 

Error Handling

If mExamine 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 = mExamine("M17/raw/unknown.fits")

print(rtn)
{'status': '1', 'msg': b'Cannot open FITS file M17/raw/unknown.fits'}

 

Classic Montage: mExamine as a Stand-Alone Program

mExamine Unix/Windows Command-line Arguments

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

Usage: mExamine [-d][-p ra dec radius | -a ra dec] image.fits

 

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

/*-***********************************************************************/
/*                                                                       */
/*  mExamine                                                             */
/*                                                                       */
/*  Opens a FITS file (using the cfitsio library), finds the coordinates */
/*  on the sky of the corners (using the WCS library) and converts them  */
/*  to equatorial J2000 (using the coord library).                       */
/*                                                                       */
/*  Outputs these corners plus all the image projection information.     */
/*                                                                       */
/*   char  *infile         FITS file to examine                          */

/*   int    areaMode       We can examine the image in general (0:NONE)  */
/*                         a specific region with radius (1:AREA) or     */
/*                         perform aperture photometry out to a fixed    */
/*                         radius (2:APPHOT)                             */
/*                                                                       */
/*   int    hdu            Optional HDU offset for input file            */
/*                                                                       */
/*   int    plane3         If datacube, the plane index for dimension 3  */
/*   int    plane4         If datacube, the plane index for dimension 4  */
/*                                                                       */
/*   double ra             RA for region statistics                      */
/*   double dec            Dec for region statistics                     */
/*   double radius         Radius for region statistics                  */
/*                                                                       */
/*   int    locinpix       The coordinates are actually in pixels        */
/*   int    radinpix       The radius is actually in pixels              */
/*                                                                       */
/*   int    debug          Debugging output level                        */
/*                                                                       */
/*************************************************************************/

struct mExamineReturn * mExamine(char *infile, int areaMode, int hdu, int plane3, int plane4, 
                                 double ra, double dec, double radius, int locinpix, int radinpix, int debug)

Return Structure

struct mExamineReturn
{
   int    status;        // Return status (0: OK, 1:ERROR)
   char   msg [1024];    // Return message (for error return)
   char   json[4096];    // Return parameters as JSON string
   char   proj  [32];    // Image projection.   
   char   csys  [16];    // Coordinate system.   
   double equinox;       // Coordinate system equinox.
   int    naxis;         // Number of axes.
   int    naxis1;        // First axis size.
   int    naxis2;        // Second axis size.
   int    naxis3;        // Third axis size (if it exists).
   int    naxis4;        // Fourth axis size (if it exists).
   double crval1;        // Axis 1 sky reference value.
   double crval2;        // Axis 2 sky reference value.
   double crpix1;        // Axis 1 reference pixel.
   double crpix2;        // Axis 2 reference pixel.
   double cdelt1;        // Axis 1 pixel scale.
   double cdelt2;        // Axis 2 pixel scale.
   double crota2;        // Image rotation on sky.
   double lonc;          // Longitude of the image center.
   double latc;          // Latitude of the image center.
   double ximgsize;      // Axis 1 size on the sky.
   double yimgsize;      // Axis 2 size on the sky.
   double rotequ;        // Rotation of image relative to Equatorial North
   double rac;           // RA of the image center.
   double decc;          // Dec of the image center.
   double ra1;           // RA of image corner 1
   double dec1;          // Dec of image corner 1
   double ra2;           // RA of image corner 2
   double dec2;          // Dec of image corner 2
   double ra3;           // RA of image corner 3
   double dec3;          // Dec of image corner 3
   double ra4;           // RA of image corner 4
   double dec4;          // Dec of image corner 4
   double radius;        // Radius of the examine radius (in degrees).
   double radpix;        // Radius of the examine radius (in pixels).
   int    npixel;        // Number of pixel in the examine area.
   double nnull;         // Number of null pixels in the examine area.
   double aveflux;       // Average flux.
   double rmsflux;       // RMS flux.
   double fluxref;       // Flux for center (reference) pixel.
   double sigmaref;      // Reference flux in units of RMS.
   double xref;          // Pixel X of reference.
   double yref;          // Pixel Y of reference.
   double raref;         // RA of reference.
   double decref;        // Dec of reference.
   double fluxmin;       // Flux of pixel with minimum value in examine area.
   double sigmamin;      // Min flux in units of RMS.
   double xmin;          // Pixel X of min.
   double ymin;          // Pixel Y of min.
   double ramin;         // RA of min pixel.
   double decmin;        // Dec of min pixel.
   double fluxmax;       // Flux of pixel with maximum value in examine area.
   double sigmamax;      // Max flux in units of RMS
   double xmax;          // Pixel X of max.
   double ymax;          // Pixel Y of max.
   double ramax;         // RA of max pixel.
   double decmax;        // Dec of m.n pixel.
   double totalflux;     // Aperture phtometry total flux.
};