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
from astroquery.simbad import Simbad
from astropy import coordinates
from astropy import units as u
result1 = Simbad.query_object('M 31')
result1
result2 = Simbad.query_region("05h35m17.3s -05d23m28s", radius=1*u.arcmin)
result2
co = coordinates.SkyCoord(l=31.0087, b=14.0627,
unit=(u.deg, u.deg),
frame='galactic')
result3 = Simbad.query_region(co)
result3
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
Simbad.ROW_LIMIT = 100
esocat = Simbad.query_catalog('eso')
esocat
ngccat = Simbad.query_catalog('ngc')
ngccat
In SIMBAD, you can also query a publication to find the sources
gins2012 = Simbad.query_bibobj('2012ApJ...758L..29G')
gins2012
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.
customSimbad = Simbad()
customSimbad.ROW_LIMIT = 100
customSimbad.add_votable_fields('bibcodelist(1800-2014)')
gins2012b = customSimbad.query_bibobj('2012ApJ...758L..29G')
gins2012b
There are archive query services that return data in addition to catalogs. ESO is among these.
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
from astroquery.eso import Eso
Eso.list_instruments()
In order to figure out how to construct a query, you can open the form directly
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
.
Eso.query_instrument('kmos', help=True)
result = Eso.query_instrument('xshooter', pi_coi='manara')
result
result.colnames
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.
set(result['ProgId'])
The DP.ID
row is the Data Product Identifier, which can be used to retrieve (download) the data
result['DP.ID']
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!
Eso.login('aginsburg')
headers = Eso.get_headers(result['DP.ID'][0:1])
Eso.data_retrieval(result['DP.ID'][0:1])
The LAMDA, Splatalogue, and NIST services query online resources related to spectroscopic lines.
from astroquery.nist import Nist
table = Nist.query(4000 * u.AA, 7000 * u.AA, linename="H I")
table
from astroquery.splatalogue import Splatalogue
Splatalogue provides access to mm lines.
just_CO = Splatalogue.get_species_ids(' CO ') # note the spaces
just_CO
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
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.
from astroquery.vizier import Vizier
velocity_catalogs = Vizier(columns=['all'], ucd='(spect.dopplerVeloc*|phys.veloc*)',
keywords=['Radio','IR'], row_limit=500)
velocity_catalogs
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
agn = Vizier(catalog="VII/258/vv10").query_constraints(Vmag="10.0..11.0")[0]
agn
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"\).
guide = Vizier(catalog="II/246", column_filters={"Kmag":"<9.0"}).query_region(agn, radius="30s", inner_radius="2s")[0]
guide
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.
from astropy import table
# 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
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
vlbacal = Vizier.find_catalogs('Petrov VLBA Calibrator')
{k:v.description for k,v in vlbacal.iteritems()}
vlbacal_matches = Vizier(catalog=vlbacal.keys()).query_region(coord_tbl, radius=2*u.deg)
vlbacal_matches
vlbacal_matches[0]
vlbacal_matches[2]