Affiliated Package: Astroquery

Astroquery is an Astropy-affiliated package that contains a collection of tools to access online Astronomical data. To install it, do:

pip install astroquery

The following modules have been completed using a common API:

  • SIMBAD Queries (astroquery.simbad)
  • VizieR Queries (astroquery.vizier)
  • IRSA Dust Extinction Service Queries (astroquery.irsa_dust)
  • NED Queries (astroquery.ned)
  • Splatalogue Queries (astroquery.splatalogue)
  • IRSA Image Server program interface (IBE) Queries (astroquery.ibe)
  • IRSA Queries (astroquery.irsa)
  • UKIDSS Queries (astroquery.ukidss)
  • MAGPIS Queries (astroquery.magpis)
  • NRAO Queries (astroquery.nrao)
  • Besancon Queries (astroquery.besancon)
  • NIST Queries (astroquery.nist)
  • NVAS Queries (astroquery.nvas)
  • GAMA Queries (astroquery.gama)
  • ESO Queries (astroquery.eso)
  • xMatch Queries (astroquery.xmatch)
  • Atomic Line List (astroquery.atomic)
  • ALMA Queries (astroquery.alma)
  • Skyview Queries (astroquery.skyview)
  • NASA ADS Queries (astroquery.nasa_ads)
  • HEASARC Queries (astroquery.heasarc)
  • LCOGT Queries (astroquery.lcogt)

These others are functional, but do not follow a common & consistent API:

  • Fermi Queries (astroquery.fermi)
  • SDSS Queries (astroquery.sdss)
  • ALFALFA Queries (astroquery.alfalfa)
  • Spitzer Heritage Archive (astroquery.sha)
  • LAMDA Queries (astroquery.lamda)
  • OGLE Queries (astroquery.ogle)
  • Open Exoplanet Catalogue(astroquery.open_exoplanet_catalogue)
  • CosmoSim Queries (astroquery.cosmosim)

SIMBAD

As an example, let's run a SIMBAD query:

In [1]:
from astropy import units as u
from astroquery.simbad import Simbad
In [2]:
r = Simbad.query_region('m42', radius=3. * u.arcmin)
In [3]:
r.colnames
Out[3]:
['MAIN_ID',
 'RA',
 'DEC',
 'RA_PREC',
 'DEC_PREC',
 'COO_ERR_MAJA',
 'COO_ERR_MINA',
 'COO_ERR_ANGLE',
 'COO_QUAL',
 'COO_WAVELENGTH',
 'COO_BIBCODE']
In [4]:
r
Out[4]:
<Table masked=True length=2266>
MAIN_IDRADECRA_PRECDEC_PRECCOO_ERR_MAJACOO_ERR_MINACOO_ERR_ANGLECOO_QUALCOO_WAVELENGTHCOO_BIBCODE
"h:m:s""d:m:s"masmasdeg
objectstr13str13int16int16float32float32int16str1str1object
NAME ORI REGION05 35 17.30-05 23 28.066----0DO
M 4205 35 17.3-05 23 28557500.0007500.00090D1981MNRAS.194..693L
[OW94] 172-23705 35 17.20-05 23 26.866----0D1999AJ....117.1375S
[OW94] 172-32705 35 17.20-05 23 26.866----0D1996AJ....111..846O
DOH 7 175-32805 35 17.5-05 23 2855----0D2004AJ....127.3456D
MAX 12605 35 17.11-05 23 29.366----0DI2005AJ....129.1534R
DOH 7 171-32705 35 17.1-05 23 2755----0D2004AJ....127.3456D
MAX 12505 35 17.11-05 23 26.666----0DI2005AJ....129.1534R
[OW94] 171-32605 35 17.1-05 23 2655----0D2004AJ....127.3456D
.................................
TPSC 805 35 18.9148-05 20 30.94188300.000300.00090CM2011ApJ...733...50M
[YKS96] 805 35 11.0-05 26 00553000.0003000.00090D
2MASS J05350705-052500505 35 07.05-05 25 00.56680.00080.00090BI2003yCat.2246....0C
[LB2000] 1905 35 13.0-05 20 4155----0D2000MNRAS.315...11L
2MASS J05351814-052029505 35 18.142-05 20 29.5277170.000160.00096BI2003yCat.2246....0C
COUP J053514.1-05262005 35 14.191-05 26 20.8377----0D2005ApJS..160..319G
JW 37705 35 12.272-05 20 45.247760.00060.00090BI2003yCat.2246....0C
MLLA 91905 35 12.59-05 20 42.966150.000150.00090CO2009A&A...502..883R
[NW2007] OrionAN-0535146-5262305 35 14.6-05 26 2355----0Em2007MNRAS.374.1413N
MLLA 94505 35 19.69-05 20 31.666----0CO2009ApJS..183..261D

