MAST Table Access Protocol Hubble Source Catalog Demo#


This tutorial demonstrates how to use astroquery to access the Hubble Source Catalog (HSC) via a Virtual Observatory standard Table Access Protocol (TAP) service at MAST, and work with the resultant data.


Table of Contents#

  1. HSC TAP Service Introduction

  2. Imports

  3. Connecting, Finding, and Displaying Table Information

    • Connecting to a TAP Service

    • Querying for Table Schema Information

    • Querying for Data

    • Use Case: Plotting a light curve for the most variable object in a field

    • Use Case: Create a color magnitude diagram for the Small Magellanic Cloud

  4. Additional Resources

  5. About This Notebook


HSC TAP Service Introduction#

Table Access Protocol (TAP) services allow more direct and flexible access to astronomical data than the simpler types of IVOA standard data services. Queries are built with the SQL-like Astronomical Data Query Language (ADQL), and can include geographic/spatial queries as well as filtering on other characteristics of the data. This also allows the user fine-grained control over the returned columns, unlike the fixed set of coumns returned from cone, image, and spectral services.

For this example, we’ll be using the astropy affiliated PyVO client, which is interoperable with other valid TAP services, including those at MAST. PyVO documentation is available at ReadTheDocs: https://pyvo.readthedocs.io

We’ll be using PyVO to call the most recent version (3) of the Hubble Source Catalog TAP service at MAST. The schema is described within the service, and we’ll show how to inspect it. The schema is also the same as the one available via the CasJobs interface, with an additional view added for the most common positional queries. CasJobs has its own copy of the schema documentation, which can be accessed through its own site: http://mastweb.stsci.edu/hcasjobs/


Imports#

import pyvo as vo

## For handling ordinary astropy Tables in responses
from astropy.table import Table

# For displaying and manipulating some types of results
%matplotlib inline
import requests
import astropy
import numpy as np
import time
from matplotlib import pyplot as plt

# For the second example: kernel density estimates
from scipy.stats import gaussian_kde


# suppress unimportant unit warnings from many TAP services
import warnings
warnings.filterwarnings("ignore", module="astropy.io.votable.*")

Connecting, Finding, and Displaying Table Information#

Connecting to a TAP Service#

The PyVO library is able to connect to any TAP service, given the “base” URL as noted in metadata registry resources describing the service. This is the URL for the newest version of the Hubble Source Catalog TAP service.

HSC_service = vo.dal.TAPService("https://mast.stsci.edu/vo-tap/api/v0.1/hsc/")

Querying for Table Schema Information#

TAP services are self-describing, which means the service itself can be asked for its schema and documentation about it. Since the Hubble Source Catalog does not follow a data model described by a standard, this is the best way to see what tables and columns we have available to then query based on geometry or other filters.

Note that several views for HSC, including the main science table SumMagAper2CatView, are extremely wide, containing columns for all potential filters, each of which may have null data. The ability to filter queries based on only columns we want, or that aren’t null, makes TAP services more flexible and potentially faster.

HSC_service.describe()
Capability ivo://ivoa.net/std/TAP

Interface vs:ParamHTTP
    https://mast.stsci.edu/vo-tap/api/v0.1/hsc

Language ADQL
Output format application/x-votable+xml
    Also available as votable

Output format text/csv;header=present
    Also available as csv

Maximum size of resultsets
    Default 100000 row
    Maximum 100000 row


Capability ivo://ivoa.net/std/DALI#examples

Interface vr:WebBrowser
    https://mast.stsci.edu/vo-tap/api/v0.1/hsc/examples
HSC_tables = HSC_service.tables
for tablename in HSC_tables.keys():
    if not "tap_schema" in tablename:  
        # No descriptions are available for these tables; this will just print the name
        HSC_tables[tablename].describe() 
        print("Columns={}".format(sorted([k.name for k in HSC_tables[tablename].columns ])))
        print("----")
dbo.detailedcatalog
    Detailed list of source catalog parameters

Columns=['abscorr', 'aperture', 'catid', 'ci', 'd', 'det', 'detector', 'dsigma', 'exposuretime', 'filter', 'flags', 'fluxaper2', 'imageid', 'imagename', 'instrument', 'kronradius', 'magaper2', 'magauto', 'matchdec', 'matchid', 'matchra', 'memid', 'mode', 'propid', 'sourcedec', 'sourceid', 'sourcera', 'startmjd', 'starttime', 'stopmjd', 'stoptime', 'targetname', 'wavelength', 'ximage', 'yimage']
----
dbo.hcvdetailedview
    Detailed list of Hubble Catalog of Variables parameters

Columns=['ci', 'corrmag', 'd', 'filter', 'imagename', 'mag', 'magerr', 'matchid', 'mjd']
----
dbo.hcvsummaryview
    Summary list of Hubble Catalog of Variables parameters

Columns=['autoclass', 'chi2', 'dec', 'expertclass', 'filter', 'filterdetflag', 'groupid', 'mad', 'matchid', 'meancorrmag', 'meanmag', 'numlc', 'ra', 'subgroupid', 'varqualflag']
----
dbo.propermotionsview
    List of proper motion information

Columns=['ci', 'ci_sigma', 'decmean', 'decmeanerr', 'dsigma', 'epochend', 'epochmean', 'epochstart', 'htmid', 'kronradius', 'kronradius_sigma', 'latmean', 'latmeanerr', 'lonmean', 'lonmeanerr', 'numfilters', 'numimages', 'numsources', 'numvisits', 'objid', 'pmdec', 'pmdecdev', 'pmdecerr', 'pmlat', 'pmlatdev', 'pmlaterr', 'pmlon', 'pmlondev', 'pmlonerr', 'pmra', 'pmradev', 'pmraerr', 'ramean', 'rameanerr', 'x', 'y', 'z']
----
dbo.sourcepositionsview
    List of source position information

Columns=['ddec', 'dec', 'dlat', 'dlon', 'dra', 'dt', 'epochmean', 'lat', 'lon', 'matchid', 'objid', 'ra', 'sourceid']
----
dbo.summagaper2catview
    Summary list of source catalog with Aper2 magnitudes

Columns=['a_f435w', 'a_f435w_mad', 'a_f435w_n', 'a_f475w', 'a_f475w_mad', 'a_f475w_n', 'a_f502n', 'a_f502n_mad', 'a_f502n_n', 'a_f550m', 'a_f550m_mad', 'a_f550m_n', 'a_f555w', 'a_f555w_mad', 'a_f555w_n', 'a_f606w', 'a_f606w_mad', 'a_f606w_n', 'a_f625w', 'a_f625w_mad', 'a_f625w_n', 'a_f658n', 'a_f658n_mad', 'a_f658n_n', 'a_f660n', 'a_f660n_mad', 'a_f660n_n', 'a_f775w', 'a_f775w_mad', 'a_f775w_n', 'a_f814w', 'a_f814w_mad', 'a_f814w_n', 'a_f850lp', 'a_f850lp_mad', 'a_f850lp_n', 'abscorr', 'ci', 'ci_sigma', 'dsigma', 'extinction', 'kronradius', 'kronradius_sigma', 'matchdec', 'matchid', 'matchra', 'numfilters', 'numimages', 'numvisits', 'spectrumflag', 'startmjd', 'starttime', 'stopmjd', 'stoptime', 'targetname', 'w2_f1042m', 'w2_f1042m_mad', 'w2_f1042m_n', 'w2_f122m', 'w2_f122m_mad', 'w2_f122m_n', 'w2_f160bn15', 'w2_f160bn15_mad', 'w2_f160bn15_n', 'w2_f160bw', 'w2_f160bw_mad', 'w2_f160bw_n', 'w2_f170w', 'w2_f170w_mad', 'w2_f170w_n', 'w2_f185w', 'w2_f185w_mad', 'w2_f185w_n', 'w2_f218w', 'w2_f218w_mad', 'w2_f218w_n', 'w2_f255w', 'w2_f255w_mad', 'w2_f255w_n', 'w2_f300w', 'w2_f300w_mad', 'w2_f300w_n', 'w2_f336w', 'w2_f336w_mad', 'w2_f336w_n', 'w2_f343n', 'w2_f343n_mad', 'w2_f343n_n', 'w2_f375n', 'w2_f375n_mad', 'w2_f375n_n', 'w2_f380w', 'w2_f380w_mad', 'w2_f380w_n', 'w2_f390n', 'w2_f390n_mad', 'w2_f390n_n', 'w2_f410m', 'w2_f410m_mad', 'w2_f410m_n', 'w2_f437n', 'w2_f437n_mad', 'w2_f437n_n', 'w2_f439w', 'w2_f439w_mad', 'w2_f439w_n', 'w2_f450w', 'w2_f450w_mad', 'w2_f450w_n', 'w2_f467m', 'w2_f467m_mad', 'w2_f467m_n', 'w2_f469n', 'w2_f469n_mad', 'w2_f469n_n', 'w2_f487n', 'w2_f487n_mad', 'w2_f487n_n', 'w2_f502n', 'w2_f502n_mad', 'w2_f502n_n', 'w2_f547m', 'w2_f547m_mad', 'w2_f547m_n', 'w2_f555w', 'w2_f555w_mad', 'w2_f555w_n', 'w2_f569w', 'w2_f569w_mad', 'w2_f569w_n', 'w2_f588n', 'w2_f588n_mad', 'w2_f588n_n', 'w2_f606w', 'w2_f606w_mad', 'w2_f606w_n', 'w2_f622w', 'w2_f622w_mad', 'w2_f622w_n', 'w2_f631n', 'w2_f631n_mad', 'w2_f631n_n', 'w2_f656n', 'w2_f656n_mad', 'w2_f656n_n', 'w2_f658n', 'w2_f658n_mad', 'w2_f658n_n', 'w2_f673n', 'w2_f673n_mad', 'w2_f673n_n', 'w2_f675w', 'w2_f675w_mad', 'w2_f675w_n', 'w2_f702w', 'w2_f702w_mad', 'w2_f702w_n', 'w2_f785lp', 'w2_f785lp_mad', 'w2_f785lp_n', 'w2_f791w', 'w2_f791w_mad', 'w2_f791w_n', 'w2_f814w', 'w2_f814w_mad', 'w2_f814w_n', 'w2_f850lp', 'w2_f850lp_mad', 'w2_f850lp_n', 'w2_f953n', 'w2_f953n_mad', 'w2_f953n_n', 'w3_blank', 'w3_blank_mad', 'w3_blank_n', 'w3_f098m', 'w3_f098m_mad', 'w3_f098m_n', 'w3_f105w', 'w3_f105w_mad', 'w3_f105w_n', 'w3_f110w', 'w3_f110w_mad', 'w3_f110w_n', 'w3_f125w', 'w3_f125w_mad', 'w3_f125w_n', 'w3_f126n', 'w3_f126n_mad', 'w3_f126n_n', 'w3_f127m', 'w3_f127m_mad', 'w3_f127m_n', 'w3_f128n', 'w3_f128n_mad', 'w3_f128n_n', 'w3_f130n', 'w3_f130n_mad', 'w3_f130n_n', 'w3_f132n', 'w3_f132n_mad', 'w3_f132n_n', 'w3_f139m', 'w3_f139m_mad', 'w3_f139m_n', 'w3_f140w', 'w3_f140w_mad', 'w3_f140w_n', 'w3_f153m', 'w3_f153m_mad', 'w3_f153m_n', 'w3_f160w', 'w3_f160w_mad', 'w3_f160w_n', 'w3_f164n', 'w3_f164n_mad', 'w3_f164n_n', 'w3_f167n', 'w3_f167n_mad', 'w3_f167n_n', 'w3_f200lp', 'w3_f200lp_mad', 'w3_f200lp_n', 'w3_f218w', 'w3_f218w_mad', 'w3_f218w_n', 'w3_f225w', 'w3_f225w_mad', 'w3_f225w_n', 'w3_f275w', 'w3_f275w_mad', 'w3_f275w_n', 'w3_f280n', 'w3_f280n_mad', 'w3_f280n_n', 'w3_f300x', 'w3_f300x_mad', 'w3_f300x_n', 'w3_f336w', 'w3_f336w_mad', 'w3_f336w_n', 'w3_f343n', 'w3_f343n_mad', 'w3_f343n_n', 'w3_f350lp', 'w3_f350lp_mad', 'w3_f350lp_n', 'w3_f373n', 'w3_f373n_mad', 'w3_f373n_n', 'w3_f390m', 'w3_f390m_mad', 'w3_f390m_n', 'w3_f390w', 'w3_f390w_mad', 'w3_f390w_n', 'w3_f395n', 'w3_f395n_mad', 'w3_f395n_n', 'w3_f410m', 'w3_f410m_mad', 'w3_f410m_n', 'w3_f438w', 'w3_f438w_mad', 'w3_f438w_n', 'w3_f467m', 'w3_f467m_mad', 'w3_f467m_n', 'w3_f469n', 'w3_f469n_mad', 'w3_f469n_n', 'w3_f475w', 'w3_f475w_mad', 'w3_f475w_n', 'w3_f475x', 'w3_f475x_mad', 'w3_f475x_n', 'w3_f487n', 'w3_f487n_mad', 'w3_f487n_n', 'w3_f502n', 'w3_f502n_mad', 'w3_f502n_n', 'w3_f547m', 'w3_f547m_mad', 'w3_f547m_n', 'w3_f555w', 'w3_f555w_mad', 'w3_f555w_n', 'w3_f600lp', 'w3_f600lp_mad', 'w3_f600lp_n', 'w3_f606w', 'w3_f606w_mad', 'w3_f606w_n', 'w3_f621m', 'w3_f621m_mad', 'w3_f621m_n', 'w3_f625w', 'w3_f625w_mad', 'w3_f625w_n', 'w3_f631n', 'w3_f631n_mad', 'w3_f631n_n', 'w3_f645n', 'w3_f645n_mad', 'w3_f645n_n', 'w3_f656n', 'w3_f656n_mad', 'w3_f656n_n', 'w3_f657n', 'w3_f657n_mad', 'w3_f657n_n', 'w3_f658n', 'w3_f658n_mad', 'w3_f658n_n', 'w3_f665n', 'w3_f665n_f6', 'w3_f665n_f6_mad', 'w3_f665n_f6_n', 'w3_f665n_mad', 'w3_f665n_n', 'w3_f673n', 'w3_f673n_mad', 'w3_f673n_n', 'w3_f680n', 'w3_f680n_mad', 'w3_f680n_n', 'w3_f689m', 'w3_f689m_mad', 'w3_f689m_n', 'w3_f763m', 'w3_f763m_mad', 'w3_f763m_n', 'w3_f775w', 'w3_f775w_mad', 'w3_f775w_n', 'w3_f814w', 'w3_f814w_mad', 'w3_f814w_n', 'w3_f845m', 'w3_f845m_mad', 'w3_f845m_n', 'w3_f850lp', 'w3_f850lp_mad', 'w3_f850lp_n', 'w3_f953n', 'w3_f953n_mad', 'w3_f953n_n', 'w3_fq232n', 'w3_fq232n_mad', 'w3_fq232n_n', 'w3_fq243n', 'w3_fq243n_mad', 'w3_fq243n_n', 'w3_fq378n', 'w3_fq378n_mad', 'w3_fq378n_n', 'w3_fq387n', 'w3_fq387n_mad', 'w3_fq387n_n', 'w3_fq422m', 'w3_fq422m_mad', 'w3_fq422m_n', 'w3_fq436n', 'w3_fq436n_mad', 'w3_fq436n_n', 'w3_fq437n', 'w3_fq437n_mad', 'w3_fq437n_n', 'w3_fq492n', 'w3_fq492n_mad', 'w3_fq492n_n', 'w3_fq508n', 'w3_fq508n_mad', 'w3_fq508n_n', 'w3_fq575n', 'w3_fq575n_mad', 'w3_fq575n_n', 'w3_fq619n', 'w3_fq619n_mad', 'w3_fq619n_n', 'w3_fq634n', 'w3_fq634n_mad', 'w3_fq634n_n', 'w3_fq672n', 'w3_fq672n_mad', 'w3_fq672n_n', 'w3_fq674n', 'w3_fq674n_mad', 'w3_fq674n_n', 'w3_fq727n', 'w3_fq727n_mad', 'w3_fq727n_n', 'w3_fq750n', 'w3_fq750n_mad', 'w3_fq750n_n', 'w3_fq889n', 'w3_fq889n_mad', 'w3_fq889n_n', 'w3_fq906n', 'w3_fq906n_mad', 'w3_fq906n_n', 'w3_fq924n', 'w3_fq924n_mad', 'w3_fq924n_n', 'w3_fq937n', 'w3_fq937n_mad', 'w3_fq937n_n', 'w3_g102', 'w3_g102_mad', 'w3_g102_n', 'w3_g141', 'w3_g141_mad', 'w3_g141_n', 'w3_g280', 'w3_g280_mad', 'w3_g280_n']
----
dbo.summagautocatview
    Summary list of source catalog with MagAuto magnitudes

