In [1]:
import warnings
warnings.filterwarnings('ignore',message='profile')
warnings.filterwarnings('ignore',message='_astropy_init')
warnings.filterwarnings('ignore',message='ConfigurationDefaultMissingWarning ')
Astroquery is a set of related tools for querying different astronomical database services, e.g. SIMBAD, VizieR, and IRSA-IPAC, and for retrieving data from archives, e.g. the ESO, IRSA, and NRAO archives. It also includes tools for querying other astronomy-related databases such as line-list servers at NIST (primarily for optical/NIR electronic transitions) and Splatalogue for mm/radio molecular transitions.
Each astroquery tool includes a query
method, or a set of query_*
methods, depending on the capabilities the service offers.
For example, SIMBAD supports queries by source name (query_object
) and by region (query_region
). The returned values are always astropy tables
In [2]:
from astroquery.simbad import Simbad
from astropy import coordinates
from astropy import units as u
In [3]:
result1 = Simbad.query_object('M 31')
result1
Out[3]:
In [4]:
result2 = Simbad.query_region("05h35m17.3s -05d23m28s", radius=1*u.arcmin)
result2
Out[4]:
In [5]:
co = coordinates.SkyCoord(l=31.0087, b=14.0627,
unit=(u.deg, u.deg),
frame='galactic')
result3 = Simbad.query_region(co)
result3
Out[5]:
There are also other query tools for some services, e.g. SIMBAD has a query_catalog
feature that allows you to query named catalogs, e.g. the NGC catalog or the ESO catalog
In [6]:
Simbad.ROW_LIMIT = 100
esocat = Simbad.query_catalog('eso')
esocat
Out[6]:
In [36]:
ngccat = Simbad.query_catalog('ngc')
ngccat
Out[36]:
In SIMBAD, you can also query a publication to find the sources
In [7]:
gins2012 = Simbad.query_bibobj('2012ApJ...758L..29G')
gins2012
Out[7]:
Finally, you can modify the default parameters of the query tool, such as the TIMEOUT
(the maximum wait time before deciding the query has failed) and the ROW_LIMIT
(the maximum number of entries returned) by creating a new object. You can also tell SIMBAD to return additional information, e.g. the number of citations for each object.
In [8]:
customSimbad = Simbad()
customSimbad.ROW_LIMIT = 100
customSimbad.add_votable_fields('bibcodelist(1800-2014)')
gins2012b = customSimbad.query_bibobj('2012ApJ...758L..29G')
gins2012b
Out[8]:
The ESO service has the following methods:
list_instruments
to list the available instruments that can be queriedlist_surveys
lists the available large public surveysquery_instrument
queries for data sets from a specific instrumentquery_surveys
does the same for surveysget_headers
gets header information for any datasets listed from a previous querylogin
logs you in with your username, which is required for any data retrieval (even public data)retrieve_datasets
or (deprecated) data_retrieval
allows you to stage and download any data set your username is allowed to accessQueries are cached, so repeating them should be fast. Downloaded data is also cached to the Eso.cache_location
In [9]:
from astroquery.eso import Eso
In [10]:
Eso.list_instruments()
Out[10]:
In order to figure out how to construct a query, you can open the form directly
In [11]:
Eso.query_instrument('kmos', open_form=True)
or use the help
keyword. The printout will then show what keywords correspond to each form name. For example, the keyword pi_coi
corresponds to the form box PI/CoI Name
.
In [12]:
Eso.query_instrument('kmos', help=True)
In [13]:
result = Eso.query_instrument('xshooter', pi_coi='manara')
result
Out[13]:
In [14]:
result.colnames
Out[14]:
A simple python trick: a set
is an unordered collection of unique objects (just like in math). np.unique
does the same thing, but returns a numpy array, which is ordered.
In [15]:
set(result['ProgId'])
Out[15]:
The DP.ID
row is the Data Product Identifier, which can be used to retrieve (download) the data
In [16]:
result['DP.ID']
Out[16]:
Eso.login
will log you in with your username. It uses the keyring
package to store your username/password if you so choose. If not, you will be asked to enter your password.
Warning: If you're using an ipython notebook, the password entry form will appear in the terminal, not in the notebook!
In [17]:
Eso.login('aginsburg')
Out[17]:
In [18]:
headers = Eso.get_headers(result['DP.ID'][0:1])
In [19]:
Eso.data_retrieval(result['DP.ID'][0:1])
Out[19]:
In [20]:
from astroquery.nist import Nist
In [21]:
table = Nist.query(4000 * u.AA, 7000 * u.AA, linename="H I")
table
Out[21]:
In [22]:
from astroquery.splatalogue import Splatalogue
Splatalogue provides access to mm lines.
In [23]:
just_CO = Splatalogue.get_species_ids(' CO ') # note the spaces
just_CO
Out[23]:
In [24]:
CO2to1 = Splatalogue.query_lines(1*u.mm, 2*u.mm, chemical_name=" CO ",
only_NRAO_recommended=True,
energy_max=50, energy_type='eu_k')
CO2to1
Out[24]:
Vizier is the main depository of published catalogs. It provides some very powerful interfaces including an x-match (cross-matching) service.
Vizier queries return TableLists of tables instead of individual tables.
In [25]:
from astroquery.vizier import Vizier
In [26]:
velocity_catalogs = Vizier(columns=['all'], ucd='(spect.dopplerVeloc*|phys.veloc*)',
keywords=['Radio','IR'], row_limit=500)
velocity_catalogs
Out[26]:
A particularly powerful example - search for guide stars within a set radius of your target sources.
The following queries only a specific catalog of AGN - VII/258/vv10
- for sources with $10 < M_V < 11$.
Note the trailing [0]
because the return is a TableList
In [27]:
agn = Vizier(catalog="VII/258/vv10").query_constraints(Vmag="10.0..11.0")[0]
agn
Out[27]:
The guide star catalog, II/246
, is then queried with the restriction that the guide star must have $M_K<9$ around the selected AGN, given that the distance between the guide star and the AGN is $2" < r < 30"$.
In [28]:
guide = Vizier(catalog="II/246", column_filters={"Kmag":"<9.0"}).query_region(agn, radius="30s", inner_radius="2s")[0]
guide
Out[28]:
The only requirement for this type of query is that the target catalog (agn
in the above example) contain the columns _RAJ2000
and _DEJ2000
, which all Vizier tables do by default. You can make your own from any valid coordinate set.
In [29]:
from astropy import table
In [30]:
# Some well-known Galactic objects
coordinate_list = coordinates.SkyCoord([(0.0,0.0),(49.488,-0.39),(43.1,0.07)] * u.deg, frame='galactic')
coordinate_list
Out[30]:
In [31]:
coord_tbl = table.Table(data=[coordinate_list.fk5.ra.deg,
coordinate_list.fk5.dec.deg],
names=('_RAJ2000', '_DEJ2000')
)
coord_tbl['_RAJ2000'].unit = u.deg
coord_tbl['_DEJ2000'].unit = u.deg
coord_tbl
Out[31]:
In [32]:
vlbacal = Vizier.find_catalogs('Petrov VLBA Calibrator')
{k:v.description for k,v in vlbacal.iteritems()}
Out[32]:
In [33]:
vlbacal_matches = Vizier(catalog=vlbacal.keys()).query_region(coord_tbl, radius=2*u.deg)
vlbacal_matches
Out[33]:
In [34]:
vlbacal_matches[0]
Out[34]:
In [35]:
vlbacal_matches[2]
Out[35]: