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

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, mImgtbl, which is used to generate an image metadata summary for a set of images.

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

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

mImgtbl(...)
    mImgtbl extracts the FITS header geometry information from a set of files and creates an ASCII image metadata table which is used by several of the other programs. It only collects data from headers that comply with the FITS standard, but reports a count of images that fail that check.
    
    Parameters
    ----------
    pathname : str
        Directory (or top of tree) for image file search (default to current directory).
    tblname : str
        Output table file name.
    recursiveMode : bool, optional
        Search for images recursively (default just top directory).
    processAreaFiles : bool, optional
        Include 'area' files in the list (not normally useful).
    haveCubes : bool, optional
        False if we know we don't have datacubes (fewer table columns).
    noGZIP : bool, optional
        mImgtbl normally includes analysis of .fits.gz files.  This turns that off.
    showCorners : bool, optional
        Include ra1,dec1, ... dec4 image corner columns in output.
    showinfo : bool, optional
        Show running 'INFO' messages for FITS HDUs with bad WCS headers.
    showbad : bool, optional
        Include bad HDUs in output table.
    imgListFile : str, optional
        Rather than searching through directories, get the list of images from a table file.
    fieldListFile : str, optional
        File with list of FITS keywords to include in output table (in addition to the standard WCS info).
    debug : int, optional
        Debugging outout level.
    
    
    Returns
    -------
    status : int
        Return status (0: OK, 1:ERROR).
    msg : str
        Return message (for errors).
    count : int
        Number of images found with valid headers (may be more than one per file).
    badfits : int
        Number of bad FITS files.
    badwcs : int
        Number of images rejected because of bad WCS information.

mImgtbl Example

mImgtbl scans the input directory (optionally recursively) looking for FITS files with proper world coordinate system (WCS) parameters in the header. For multi-part files, each HDU is scanned separately. The results are written to the output table. These tables are of general utility (e.g., for constructing searchable archive metadata database tables), but their primary purpose in this mosaicking scenario is as lists of images to process and coverage information to determine image overlaps.

The following call generates a metadata table for a set of 2MASS J-band images near M17 a retreived by mArchiveList/mArchiveExec:

In [2]:
rtn = mImgtbl('M17/raw', 'work/M17/rimages.tbl')

print(rtn)
{'status': '0', 'count': 49, 'badfits': 0, 'badwcs': 0}

Montage modules return JSON structures. They always include a status (0: success; 1: error) and a variable number of informational parameters. Here the list contains 85 images.

Archive List Data

The returned table is in IPAC ASCII format, the default for Montage. You can read it into a Pandas dataframe with AstroPy. Here we extract the local file name and the center coordinates.

In [3]:
import os
import numpy as np
import pandas as pd
from astropy.io import ascii

ipactable = ascii.read('work/M17/rimages.tbl').to_pandas()

