Montage and Docker (Visualization)

This notebook is part of a tutorial where we will have already created image mosaics by the time we get to this point. Here we use the Astroquery package to retrieve some catalog data, then display the image along with a catalog overlay.

Setup

In the tutorial, this notebook should be installed into the same directory ("/work" in a Docker container) where we have already generated the mosaics.

In [2]:
import os
import sys
import shutil
import warnings
import datetime
import math
import numpy as np
import pandas as pd
import plotly as py
import plotly.graph_objs as go
import ipywidgets as widgets
import requests
import qgrid

from astropy.io import ascii
from astropy.coordinates import SkyCoord
from astroquery.utils.tap.core import Tap
from MontagePy.main import *
from IPython.display import Image
WARNING: AstropyDeprecationWarning: astropy.extern.six will be removed in 4.0, use the six module directly if it is still needed [astropy.extern.six]

Searching a Catalog

The VO Table Access Protocol (TAP) services provide DBMS search capabilities for astronomical catalogs. TAP is essentially SQL enhanced with a spatial search capability. First we determine the region of interest (basically looking up the coordinates of our object).

In [2]:
# These are the parameters defining our region of interest

location  = "M 51"
size      = 0.25

coord = SkyCoord.from_name(location)

ra  = coord.ra.to_value()
dec = coord.dec.to_value()

radius = size * 1.414

print('RA:     ', ra)
print('Dec:    ', dec)
print('Radius: ', radius)
RA:      202.469575
Dec:     47.19525833
Radius:  0.3535

then we use TAP to retrieve our catalog data (here the 2MASS Point Source Catalog)

In [3]:
# There are Table Access Protocol services at CDS, IRSA, GAIA, NED etc.

warnings.filterwarnings('ignore')
   
service = Tap(url="https://irsa.ipac.caltech.edu/TAP")

job = service.launch_job_async("""SELECT ra, dec, j_m, h_m, k_m, 
                                  j_m - h_m as jmh, h_m - k_m as hmk, j_m - k_m as jmk
                                  FROM fp_psc 
                                  WHERE CONTAINS(POINT('ICRS',ra, dec), CIRCLE('ICRS',"""
                                  + str(ra) + ',' + str(dec) + ',' + str(radius) + '))=1',
                                  verbose=False, background=True)
res = job.get_results()

ascii.write(res, output='fp_2mass.tbl', format='ipac')

And Image Metadata

Montage has custom image metadata searches set up for a number of image archives. Here we retrieve Spitzer MIPS band 1.

In [4]:
mArchiveList("Spitzer", "MIPS1", "M51", 0.3, 0.3, 'mips.tbl')
Out[4]:
{'status': '0', 'count': 11}

View the Image and Catalog Data

FITS files are binary data structures. To see the image we need to render to a JPEG or PNG form. This involves choosing a stretch, color table (if it is a single image as here) and so on. Montage provides a general visualization tool (mViewer) which can process a single image or multiple images for full color. It supports overlays of various sorts. One of its most useful features is a custom stretch algorithm which is based on gaussian-transformed histogram equalization, optionally with an extra logarithmic transform for really bright excursions. A large fraction of astronomical images share the general characteristics of having a lot of pixels with something like a gaussian distribution at a low flux level (either background noise of low-level sky structure) coupled with a long histogram tail of very bright point-like sources. If we apply our algorithm to this, stretching from the -2 or -1 "sigma" value of the low-level distribution to the image brightness maximum we usually get a good balance of seeing the low-level structure while still seeing the structure and brightness variations of the bright sources.

mViewer specifications can become quite lengthy so the module provides three entry mechanisms. The most terse (used here) is a "parameter string" based on the command-line arguments of the original stand-alone C program. For more complicated descriptions the user can define a JSON string or JSON file.

We use the built-in IPython.display utility to show the resultant image, which shrinks it to fit. There are several other tools you can use instead.

In [5]:
# Make a PNG rendering of the data and display it.

rtn = mViewer('''-color gray
                 -grid equ j2000
                 -color red 
                 -symbol 1.0 circle 
                 -scalecol j_m 16.0 mag 
                 -catalog fp_2mass.tbl
                 -color yellow
                 -imginfo mips.tbl
                 -blue  uband/mosaic.fits 0s max gaussian-log
                 -green gband/mosaic.fits 0s max gaussian-log
                 -red   iband/mosaic.fits 0s max gaussian-log -out M51_color.png''',

               "", mode=2)

Image(filename='M51_color.png')
Out[5]:

If you want to see this image a full resolution, you will find it as a PNG on the Jupyter directory listing page (refresh that page if it doesn't show).

Display the Table

In [3]:
twomass_data = ascii.read("fp_2mass.tbl")

tmass = twomass_data.to_pandas()

df_qgrid = qgrid.show_grid(tmass)

df_qgrid

Scatter Plot of the Table

This specific plot is planet mass vs. radius (Jupiter units). We want to also indicate orbital period so we create a list of colors based on the log() of that variable (e.g. values between 1 and 10 AU are blue). Records with unknow period are white.

In [4]:
py.offline.init_notebook_mode(connected=True)

layout = go.Layout(
    title='2MASS Catalog Sources',
    height=800,
    yaxis=dict(
        title='K [mag]',
        type='linear',
        autorange=True
    ),
    xaxis=dict(
        title='J-K [mag]',
        type='linear',
        autorange=True
    )
)

trace1 = go.Scatter(
    x=tmass['jmk'].tolist(),
    y=tmass['k_m'].tolist(),
    mode='markers',
    marker=dict(
        opacity=0.5,
        line = dict(
          color = '#404040',
          width = 1
        )
    )       
)

fig = go.Figure(data=[trace1], layout=layout)
py.offline.iplot(fig)
In [ ]: