Accessing the Gaia and Pan-STARRS catalogs using Python

The recently available Gaia and Pan-STARRS data releases are certainly interesting to the majority of astronomers for various reasons. If only there was a way to load the catalog data into Python…

Gaia DR1 catalog access using astroquery.vizier

The Gaia DR1 catalog is accessible through Vizier, which in turn can be accessed using the astroquery.vizier module, providing a comfortable astropy.table output. A simple query could look like this:

from astroquery.vizier import Vizier 
import astropy.units as u 
import astropy.coordinates as coord

def gaia_query(ra_deg, dec_deg, rad_deg, maxmag=20, 
    Query Gaia DR1 @ VizieR using astroquery.vizier
    parameters: ra_deg, dec_deg, rad_deg: RA, Dec, field 
                                          radius in degrees
                maxmag: upper limit G magnitude (optional)
                maxsources: maximum number of sources
    returns: astropy.table object
    vquery = Vizier(columns=['Source', 'RA_ICRS', 'DE_ICRS', 
                                    ("<%f" % maxmag)}, 
                    row_limit = maxsources) 
    field = coord.SkyCoord(ra=ra_deg, dec=dec_deg, 
                           unit=(u.deg, u.deg), 
    return vquery.query_region(field, 
                               width=("%fd" % rad_deg), 

# Example query
print(gaia_query(12.345, 67.89, 0.1))

Other columns are available, too. Simply add their names as provided here to the ‘columns’ list.

Pan-STARRS DR1 catalog access

The Pan-STARRS DR1 catalog resides at MAST, which unfortunately does not yet have an astroquery interface. Hence, we have to use a different approach: we download the data as an xml file and read that in using astroquery, again providing an astropy.table object:

import requests 
from import parse_single_table 
def panstarrs_query(ra_deg, dec_deg, rad_deg, mindet=1, 
    Query Pan-STARRS DR1 @ MAST
    parameters: ra_deg, dec_deg, rad_deg: RA, Dec, field 
                                          radius in degrees
                mindet: minimum number of detection (optional)
                maxsources: maximum number of sources
                server: servername
    returns: astropy.table object
    r = requests.get(server, 
    params= {'RA': ra_deg, 'DEC': dec_deg, 
             'SR': rad_deg, 'max_records': maxsources, 
             'outputformat': 'VOTable', 
             'ndetections': ('>%d' % mindet)}) 
    # write query data into local file 
    outf = open('panstarrs.xml', 'w') 
    # parse local file into astropy.table object 
    data = parse_single_table('panstarrs.xml')
    return data.to_table(use_names_over_ids=True) 
# Example query
print(panstarrs_query(12.345, 67.89, 0.1))

The file download makes this query significantly slower than comparable astroquery routines. Please note that STScI currently limits the Pan-STARRS queries on their servers to field radii smaller than 0.5 degrees.