Columns=['a_f435w', 'a_f435w_mad', 'a_f435w_n', 'a_f475w', 'a_f475w_mad', 'a_f475w_n', 'a_f502n', 'a_f502n_mad', 'a_f502n_n', 'a_f550m', 'a_f550m_mad', 'a_f550m_n', 'a_f555w', 'a_f555w_mad', 'a_f555w_n', 'a_f606w', 'a_f606w_mad', 'a_f606w_n', 'a_f625w', 'a_f625w_mad', 'a_f625w_n', 'a_f658n', 'a_f658n_mad', 'a_f658n_n', 'a_f660n', 'a_f660n_mad', 'a_f660n_n', 'a_f775w', 'a_f775w_mad', 'a_f775w_n', 'a_f814w', 'a_f814w_mad', 'a_f814w_n', 'a_f850lp', 'a_f850lp_mad', 'a_f850lp_n', 'abscorr', 'ci', 'ci_sigma', 'dsigma', 'extinction', 'kronradius', 'kronradius_sigma', 'matchdec', 'matchid', 'matchra', 'numfilters', 'numimages', 'numvisits', 'spectrumflag', 'startmjd', 'starttime', 'stopmjd', 'stoptime', 'targetname', 'w2_f1042m', 'w2_f1042m_mad', 'w2_f1042m_n', 'w2_f122m', 'w2_f122m_mad', 'w2_f122m_n', 'w2_f160bn15', 'w2_f160bn15_mad', 'w2_f160bn15_n', 'w2_f160bw', 'w2_f160bw_mad', 'w2_f160bw_n', 'w2_f170w', 'w2_f170w_mad', 'w2_f170w_n', 'w2_f185w', 'w2_f185w_mad', 'w2_f185w_n', 'w2_f218w', 'w2_f218w_mad', 'w2_f218w_n', 'w2_f255w', 'w2_f255w_mad', 'w2_f255w_n', 'w2_f300w', 'w2_f300w_mad', 'w2_f300w_n', 'w2_f336w', 'w2_f336w_mad', 'w2_f336w_n', 'w2_f343n', 'w2_f343n_mad', 'w2_f343n_n', 'w2_f375n', 'w2_f375n_mad', 'w2_f375n_n', 'w2_f380w', 'w2_f380w_mad', 'w2_f380w_n', 'w2_f390n', 'w2_f390n_mad', 'w2_f390n_n', 'w2_f410m', 'w2_f410m_mad', 'w2_f410m_n', 'w2_f437n', 'w2_f437n_mad', 'w2_f437n_n', 'w2_f439w', 'w2_f439w_mad', 'w2_f439w_n', 'w2_f450w', 'w2_f450w_mad', 'w2_f450w_n', 'w2_f467m', 'w2_f467m_mad', 'w2_f467m_n', 'w2_f469n', 'w2_f469n_mad', 'w2_f469n_n', 'w2_f487n', 'w2_f487n_mad', 'w2_f487n_n', 'w2_f502n', 'w2_f502n_mad', 'w2_f502n_n', 'w2_f547m', 'w2_f547m_mad', 'w2_f547m_n', 'w2_f555w', 'w2_f555w_mad', 'w2_f555w_n', 'w2_f569w', 'w2_f569w_mad', 'w2_f569w_n', 'w2_f588n', 'w2_f588n_mad', 'w2_f588n_n', 'w2_f606w', 'w2_f606w_mad', 'w2_f606w_n', 'w2_f622w', 'w2_f622w_mad', 'w2_f622w_n', 'w2_f631n', 'w2_f631n_mad', 'w2_f631n_n', 'w2_f656n', 'w2_f656n_mad', 'w2_f656n_n', 'w2_f658n', 'w2_f658n_mad', 'w2_f658n_n', 'w2_f673n', 'w2_f673n_mad', 'w2_f673n_n', 'w2_f675w', 'w2_f675w_mad', 'w2_f675w_n', 'w2_f702w', 'w2_f702w_mad', 'w2_f702w_n', 'w2_f785lp', 'w2_f785lp_mad', 'w2_f785lp_n', 'w2_f791w', 'w2_f791w_mad', 'w2_f791w_n', 'w2_f814w', 'w2_f814w_mad', 'w2_f814w_n', 'w2_f850lp', 'w2_f850lp_mad', 'w2_f850lp_n', 'w2_f953n', 'w2_f953n_mad', 'w2_f953n_n', 'w3_blank', 'w3_blank_mad', 'w3_blank_n', 'w3_f098m', 'w3_f098m_mad', 'w3_f098m_n', 'w3_f105w', 'w3_f105w_mad', 'w3_f105w_n', 'w3_f110w', 'w3_f110w_mad', 'w3_f110w_n', 'w3_f125w', 'w3_f125w_mad', 'w3_f125w_n', 'w3_f126n', 'w3_f126n_mad', 'w3_f126n_n', 'w3_f127m', 'w3_f127m_mad', 'w3_f127m_n', 'w3_f128n', 'w3_f128n_mad', 'w3_f128n_n', 'w3_f130n', 'w3_f130n_mad', 'w3_f130n_n', 'w3_f132n', 'w3_f132n_mad', 'w3_f132n_n', 'w3_f139m', 'w3_f139m_mad', 'w3_f139m_n', 'w3_f140w', 'w3_f140w_mad', 'w3_f140w_n', 'w3_f153m', 'w3_f153m_mad', 'w3_f153m_n', 'w3_f160w', 'w3_f160w_mad', 'w3_f160w_n', 'w3_f164n', 'w3_f164n_mad', 'w3_f164n_n', 'w3_f167n', 'w3_f167n_mad', 'w3_f167n_n', 'w3_f200lp', 'w3_f200lp_mad', 'w3_f200lp_n', 'w3_f218w', 'w3_f218w_mad', 'w3_f218w_n', 'w3_f225w', 'w3_f225w_mad', 'w3_f225w_n', 'w3_f275w', 'w3_f275w_mad', 'w3_f275w_n', 'w3_f280n', 'w3_f280n_mad', 'w3_f280n_n', 'w3_f300x', 'w3_f300x_mad', 'w3_f300x_n', 'w3_f336w', 'w3_f336w_mad', 'w3_f336w_n', 'w3_f343n', 'w3_f343n_mad', 'w3_f343n_n', 'w3_f350lp', 'w3_f350lp_mad', 'w3_f350lp_n', 'w3_f373n', 'w3_f373n_mad', 'w3_f373n_n', 'w3_f390m', 'w3_f390m_mad', 'w3_f390m_n', 'w3_f390w', 'w3_f390w_mad', 'w3_f390w_n', 'w3_f395n', 'w3_f395n_mad', 'w3_f395n_n', 'w3_f410m', 'w3_f410m_mad', 'w3_f410m_n', 'w3_f438w', 'w3_f438w_mad', 'w3_f438w_n', 'w3_f467m', 'w3_f467m_mad', 'w3_f467m_n', 'w3_f469n', 'w3_f469n_mad', 'w3_f469n_n', 'w3_f475w', 'w3_f475w_mad', 'w3_f475w_n', 'w3_f475x', 'w3_f475x_mad', 'w3_f475x_n', 'w3_f487n', 'w3_f487n_mad', 'w3_f487n_n', 'w3_f502n', 'w3_f502n_mad', 'w3_f502n_n', 'w3_f547m', 'w3_f547m_mad', 'w3_f547m_n', 'w3_f555w', 'w3_f555w_mad', 'w3_f555w_n', 'w3_f600lp', 'w3_f600lp_mad', 'w3_f600lp_n', 'w3_f606w', 'w3_f606w_mad', 'w3_f606w_n', 'w3_f621m', 'w3_f621m_mad', 'w3_f621m_n', 'w3_f625w', 'w3_f625w_mad', 'w3_f625w_n', 'w3_f631n', 'w3_f631n_mad', 'w3_f631n_n', 'w3_f645n', 'w3_f645n_mad', 'w3_f645n_n', 'w3_f656n', 'w3_f656n_mad', 'w3_f656n_n', 'w3_f657n', 'w3_f657n_mad', 'w3_f657n_n', 'w3_f658n', 'w3_f658n_mad', 'w3_f658n_n', 'w3_f665n', 'w3_f665n_f6', 'w3_f665n_f6_mad', 'w3_f665n_f6_n', 'w3_f665n_mad', 'w3_f665n_n', 'w3_f673n', 'w3_f673n_mad', 'w3_f673n_n', 'w3_f680n', 'w3_f680n_mad', 'w3_f680n_n', 'w3_f689m', 'w3_f689m_mad', 'w3_f689m_n', 'w3_f763m', 'w3_f763m_mad', 'w3_f763m_n', 'w3_f775w', 'w3_f775w_mad', 'w3_f775w_n', 'w3_f814w', 'w3_f814w_mad', 'w3_f814w_n', 'w3_f845m', 'w3_f845m_mad', 'w3_f845m_n', 'w3_f850lp', 'w3_f850lp_mad', 'w3_f850lp_n', 'w3_f953n', 'w3_f953n_mad', 'w3_f953n_n', 'w3_fq232n', 'w3_fq232n_mad', 'w3_fq232n_n', 'w3_fq243n', 'w3_fq243n_mad', 'w3_fq243n_n', 'w3_fq378n', 'w3_fq378n_mad', 'w3_fq378n_n', 'w3_fq387n', 'w3_fq387n_mad', 'w3_fq387n_n', 'w3_fq422m', 'w3_fq422m_mad', 'w3_fq422m_n', 'w3_fq436n', 'w3_fq436n_mad', 'w3_fq436n_n', 'w3_fq437n', 'w3_fq437n_mad', 'w3_fq437n_n', 'w3_fq492n', 'w3_fq492n_mad', 'w3_fq492n_n', 'w3_fq508n', 'w3_fq508n_mad', 'w3_fq508n_n', 'w3_fq575n', 'w3_fq575n_mad', 'w3_fq575n_n', 'w3_fq619n', 'w3_fq619n_mad', 'w3_fq619n_n', 'w3_fq634n', 'w3_fq634n_mad', 'w3_fq634n_n', 'w3_fq672n', 'w3_fq672n_mad', 'w3_fq672n_n', 'w3_fq674n', 'w3_fq674n_mad', 'w3_fq674n_n', 'w3_fq727n', 'w3_fq727n_mad', 'w3_fq727n_n', 'w3_fq750n', 'w3_fq750n_mad', 'w3_fq750n_n', 'w3_fq889n', 'w3_fq889n_mad', 'w3_fq889n_n', 'w3_fq906n', 'w3_fq906n_mad', 'w3_fq906n_n', 'w3_fq924n', 'w3_fq924n_mad', 'w3_fq924n_n', 'w3_fq937n', 'w3_fq937n_mad', 'w3_fq937n_n', 'w3_g102', 'w3_g102_mad', 'w3_g102_n', 'w3_g141', 'w3_g141_mad', 'w3_g141_n', 'w3_g280', 'w3_g280_mad', 'w3_g280_n']
----
dbo.catalog_image_metadata
    Summary list of Image processing metadata

