<jupyter_start><jupyter_text>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 ("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: mImgtblThe 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.<jupyter_code>from MontagePy.main import mImgtbl

help(mImgtbl)<jupyter_output>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[...]<jupyter_text>mImgtbl ExamplemImgtbl 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:<jupyter_code>rtn = mImgtbl('M17/raw', 'work/M17/rimages.tbl')

print(rtn)<jupyter_output>{'status': '0', 'count': 49, 'badfits': 0, 'badwcs': 0}<jupyter_text>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 DataThe 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.<jupyter_code>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<jupyter_output><empty_output><jupyter_text>Error HandlingIf 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:<jupyter_code>rtn = mImgtbl('M17/unknown', 'work/M17/rimages.tbl')

print(rtn)<jupyter_output>{'status': '1', 'msg': b'Cannot access M17/unknown'}
{'fraction_non_alphanumeric': 0.060405851816894764, 'fraction_numerical': 0.006134969325153374, 'mean_word_length': 4.359039190897598, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '300858', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1197, 'n_tokens_neox': 1123, 'n_words': 577, 'path': 'mImgtbl.ipynb', 'repo_name': 'Caltech-IPAC/MontageNotebooks', 'size': '4238'}