Astroquery

This is the documentation for the Astroquery coordinated package of astropy.

Code and issue tracker are on GitHub.

If you use astroquery, please cite the paper Ginsburg, Sipőcz, Brasseur et al 2019.

Introduction

Astroquery is a set of tools for querying astronomical web forms and databases.

There are two other packages with complimentary functionality as Astroquery: pyvo is an Astropy affiliated package, and Simple-Cone-Search-Creator to generate a cone search service complying with the IVOA standard. They are more oriented to general virtual observatory discovery and queries, whereas Astroquery has web service specific interfaces.

Installation

Uniquely in the Astropy ecosystem, Astroquery is operating with a continuous deployment model. It means that a release is instantaneously available after a pull request has been merged. These releases are automatically uploaded to PyPI, and therefore the latest version of astroquery can be pip installed. The version number of these automated releases contain the 'dev' tag, thus pip needs to be told to look for these releases during an upgrade, using the --pre install option. If astroquery is already installed, please make sure you use the --upgrade (or -U) install option as well.

$ python -m pip install -U --pre astroquery

To install all the mandatory and optional dependencies add the [all] identifyer to the pip command above (or use [docs] or [test] for the dependencies required to build the documentation or run the tests):

$ python -m pip install -U --pre astroquery[all]

In addition to the automated releases, we also keep doing regular, tagged version for maintenance and packaging purposes. These can be pip installed without the --pre option and are also available from the conda-forge conda channel.

$ conda install -c conda-forge astroquery

To review recent changes and fixes, please have a look at the changelog:

Building from source

The development version can be obtained and installed from github:

$ # If you have a github account:
$ git clone git@github.com:astropy/astroquery.git
$ # If you do not:
$ git clone https://github.com/astropy/astroquery.git
$ cd astroquery
$ python -m pip install .

To install all the optional dependencies (listed below), add the option [all]. To install dependencies required for running the tests locally use [test], and for documentation build [docs]. If you would like to modify the source, you can install astroquery in editable mode, which means you don’t need to rerun the install command after you made the changes.

To install all dependencies, including those required for local testing and building the documentation, in editable mode:

$ python -m pip install -e .[all,test,docs]

Requirements

Astroquery works with Python 3.7 or later.

The following packages are required for astroquery installation & use:

and for running the tests:

The following packages are optional dependencies and are required for the full functionality of the mocserver, alma, and xmatch modules:

For the vamdc module:

  • vamdclib install version from personal fork: python -m pip install git+https://github.com/keflavich/vamdclib-1.git

The following packages are optional dependencies and are required for the full functionality of the mast module:

Using astroquery

All astroquery modules are supposed to follow the same API. In its simplest form, the API involves queries based on coordinates or object names. Some simple examples, using SIMBAD:

>>> from astroquery.simbad import Simbad
>>> result_table = Simbad.query_object("m1")
>>> result_table.pprint()
MAIN_ID     RA        DEC    ...    COO_BIBCODE      SCRIPT_NUMBER_ID
         "h:m:s"    "d:m:s"  ...
------- ---------- --------- ... ------------------- ----------------
  M   1 05 34 30.9 +22 00 53 ... 1995AuJPh..48..143S                1

All query tools allow coordinate-based queries:

>>> from astropy import coordinates
>>> import astropy.units as u
>>> # works only for ICRS coordinates:
>>> c = coordinates.SkyCoord("05h35m17.3s -05d23m28s", frame='icrs')
>>> r = 5 * u.arcminute
>>> result_table = Simbad.query_region(c, radius=r)
>>> result_table.pprint(show_unit=True, max_width=80, max_lines=5)
        MAIN_ID               RA      ...     COO_BIBCODE     SCRIPT_NUMBER_ID
                           "h:m:s"    ...
----------------------- ------------- ... ------------------- ----------------
        NAME Ori Region   05 35 17.30 ...                                    1
                    ...           ... ...                 ...              ...
2MASS J05353573-0525256 05 35 35.7755 ... 2020yCat.1350....0G                1
           V* V2114 Ori 05 35 01.6720 ... 2020yCat.1350....0G                1
Length = 3272 rows

For additional guidance and examples, read the documentation for the individual services below.

Default configuration file

To customize this, copy the default configuration to $HOME/.astropy/config/astroquery.cfg, uncomment the relevant configuration item(s), and insert your desired value(s).

Caching

By default Astroquery employs query caching with a timeout of 1 week. The user can clear their cache at any time, as well as suspend cache usage, and change the cache location. Caching persists between Astroquery sessions. If you know the service you are using has released new data recently, or if you believe you are not recieving the newest data, try clearing the cache.

Service specific settings

The Astroquery cache location is specific to individual services, so each service’s cache should be managed invidually. The cache location can be viewed with the following command (using Simbad as an example):

>>> from astroquery.simbad import Simbad
>>> print(Simbad.cache_location)   
/Users/username/.astropy/cache/astroquery/Simbad

Each service’s cache is cleared with the clear_cache function within that service.

>>> import os
>>> from astroquery.simbad import Simbad
...
>>> os.listdir(Simbad.cache_location)   
['8abafe54f49661237bdbc2707179df53b6ee0d74ca6b7679c0e4fac0.pickle',
'0e4766a7673ddfa4adaee2cfa27a924ed906badbfae8cc4a4a04256c.pickle']
>>> Simbad.clear_cache()
>>> os.listdir(Simbad.cache_location)   
[]

Astroquery-wide settings

Whether caching is active and when cached files expire are controlled centrally through the astroquery cache_conf module, and shared among all services. Astroquery uses the Astropy configuration infrastructure, information about temporarily or permanently changing configuration values can be found here.

>>> from astroquery import cache_conf
...
>>> # Is the cache active?
>>> print(cache_conf.cache_active)
True
>>> # Cache timout in seconds
>>> print(cache_conf.cache_timeout)
604800

Available Services

The following modules have been completed using a common API:

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

There are also subpackages that serve as the basis of others.

Catalog, Archive, and Other

A second index of the services by the type of data they serve. Some services perform many tasks and are listed more than once.

Catalogs

The first serve catalogs, which generally return one row of information for each source (though they may return many catalogs that each have one row for each source)

Archives

Archive services provide data, usually in FITS images or spectra. They will generally return a table listing the available data first.

Simulations

These services query databases of simulated or synthetic data:

Line List Services

There are several web services that provide atomic or molecular line lists, as well as cross section and collision rates. Those services are:

Other

There are other astronomically significant services, that don’t fit the above categories. Those services are here:

Topical Collections

Some services focusing on similar topics are also collected in topical submodules:

Developer documentation

The modules and their maintainers are listed on the Maintainers wiki page.

The Astroquery API Specification is intended to be kept as consistent as possible, such that any web service can be used with a minimal learning curve imposed on the user.

The following Astroquery modules are mostly meant for internal use of services in Astroquery, you can use them for your scripts, but we don’t guarantee API stability.

To debug astroquery, logging level can be configured with the following:

>>> from astroquery import log
>>> log.setLevel(level)

If level is set to "DEBUG", then HTTP requests are logged. If level is set to "TRACE", then HTTP requests and responses are logged.

License

Astroquery is licensed under a 3-clause BSD style license - see Licenses.