<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: mArchiveGetThe 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 module, mArchiveGet, which retrieves a single archive image.Visit Building a Mosaic with Montage to see how mArchiveGet is used as part of a workflow to create 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 mArchiveGet, mViewer

help(mArchiveGet)<jupyter_output>Help on built-in function mArchiveGet in module MontagePy.main:

mArchiveGet(...)
    mArchiveGet retrieves an image file by URL from one of several archives.
    
    Parameters
    ----------
    url : str
        Directory containing files to be coadded.
    datafile : str
        Table file list of reprojected files to coadded.
    timeout : int, optional
        Timeout in seconds.
    debug : int, optional
        Debugging output level.
    
    
    Returns
    -------
    status : int
        Return status (0: OK, 1:ERROR).
    msg : str
        Return message (for errors).
    count : int
        Size of file in bytes.<jupyter_text>mArchiveGet ExamplemArchiveGet can be used stand-alone but is really just meant for use by mArchiveExec when retreiving a list of images.  Stand-alone it has no advantage over tools like wget and curl.  The two main arguments are the URL to retreive and the local file to write it to:<jupyter_code>rtn = mArchiveGet('http://irsa.ipac.caltech.edu/ibe/data/twomass/full/full/990502s/s134/image/ji1340186.fits.gz', 
                  'work/M17/raw/2mass-atlas-990502s-j1340186.fits')

print(rtn)<jupyter_output>{'status': '0', 'count': 1633635}<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 returned file had 1633635 bytes. Returned DataTo verify the download, we can take a look at the image:<jupyter_code>from IPython.display import Image

rtn = mViewer("-ct 1 -gray work/M17/raw/2mass-atlas-990502s-j1340186.fits \
               -2s max gaussian-log -out work/M17/2mass-atlas-990502s-j1340186.png",
              "", mode=2)

Image(filename='work/M17/2mass-atlas-990502s-j1340186.png')<jupyter_output><empty_output><jupyter_text>mArchiveGet Error HandlingIf mArchiveGet 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 URL that doesn't exist:<jupyter_code>rtn = mArchiveGet('http://unknown.edu/image/ji1340186.fits.gz', 
                  'work/M17/raw/2mass-atlas-990502s-j1340186.fits')

print(rtn)<jupyter_output>{'status': '1', 'msg': b'Unable to resolve URL.'}
{'fraction_non_alphanumeric': 0.07601078167115903, 'fraction_numerical': 0.03423180592991914, 'mean_word_length': 3.703422053231939, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '419593', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1195, 'n_tokens_neox': 1070, 'n_words': 442, 'path': 'mArchiveGet.ipynb', 'repo_name': 'Caltech-IPAC/MontageNotebooks', 'size': '3710'}