Columns=['image_filedate', 'image_name', 'image_published', 'objid', 'pa_aperture', 'sexcat_aper1', 'sexcat_aper2', 'sexcat_filedate', 'sexcat_nobj', 'sexcat_ntot', 'sexcat_published']
----

Querying for Data#

As noted above, this view contains every filter known in the HSC, and can return each even if it is NULL for the given match (this can cause warnings in astroquery). In order to narrow results, one could query on individual filters where their value is not null, or only return certain of them.

Here we are searching for every row with data within a .1 degree circle of RA=129.23 and Dec=7.95, and returning a few columns to get an idea of what we have available.

results = HSC_service.run_async("""
SELECT TOP 10 MatchRA, MatchDec, TargetName, StartTime, StopTime
FROM dbo.SumMagAper2CatView
WHERE CONTAINS(POINT('ICRS', MatchRA, MatchDec),CIRCLE('ICRS',129.23,7.95,0.1))=1
  """)
results.to_table()
Table length=10
matchramatchdectargetnamestarttimestoptime
degdeg
float64float64objectobjectobject
129.23014159290657.950695449211841J083655+0757122009-12-07 16:10:34.3800002009-12-07 16:53:36.620000
129.2306344027777.950503873826787J083655+0757122009-12-07 16:10:34.3800002009-12-07 16:53:36.620000
129.23062989700647.9506171736020175J083655+0757122009-12-07 16:10:34.3800002009-12-07 16:53:36.620000
129.2309167229677.950108687927433J083655+0757122009-12-07 16:10:34.3800002009-12-07 16:53:36.620000
129.228982206424387.95042469130075J083655+0757122009-12-07 16:10:34.3800002009-12-07 16:53:36.620000
129.229110872567677.94912639772422J083655+0757122009-12-07 16:10:34.3800002009-12-07 16:53:36.620000
129.22875438346657.950874479922319J083655+0757122009-12-07 16:10:34.3800002009-12-07 16:53:36.620000
129.230212945360367.9516294527782065J083655+0757122009-12-07 16:10:34.3800002009-12-07 16:53:36.620000
129.228320142972367.949703958229378J083655+0757122009-12-07 16:10:34.3800002009-12-07 16:53:36.620000
129.229044241144467.951706894402595J083655+0757122009-12-07 16:10:34.3800002009-12-07 16:53:36.620000