SDSS

In the following example we are looking for the SDSS photometry for a small subset of objects from the WTS survey and aim to have get a table that contains both the UKIRT JHK and SDSS griz values.

In [5]:
from astropy.table import Table, join
from astropy.coordinates import SkyCoord

from astroquery.sdss import SDSS
/sw/lib/python3.4/site-packages/astroquery/sdss/__init__.py:28: UserWarning: Experimental: SDSS has not yet been refactored to have its API match the rest of astroquery (but it's nearly there).
  warnings.warn("Experimental: SDSS has not yet been refactored to have its API "
In [6]:
input_objects = Table.read('data/WTS_sources.txt', format='ascii')
input_objects
Out[6]:
<Table length=10>
obj_idRADECJJ_errHH_errKK_err
str11float64float64float64float64float64float64float64float64
03a_1_021520.938573837280.68325656652517.98084912010.020752046257317.54309906950.032683864235917.41665526070.0527142696083
03a_1_021530.9385837316510.68369197845518.06486787890.021765211597117.53919817190.032562561333216.93712630640.0348142385483
03a_1_021560.9385846257210.68199521303217.97325029740.020676568150517.23344879580.025255994871316.41996361090.0226280763745
03a_1_021580.9385632276540.68335580825820.71727619450.140657648444infnaninfnan
03a_1_021600.9385553002360.68150913715421.24907352790.224075511098infnaninfnan
03a_1_021620.938552141190.68087726831419.49662304620.054812896996718.83120298480.10137414932318.34306835140.120554670691
03a_1_021660.938557028770.6831280589119.95685989670.076809950172918.93877285940.11124093085518.71911553540.168692871928
03a_1_021700.9385808110240.68102210760118.02838515130.02136448025717.9397176860.046096920967117.55517340090.059726126492
03a_1_021730.9385690689090.68211364746120.39658795640.10850790143infnan18.7838367080.179137885571
03a_1_021770.9385467171670.68300420045919.89410168960.073206841945619.76808238920.23565106093918.84233135470.188655138016
In [7]:
coords = SkyCoord(input_objects['RA'], input_objects['DEC'],
                         unit=u.rad)
photoobj_fields = ['ra', 'dec',
                   'psfMag_g', 'psfMagErr_g',
                   'psfMag_r', 'psfMagErr_r',
                   'psfMag_i', 'psfMagErr_i',
                   'psfMag_z', 'psfMagErr_z']
In [8]:
sdss_match = SDSS.query_crossid(coords, photoobj_fields=photoobj_fields,
                                obj_names=input_objects['obj_id'])
sdss_match
Out[8]:
<Table length=10>
obj_idobjIDradecpsfMag_gpsfMagErr_gpsfMag_rpsfMagErr_rpsfMag_ipsfMagErr_ipsfMag_zpsfMagErr_zobj_id1type
bytes11int64float64float64float64float64float64float64float64float64float64float64int64bytes6
03a_1_02152123766108320091433753.776347569939.147705269820.225180.0171843119.499910.0140062519.167980.0136399619.034620.034768651237661083200914337STAR
03a_1_02153123766105528343140453.776862452439.172638499822.041970.0591880121.158740.0404068420.591060.0351681320.274020.093556911237661055283431404GALAXY
03a_1_02156123766108320091542553.776954305839.075442301223.305840.15141221.499130.049491720.601640.0344121520.057990.068795991237661083200915425GALAXY
03a_1_02158123766108320091585453.775770198439.153373773725.17510.395202223.54050.269645922.597640.184027521.62670.23788351237661083200915854STAR
03a_1_02160123766108320091600753.775257412139.047612289524.434890.332302622.849130.151665122.572560.175898422.032860.30593581237661083200916007GALAXY
03a_1_02162123766108320091629753.775126674639.011425973825.151130.395093424.246550.400877122.048180.112996620.988270.14502461237661083200916297STAR
03a_1_02166123766108320091508653.775363775339.140333401122.9540.113517922.059930.0795132521.771630.0902960721.05961.0052571237661083200915086GALAXY
03a_1_02170123766108320091513553.776705340839.019697688521.517450.0373042220.828180.0298385920.574010.0342391720.356210.087182281237661083200915135GALAXY
03a_1_02173123766108320091372753.776055786439.082228932524.255530.715522723.261160.213894922.288270.138453922.573370.46840041237661083200913727GALAXY
03a_1_02177123766108320091509553.774772161439.133235678721.738890.0430237521.120620.037152220.869090.0422116120.691240.11347991237661083200915095STAR
In [9]:
result = join(input_objects, sdss_match, keys='obj_id', join_type='left')
result
Out[9]:
<Table length=10>
obj_idRADECJJ_errHH_errKK_errobjIDradecpsfMag_gpsfMagErr_gpsfMag_rpsfMagErr_rpsfMag_ipsfMagErr_ipsfMag_zpsfMagErr_zobj_id1type
str14float64float64float64float64float64float64float64float64int64float64float64float64float64float64float64float64float64float64float64int64bytes6
03a_1_021520.938573837280.68325656652517.98084912010.020752046257317.54309906950.032683864235917.41665526070.0527142696083123766108320091433753.776347569939.147705269820.225180.0171843119.499910.0140062519.167980.0136399619.034620.034768651237661083200914337STAR
03a_1_021530.9385837316510.68369197845518.06486787890.021765211597117.53919817190.032562561333216.93712630640.0348142385483123766105528343140453.776862452439.172638499822.041970.0591880121.158740.0404068420.591060.0351681320.274020.093556911237661055283431404GALAXY
03a_1_021560.9385846257210.68199521303217.97325029740.020676568150517.23344879580.025255994871316.41996361090.0226280763745123766108320091542553.776954305839.075442301223.305840.15141221.499130.049491720.601640.0344121520.057990.068795991237661083200915425GALAXY
03a_1_021580.9385632276540.68335580825820.71727619450.140657648444infnaninfnan123766108320091585453.775770198439.153373773725.17510.395202223.54050.269645922.597640.184027521.62670.23788351237661083200915854STAR
03a_1_021600.9385553002360.68150913715421.24907352790.224075511098infnaninfnan123766108320091600753.775257412139.047612289524.434890.332302622.849130.151665122.572560.175898422.032860.30593581237661083200916007GALAXY
03a_1_021620.938552141190.68087726831419.49662304620.054812896996718.83120298480.10137414932318.34306835140.120554670691123766108320091629753.775126674639.011425973825.151130.395093424.246550.400877122.048180.112996620.988270.14502461237661083200916297STAR
03a_1_021660.938557028770.6831280589119.95685989670.076809950172918.93877285940.11124093085518.71911553540.168692871928123766108320091508653.775363775339.140333401122.9540.113517922.059930.0795132521.771630.0902960721.05961.0052571237661083200915086GALAXY
03a_1_021700.9385808110240.68102210760118.02838515130.02136448025717.9397176860.046096920967117.55517340090.059726126492123766108320091513553.776705340839.019697688521.517450.0373042220.828180.0298385920.574010.0342391720.356210.087182281237661083200915135GALAXY
03a_1_021730.9385690689090.68211364746120.39658795640.10850790143infnan18.7838367080.179137885571123766108320091372753.776055786439.082228932524.255530.715522723.261160.213894922.288270.138453922.573370.46840041237661083200913727GALAXY
03a_1_021770.9385467171670.68300420045919.89410168960.073206841945619.76808238920.23565106093918.84233135470.188655138016123766108320091509553.774772161439.133235678721.738890.0430237521.120620.037152220.869090.0422116120.691240.11347991237661083200915095STAR
In [10]:
import matplotlib.pylab as plt
%matplotlib inline

plt.rc('figure', figsize=(10, 5))
plt.ylabel('J')
plt.xlabel('g-z')
plt.plot(result['psfMag_g']-result['psfMag_z'], result['J'], 'x')
Out[10]:
[<matplotlib.lines.Line2D at 0x1083b4128>]

Practical Exercise

Go to the documentation and try out a query interface for a service that might be relevant to you!