ipactable
Out[3]:
cntr ra dec cra cdec naxis1 naxis2 ctype1 ctype2 crpix1 ... dec1 ra2 dec2 ra3 dec3 ra4 dec4 size hdu fname
0 0.0 274.875039 -15.764042 18h 19m 30.01s -15d 45m 50.5s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -15.906385 274.949010 -15.621662 274.801044 -15.621674 274.800965 -15.906396 1648112.0 0.0 2mass-atlas-990502s-j1340174.fits
1 1.0 275.752732 -16.516501 18h 23m 00.66s -16d 30m 59.4s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.658841 275.826978 -16.374119 275.678454 -16.374135 275.678378 -16.658857 1644834.0 0.0 2mass-atlas-990502s-j1470068.fits
2 2.0 275.123042 -15.765737 18h 20m 29.53s -15d 45m 56.7s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -15.908077 275.197008 -15.623354 275.049041 -15.623372 275.048973 -15.908094 1599290.0 0.0 2mass-atlas-990502s-j1420174.fits
3 3.0 275.370753 -16.034853 18h 21m 28.98s -16d 02m 05.5s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.177195 275.444821 -15.892473 275.296658 -15.892486 275.296580 -16.177208 1640108.0 0.0 2mass-atlas-990502s-j1440186.fits
4 4.0 275.246697 -15.709735 18h 20m 59.21s -15d 42m 35.0s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -15.852073 275.320638 -15.567350 275.172711 -15.567372 275.172653 -15.852095 1635528.0 0.0 2mass-atlas-990502s-j1430103.fits
5 5.0 274.998829 -15.708226 18h 19m 59.72s -15d 42m 29.6s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -15.850565 275.072772 -15.565843 274.924847 -15.565861 274.924782 -15.850584 1651828.0 0.0 2mass-atlas-990502s-j1350103.fits
6 6.0 274.628266 -16.304900 18h 18m 30.78s -16d 18m 17.6s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.447250 274.702453 -16.162527 274.554089 -16.162523 274.553972 -16.447246 1601540.0 0.0 2mass-atlas-001012s-j0140198.fits
7 7.0 274.627507 -16.033815 18h 18m 30.60s -16d 02m 01.7s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.176161 274.701583 -15.891439 274.553420 -15.891444 274.553325 -16.176166 1650101.0 0.0 2mass-atlas-990502s-j1320186.fits
8 8.0 274.628258 -16.574344 18h 18m 30.78s -16d 34m 27.6s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.716694 274.702546 -16.431972 274.553978 -16.431967 274.553860 -16.716690 1569252.0 0.0 2mass-atlas-001012s-j0140209.fits
9 9.0 275.246740 -15.979179 18h 20m 59.22s -15d 58m 45.0s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.121517 275.320779 -15.836794 275.172656 -15.836816 275.172596 -16.121539 1649572.0 0.0 2mass-atlas-990502s-j1430092.fits
10 10.0 275.494688 -16.786829 18h 21m 58.73s -16d 47m 12.6s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.929170 275.569040 -16.644447 275.420308 -16.644461 275.420226 -16.929184 1641170.0 0.0 2mass-atlas-990502s-j1450056.fits
11 11.0 275.628368 -16.572576 18h 22m 30.81s -16d 34m 21.3s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.714915 275.702632 -16.430192 275.554065 -16.430211 275.553994 -16.714933 1633130.0 0.0 2mass-atlas-990502s-j1460209.fits
12 12.0 275.628331 -16.303131 18h 22m 30.80s -16d 18m 11.3s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.445470 275.702493 -16.160748 275.554130 -16.160767 275.554061 -16.445489 1657629.0 0.0 2mass-atlas-990502s-j1460198.fits
13 13.0 274.998865 -15.977670 18h 19m 59.73s -15d 58m 39.6s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.120010 275.072906 -15.835287 274.924785 -15.835306 274.924718 -16.120028 1599610.0 0.0 2mass-atlas-990502s-j1350092.fits
14 14.0 274.751230 -16.785979 18h 19m 00.30s -16d 47m 09.5s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.928316 274.825573 -16.643594 274.676842 -16.643615 274.676775 -16.928337 1533951.0 0.0 2mass-atlas-990502s-j1330056.fits
15 15.0 275.494606 -15.978495 18h 21m 58.71s -15d 58m 42.6s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.120837 275.568652 -15.836114 275.420530 -15.836128 275.420454 -16.120851 1646490.0 0.0 2mass-atlas-990502s-j1450092.fits
16 16.0 275.246870 -16.787513 18h 20m 59.25s -16d 47m 15.0s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.929849 275.321213 -16.645127 275.172481 -16.645149 275.172415 -16.929872 1618533.0 0.0 2mass-atlas-990502s-j1430056.fits
17 17.0 274.751105 -15.977645 18h 19m 00.27s -15d 58m 39.5s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.119983 274.825144 -15.835261 274.677023 -15.835282 274.676961 -16.120004 1656061.0 0.0 2mass-atlas-990502s-j1330092.fits
18 18.0 274.998975 -16.786004 18h 19m 59.75s -16d 47m 09.6s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.928342 275.073321 -16.643620 274.924590 -16.643638 274.924517 -16.928361 1581598.0 0.0 2mass-atlas-990502s-j1350056.fits
19 19.0 274.627497 -15.764371 18h 18m 30.60s -15d 45m 51.7s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -15.906717 274.701475 -15.621994 274.553509 -15.621999 274.553415 -15.906722 1642365.0 0.0 2mass-atlas-990502s-j1320174.fits
20 20.0 275.752701 -16.247057 18h 23m 00.65s -16d 14m 49.4s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.389397 275.826845 -16.104675 275.678524 -16.104691 275.678450 -16.389413 1650435.0 0.0 2mass-atlas-990502s-j1470080.fits
21 21.0 275.370728 -15.765409 18h 21m 28.97s -15d 45m 55.5s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -15.907751 275.444698 -15.623028 275.296731 -15.623041 275.296654 -15.907764 1656387.0 0.0 2mass-atlas-990502s-j1440174.fits
22 22.0 275.123077 -16.035181 18h 20m 29.54s -16d 02m 06.7s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.177521 275.197140 -15.892798 275.048977 -15.892816 275.048907 -16.177538 1621035.0 0.0 2mass-atlas-990502s-j1420186.fits
23 23.0 275.494578 -15.709051 18h 21m 58.70s -15d 42m 32.6s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -15.851393 275.568527 -15.566670 275.420601 -15.566684 275.420526 -15.851407 1654852.0 0.0 2mass-atlas-990502s-j1450103.fits
24 24.0 274.751064 -15.708201 18h 19m 00.26s -15d 42m 29.5s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -15.850539 274.825005 -15.565817 274.677079 -15.565838 274.677019 -15.850560 1616957.0 0.0 2mass-atlas-990502s-j1330103.fits
25 25.0 274.875062 -16.033486 18h 19m 30.01s -16d 02m 00.5s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.175829 274.949131 -15.891106 274.800969 -15.891118 274.800887 -16.175840 1633635.0 0.0 2mass-atlas-990502s-j1340186.fits
26 26.0 275.752764 -16.785946 18h 23m 00.66s -16d 47m 09.4s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.928286 275.827113 -16.643563 275.678382 -16.643579 275.678304 -16.928302 1638810.0 0.0 2mass-atlas-990502s-j1470056.fits
27 27.0 274.628275 -16.035455 18h 18m 30.79s -16d 02m 07.6s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.177806 274.702361 -15.893083 274.554197 -15.893079 274.554082 -16.177802 1659317.0 0.0 2mass-atlas-001012s-j0140186.fits
28 28.0 274.627527 -16.572704 18h 18m 30.61s -16d 34m 21.7s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.715049 274.701805 -16.430327 274.553238 -16.430332 274.553139 -16.715055 1562618.0 0.0 2mass-atlas-990502s-j1320209.fits
29 29.0 274.627517 -16.303259 18h 18m 30.60s -16d 18m 11.7s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.445605 274.701693 -16.160883 274.553330 -16.160888 274.553233 -16.445610 1592556.0 0.0 2mass-atlas-990502s-j1320198.fits
30 30.0 275.370805 -16.573742 18h 21m 28.99s -16d 34m 25.5s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.716083 275.445075 -16.431361 275.296508 -16.431374 275.296425 -16.716097 1604130.0 0.0 2mass-atlas-990502s-j1440209.fits
31 31.0 275.370779 -16.304298 18h 21m 28.99s -16d 18m 15.5s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.446639 275.444947 -16.161917 275.296584 -16.161930 275.296503 -16.446652 1644389.0 0.0 2mass-atlas-990502s-j1440198.fits
32 32.0 275.628294 -16.033687 18h 22m 30.79s -16d 02m 01.3s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.176026 275.702356 -15.891304 275.554194 -15.891322 275.554127 -16.176045 1656210.0 0.0 2mass-atlas-990502s-j1460186.fits
33 33.0 275.494661 -16.517384 18h 21m 58.72s -16d 31m 02.6s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.659725 275.568908 -16.375003 275.420384 -16.375017 275.420303 -16.659739 1614344.0 0.0 2mass-atlas-990502s-j1450068.fits
34 34.0 274.998902 -16.247115 18h 19m 59.74s -16d 14m 49.6s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.389454 275.073043 -16.104731 274.924722 -16.104750 274.924653 -16.389472 1562099.0 0.0 2mass-atlas-990502s-j1350080.fits
35 35.0 274.751188 -16.516534 18h 19m 00.29s -16d 30m 59.5s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.658872 274.825428 -16.374149 274.676904 -16.374170 274.676839 -16.658893 1551169.0 0.0 2mass-atlas-990502s-j1330068.fits
36 36.0 275.246783 -16.248624 18h 20m 59.23s -16d 14m 55.0s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.390961 275.320921 -16.106239 275.172599 -16.106261 275.172538 -16.390983 1648784.0 0.0 2mass-atlas-990502s-j1430080.fits
37 37.0 275.752638 -15.708168 18h 23m 00.63s -15d 42m 29.4s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -15.850509 275.826584 -15.565786 275.678659 -15.565802 275.678588 -15.850525 1650006.0 0.0 2mass-atlas-990502s-j1470103.fits
38 38.0 275.246826 -16.518068 18h 20m 59.24s -16d 31m 05.0s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.660405 275.321066 -16.375683 275.172541 -16.375705 275.172477 -16.660427 1610118.0 0.0 2mass-atlas-990502s-j1430068.fits
39 39.0 274.751147 -16.247090 18h 19m 00.28s -16d 14m 49.5s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.389428 274.825285 -16.104705 274.676964 -16.104726 274.676901 -16.389449 1607886.0 0.0 2mass-atlas-990502s-j1330080.fits
40 40.0 274.998938 -16.516559 18h 19m 59.75s -16d 30m 59.6s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.658898 275.073181 -16.374175 274.924657 -16.374194 274.924586 -16.658917 1594836.0 0.0 2mass-atlas-990502s-j1350068.fits
41 41.0 275.494633 -16.247940 18h 21m 58.71s -16d 14m 52.6s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.390281 275.568779 -16.105559 275.420458 -16.105573 275.420380 -16.390295 1651471.0 0.0 2mass-atlas-990502s-j1450080.fits
42 42.0 275.628258 -15.764243 18h 22m 30.78s -15d 45m 51.3s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -15.906582 275.702221 -15.621860 275.554256 -15.621878 275.554190 -15.906601 1646515.0 0.0 2mass-atlas-990502s-j1460174.fits
43 43.0 274.628283 -15.766011 18h 18m 30.79s -15d 45m 57.6s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -15.908361 274.702271 -15.623639 274.554304 -15.623635 274.554191 -15.908357 1650467.0 0.0 2mass-atlas-001012s-j0140174.fits
44 44.0 275.752669 -15.977612 18h 23m 00.64s -15d 58m 39.4s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.119953 275.826713 -15.835230 275.678592 -15.835246 275.678520 -16.119969 1645716.0 0.0 2mass-atlas-990502s-j1470092.fits
45 45.0 274.875085 -16.302930 18h 19m 30.02s -16d 18m 10.5s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.445273 274.949254 -16.160550 274.800892 -16.160562 274.800808 -16.445285 1574588.0 0.0 2mass-atlas-990502s-j1340198.fits
46 46.0 274.875108 -16.572375 18h 19m 30.03s -16d 34m 20.5s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.714717 274.949379 -16.429995 274.800812 -16.430006 274.800727 -16.714729 1564492.0 0.0 2mass-atlas-990502s-j1340209.fits
47 47.0 275.123111 -16.304626 18h 20m 29.55s -16d 18m 16.7s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.446965 275.197274 -16.162243 275.048911 -16.162260 275.048839 -16.446983 1643713.0 0.0 2mass-atlas-990502s-j1420198.fits
48 48.0 275.123145 -16.574070 18h 20m 29.55s -16d 34m 26.7s 512.0 1024.0 RA---SIN DEC--SIN 256.5 ... -16.716409 275.197411 -16.431687 275.048843 -16.431704 275.048770 -16.716427 1621040.0 0.0 2mass-atlas-990502s-j1420209.fits