We can also filter by start/stop time or any other column in the view:

results = HSC_service.run_async("""
SELECT TOP 10 MatchID, MatchRA, MatchDec, TargetName, StartTime, StopTime
FROM dbo.SumMagAper2CatView
WHERE 
CONTAINS(POINT('ICRS', MatchRA, MatchDec),CIRCLE('ICRS',129.23,7.95,0.1))=1
AND StartTime > '2015-01-01' AND StopTime < '2015-04-01'
""")
results.to_table()
Table length=10
matchidmatchramatchdectargetnamestarttimestoptime
degdeg
int64float64float64objectobjectobject
25671973129.232921076514977.994530012714008SDSSJ0837+08012015-03-15 14:22:48.9500002015-03-15 14:55:27.980000
27864401129.234986394266317.994779169533944SDSSJ0837+08012015-03-15 14:22:48.9500002015-03-15 15:07:16.973000
26083531129.240400454145547.994206594193051SDSSJ0837+08012015-03-15 14:22:48.9500002015-03-15 15:07:16.973000
26469969129.237978390730947.994726362108929SDSSJ0837+08012015-03-15 14:22:48.9500002015-03-15 15:07:16.973000
85404139129.22195740958337.995008272788658SDSSJ0837+08012015-03-15 14:22:48.9500002015-03-15 15:07:16.973000
88918217129.220487405976037.994958674698499SDSSJ0837+08012015-03-15 14:22:48.9500002015-03-15 15:07:16.973000
10629948129.23106628296447.996037541307772SDSSJ0837+08012015-03-15 14:22:48.9500002015-03-15 15:07:16.973000
20950138129.218969215620357.995096579949863SDSSJ0837+08012015-03-15 14:22:48.9500002015-03-15 15:07:16.973000
51540145129.23465950209037.996304692203746SDSSJ0837+08012015-03-15 14:22:48.9500002015-03-15 15:07:16.973000
62500828129.235963101088777.996289301829676SDSSJ0837+08012015-03-15 14:34:37.9400002015-03-15 15:07:16.973000

