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.
In the tutorial, this notebook should be installed into the same directory ("/work" in a Docker container) where we have already generated the mosaics.
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
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).
# 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)
then we use TAP to retrieve our catalog data (here the 2MASS Point Source Catalog)
# 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')
Montage has custom image metadata searches set up for a number of image archives. Here we retrieve Spitzer MIPS band 1.
mArchiveList("Spitzer", "MIPS1", "M51", 0.3, 0.3, 'mips.tbl')
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.
# 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')