49 rows × 37 columns

Error Handling

If mImgtbl 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 asks for a non-existent directory:

In [4]:
rtn = mImgtbl('M17/unknown', 'work/M17/rimages.tbl')

print(rtn)
{'status': '1', 'msg': b'Cannot access M17/unknown'}

 

Classic Montage: mImgtbl as a Stand-Alone Program

mImgtbl Unix/Windows Command-line Arguments

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

Usage: mImgtbl [-rcCaidbd][-s statusfile][-f fieldlistfile][-t imglist] directory images.tbl

 

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

/*-***********************************************************************/
/*                                                                       */
/*  mImgtbl                                                              */
/*                                                                       */
/*  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, mImgtbl, makes a list (with WCS information) of all     */
/*  FITS image files in the named directory (and optionally recursively) */
/*                                                                       */
/*  mImgtbl supports a lot of variation in input (and a little in        */
/*  output) so there are lot of parameters on the call, most of which    */
/*  can be "defaulted" (i.e. set to zero / NULL).  The full parameter    */
/*  list is:                                                             */
/*                                                                       */
/*   char *pathname        Directory (or top of tree) for image file     */
/*                         search (default to current directory).        */
/*   char *tblname         Output table file name (no default).          */
/*                                                                       */
/*   int recursiveMode     Search for images recursively (default just   */
/*                         top directory).                               */
/*   int processAreaFiles  Include "area" files in the list (not         */
/*                         normally advisable).                          */
/*   int haveCubes         False if we know we don't have datacubes      */
/*                         (fewer table columns)                         */
/*   int noGZIP            mImgtbl normally includes analysis of         */
/*                         .fits.gz files.  This turns that off.         */
/*   int showCorners       Include ra1,dec1, ... dec4 image corner       */
/*                         columns in output.                            */
/*   int showinfo          For HDUs that are are rejected, emit an       */
/*                         INFO message.  Best used in application       */
/*                         mode or when debugging.                       */
/*   int showbad           Show running "INFO" messages for FITS files   */
/*                         that cannot be opened by CFITSIO.             */
/*                                                                       */
/*   char *imgListFile     Rather than searching through directories,    */
/*                         get the list of images from a table file.     */
/*   char *fieldListFile   List of FITS keywords to include in output    */
/*                         table (in addition to the standard WCS info.  */
/*                                                                       */
/*   int debug             Turn on debugging output (not for general     */
/*                         use).                                         */
/*                                                                       */
/*************************************************************************/

struct mImgtblReturn *mImgtbl(char *pathnamein, char *tblname,
                              int recursiveModein, int processAreaFilesin, int haveCubes, int noGZIPin, 
                              int showCornersin, int showinfo, int showbadin, char *imgListFile, char *fieldListFile,
                              int debugin)

Return Structure

struct mImgtblReturn
{
   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    count;         // Number of images found with valid headers (may be more than one per file).
   int    nfile;         // Number of FITS files found.
   int    nhdu;          // Total number of HDSs in all files.
   int    badfits;       // Number of bad FITS files.
   int    badwcs;        // Number of images rejected because of bad WCS information.
};