Use Case: Plotting a light curve for the most variable object in a field#

A use case example: search for objects with 10 or more ACS F475W magnitudes in a crowded field near IC 1613 (see HSC Use Case 3). Then get the individual A_F475W measurements for the most variable object in the list and plot the light curve. Note we must use asynchronous query mode for this example rather than synchronous, because it has a longer allowed timeout, which can be useful for large or complex queries.

results = HSC_service.run_async("""
SELECT MatchID, MatchRA, MatchDec, TargetName, NumImages, NumVisits, A_F475W, A_F475W_MAD, A_F475W_N
FROM dbo.SumMagAper2CatView
WHERE 
   A_F475W_N >= 10
   AND
   CONTAINS(POINT('ICRS', MatchRA, MatchDec),CIRCLE('ICRS',16.117562,2.162183,0.1))=1
   """)
HSC_results = results.to_table()
HSC_results
/opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/site-packages/pyvo/dal/query.py:325: DALOverflowWarning: Partial result set. Potential causes MAXREC, async storage space, etc.
  warn("Partial result set. Potential causes MAXREC, async storage space, etc.",
Table length=21720
matchidmatchramatchdectargetnamenumimagesnumvisitsa_f475wa_f475w_mada_f475w_n
degdegmagmag
int64float64float64objectint32int32float64float64int32
277389516.1175613799874042.162183863356067IC1613261423.483599662780760.1392002105712890612
4282143716.1174734165469222.1623009639591975IC1613241225.89660072326660.0763988494873046912
4339595616.117538911936452.162450000553497IC1613261424.5246496200561520.01009941101074218812
9934891416.1178790674491172.1623185494588673IC1613261423.8559007644653320.02075004577636718812
6776923516.117282892927172.161947424653218IC1613261421.6763496398925780.006299972534179687512
5260917016.1173917707434672.161720153122062IC1613261425.5146503448486330.0472002029418945312
1510115116.11762561746412.1627492019526584IC1613261425.1660995483398440.01230049133300781212
7839309316.11789321963392.162674625053314IC1613201226.465000152587890.0600996017456054712
9769811716.1177864628896262.1616046057098774IC1613241225.299550056457520.02699947357177734412
...........................
4813035416.0995082598058272.1242547489396593IC1613221226.728199958801270.0384998321533203112
8900580816.0987971530120972.124595528281905IC1613241226.5874004364013670.0639009475708007812
2740087216.1007070043466562.123581759229902IC1613221125.327100753784180.0445003509521484411
6542406416.100381279585832.123437806823172IC1613211126.5981006622314450.0356006622314453111
5992050916.1002425181804762.1234727017059543IC1613241226.653699874877930.0378999710083007812
2289058816.099013108553832.1236732912908427IC1613171126.6856994628906250.03760147094726562511
4773042516.0989648259397242.1234575027278906IC1613241225.139149665832520.01494979858398437512
10201243316.0989910481510952.1233534249841197IC1613221126.7621002197265620.0501003265380859411
222796116.0991741955765342.123200074969115IC1613241224.698099136352540.00909996032714843812
plt.rcParams.update({'font.size': 16})
plt.figure(1,(10,6))
plt.scatter(HSC_results['a_f475w'], HSC_results['a_f475w_mad'])
plt.xlabel('A_F475W')
plt.ylabel('A_F475W_MAD')
Text(0, 0.5, 'A_F475W_MAD')
../../../_images/07cd4cedf526b464197e0528f4b534338fd6c148286089d8fc5422e5543c4ab1.png
madvalues = HSC_results['a_f475w_mad']
i = np.argmax(madvalues)
print()
print(HSC_results[i])

matchid = HSC_results['matchid'][i]
details = HSC_service.run_async("""
SELECT SourceID, ImageID, SourceRA, SourceDec, D, Filter, Detector, MagAper2, StartMJD
FROM dbo.DetailedCatalog
WHERE 
   MatchID={}
   AND Detector='ACS/WFC' AND Filter='F475W' AND Det='Y'
ORDER BY StartMJD
""".format(matchid))
HSC_details = details.to_table()
HSC_details

plt.rcParams.update({'font.size': 16})
plt.figure(1,(10,6))
plt.scatter(HSC_details['StartMJD'], HSC_details['MagAper2'])
plt.xlabel('MJD')
plt.ylabel('A_F475W')
 matchid       matchra            matchdec      targetname numimages numvisits      a_f475w          a_f475w_mad     a_f475w_n
                 deg                deg                                               mag                mag                  
--------- ------------------ ------------------ ---------- --------- --------- ------------------ ------------------ ---------
102334412 16.130003898898327 2.1655152822114365     IC1613        26        14 20.970849990844727 0.5844001770019531        12
Text(0, 0.5, 'A_F475W')
../../../_images/80cdcf20c3539f92520560b1ffb004e034ab12e0032f8653b53c0e1840188f25.png

Use Case: Create a color magnitude diagram for the Small Magellanic Cloud#

For another example of using data from a TAP service, we start by doing a search around the SMC with a .25 degree radius for objects with ACS F555W and F814W measurements. HSC TAP will limit us to 100k responses by default. Note this is a large query that can take over a minute to run. See HSC Use Case 2 for more details.

Since our query exceeds the 100k response limit, we will get a warning that we are only seeing a partial result set. This partial set is sufficient for our purposes, so you can ignore it!

t0 = time.time()

results = HSC_service.run_async("""
SELECT MatchID, MatchRA, MatchDec, CI, A_F555W, A_F814W
FROM dbo.SumMagAper2CatView
WHERE A_F555W_N > 0 and A_F814W_N > 0
    AND CONTAINS(POINT('ICRS', MatchRA, MatchDec),CIRCLE('ICRS',13.1866,-72.8286,0.25))=1
   """)
HSC_results = results.to_table()
print("Query completed in {:.1f} sec".format(time.time()-t0))
HSC_results
Query completed in 95.3 sec
Table length=100000
matchidmatchramatchdeccia_f555wa_f814w
degdegmagmagmag
int64float64float64float64float64float64
8719389513.024000412138577-72.929688593265821.44358027128525724.84059906005859424.58449935913086
3577369913.025035586383748-72.92997947390341.02787036218760924.6124000549316424.349300384521484
10401752813.023555729947981-72.92979260158431.025370388855168821.87389945983886722.162900924682617
4053500713.0257520380231-72.930181960502521.450231505764855425.0737991333007824.825300216674805
6103259213.02421440278526-72.930095589264671.518950638947663222.52969932556152322.386699676513672
8932400313.02272444537175-72.929904717134351.016049362995006524.37330055236816424.10099983215332
10105759713.026053482371552-72.930371354864551.027777791023254425.46859931945800825.322099685668945
8020870013.024679741921718-72.930252880560810.964351881433416225.87730026245117225.44540023803711
8115836913.023183887830848-72.930077608540971.052345685016961522.4389991760253922.407800674438477
..................
3129156413.216750037744728-73.065461281468961.045046305214917322.64920043945312522.56599998474121
195007913.183951460664364-73.065626098393351.106759243541293624.1415004730224623.97480010986328
3441539113.22645919127738-73.065339391646941.061419737927707520.33279991149902319.793099403381348
10502527513.297977267668726-73.063366785422971.12040120142477524.0673007965087923.66629981994629
270081713.305409173846048-73.063054834642661.323487655616100823.96330070495605523.725099563598633
2749080213.208846313783647-73.065540493476961.019629670514000925.31819915771484425.075700759887695
7931487813.129966526893558-73.065048593185781.0111419507014924.781000137329124.54400062561035
7878585313.245981289154832-73.064990940237931.14364197224746524.36230087280273424.17329978942871
5997418113.989040704560631-72.822242091193660.888287000082157224.28269958496093823.828100204467773

Next, plot the color-magnitude diagram for the ~100k points retrieved from the database. This uses kernel density estimate for the crowded plot. As a preview for the demo, we are only working with 1/25th of the data so that the notebook executes quickly. You can switch the commented-out lines to call gaussian_kde for the full plot, which can take a few minutes to complete.

f555w = HSC_results['a_f555w']
f814w = HSC_results['a_f814w']
VminusI = f555w-f814w
CI = HSC_results['ci']
w = np.where((CI>0.9) & (CI<1.6) & (VminusI > -1.5) & (VminusI < 1.5))
print(len(w[0]),"points remaining after CI and V-I filtering")

# Calculate the point density
x = np.array(VminusI[w])
y = np.array(f555w[w])
xy = np.vstack([x,y])

t0 = time.time()

z = gaussian_kde(xy[:, ::25])(xy) #to do the KDE on only the full dataset, comment out this and uncomment below:
#z = gaussian_kde(xy)(xy) #uncomment this line to do the KDE on the full dataset

print("kde took {:.1f} sec".format(time.time()-t0))
87914 points remaining after CI and V-I filtering
kde took 2.8 sec
# Sort the points by density, so that the densest points are plotted last
idx = z.argsort()
x, y, z = x[idx], y[idx], z[idx]

plt.rcParams.update({'font.size': 16})
plt.figure(1,(12,10))
plt.scatter(x, y, c=z, s=2, cmap='plasma')
plt.autoscale(tight=True)
plt.xlabel('V-I')
plt.ylabel('V')
plt.gca().invert_yaxis()
plt.colorbar()
plt.text(.17,.93,'{:d} stars in SMC'.format(len(x)),
       horizontalalignment='center',
       transform=plt.gca().transAxes)
#plt.savefig("smc_colormag.png")
Text(0.17, 0.93, '87914 stars in SMC')
../../../_images/f5ae562298044cf37d6b90042e9742d7483f50f667af3daca87cceb6793defde.png

Additional Resources#

Table Access Protocol#

  • IVOA standard for RESTful web service access to tabular data

  • http://www.ivoa.net/documents/TAP/

Hubble Source Catalog v3#

  • Catalog created at MAST by combining the tens of thousands of visit-based source lists in the Hubble Legacy Archive (HLA) into a single master catalog.

  • https://archive.stsci.edu/hst/hsc/

Astronomical Query Data Language (2.0)#

  • IVOA standard for querying astronomical data in tabular format, with geometric search support

  • http://www.ivoa.net/documents/latest/ADQL.html

PyVO#

  • an affiliated package for astropy

  • find and retrieve astronomical data available from archives that support standard IVOA virtual observatory service protocols.

  • https://pyvo.readthedocs.io/en/latest/index.html


About this Notebook#

Authors: Rick White & Theresa Dower, STScI Archive Scientist & Software Engineer. Additional edits by Thomas Dutkiewicz.

Last Updated: May 2024


STScI logo