diff --git a/astroquery/heasarc/__init__.py b/astroquery/heasarc/__init__.py new file mode 100644 index 0000000000..ebce1ba20b --- /dev/null +++ b/astroquery/heasarc/__init__.py @@ -0,0 +1,35 @@ +# Licensed under a 3-clause BSD style license - see LICENSE.rst +""" +HEASARC +------- + +The High Energy Astrophysics Science Archive Research Center (HEASARC) +is the primary archive for NASA's (and other space agencies') missions. + +The initial version of this was coded in a sprint at the +"Python in astronomy" workshop in April 2015 by Jean-Christophe Leyder, +Abigail Stevens, Antonio Martin-Carrillo and Christoph Deil. +""" +from astropy import config as _config + + +class Conf(_config.ConfigNamespace): + """ + Configuration parameters for `astroquery.heasarc`. + """ + server = _config.ConfigItem( + ['http://heasarc.gsfc.nasa.gov/cgi-bin/W3Browse/w3query_noredir.pl'], + 'Name of the HEASARC server to use.' + ) + timeout = _config.ConfigItem( + 30, + 'Time limit for connecting to HEASARC server.' + ) + +conf = Conf() + +from .core import Heasarc, HeasarcClass + +__all__ = ['Heasarc', 'HeasarcClass', + 'Conf', 'conf', + ] diff --git a/astroquery/heasarc/core.py b/astroquery/heasarc/core.py new file mode 100644 index 0000000000..bd58277a59 --- /dev/null +++ b/astroquery/heasarc/core.py @@ -0,0 +1,50 @@ +# Licensed under a 3-clause BSD style license - see LICENSE.rst +from __future__ import print_function +from astropy.extern.six import BytesIO +from astropy.table import Table +from ..query import BaseQuery +from ..utils import commons +from ..utils import async_to_sync +from . import conf + +__all__ = ['Heasarc', 'HeasarcClass'] + + +@async_to_sync +class HeasarcClass(BaseQuery): + """HEASARC query class. + """ + + URL = conf.server + TIMEOUT = conf.timeout + + def query_object_async(self, object_name, mission, cache=True, + get_query_payload=False): + """TODO: document this! + + (maybe start by copying over from some other service.) + """ + request_payload = dict() + request_payload['object_name'] = object_name + request_payload['tablehead'] = 'BATCHRETRIEVALCATALOG_2.0 {}'.format(mission) + request_payload['Action'] = 'Query' + request_payload['displaymode'] = 'FitsDisplay' + + if get_query_payload: + return request_payload + + response = self._request('GET', self.URL, params=request_payload, + timeout=self.TIMEOUT, cache=cache) + return response + + def _parse_result(self, response, verbose=False): + # if verbose is False then suppress any VOTable related warnings + if not verbose: + commons.suppress_vo_warnings() + + data = BytesIO(response.content) + table = Table.read(data, hdu=1) + return table + + +Heasarc = HeasarcClass() diff --git a/astroquery/heasarc/tests/__init__.py b/astroquery/heasarc/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/astroquery/heasarc/tests/setup_package.py b/astroquery/heasarc/tests/setup_package.py new file mode 100644 index 0000000000..26754e7474 --- /dev/null +++ b/astroquery/heasarc/tests/setup_package.py @@ -0,0 +1,9 @@ +# Licensed under a 3-clause BSD style license - see LICENSE.rst +import os + + +def get_package_data(): + paths = [os.path.join('data', '*.dat'), + os.path.join('data', '*.xml'), + ] + return {'astroquery.heasarc.tests': paths} diff --git a/astroquery/heasarc/tests/test_heasarc.py b/astroquery/heasarc/tests/test_heasarc.py new file mode 100644 index 0000000000..a3708044e6 --- /dev/null +++ b/astroquery/heasarc/tests/test_heasarc.py @@ -0,0 +1,2 @@ +#Licensed under a 3-clause BSD style license - see LICENSE.rst +from __future__ import print_function diff --git a/astroquery/heasarc/tests/test_heasarc_remote.py b/astroquery/heasarc/tests/test_heasarc_remote.py new file mode 100644 index 0000000000..7cdf7ef0e3 --- /dev/null +++ b/astroquery/heasarc/tests/test_heasarc_remote.py @@ -0,0 +1,16 @@ +# Licensed under a 3-clause BSD style license - see LICENSE.rst +from __future__ import print_function +from astropy.tests.helper import remote_data, pytest +from ...heasarc import Heasarc + +@remote_data +class TestHeasarc: + + def test_basic_example(self): + mission = 'rospublic' + object_name = '3c273' + + heasarc = Heasarc() + table = heasarc.query_object(object_name, mission=mission) + + assert len(table) == 1000 diff --git a/docs/heasarc/heasarc.rst b/docs/heasarc/heasarc.rst new file mode 100644 index 0000000000..24b75d677d --- /dev/null +++ b/docs/heasarc/heasarc.rst @@ -0,0 +1,40 @@ +.. doctest-skip-all + +.. _astroquery.heasarc: + +************************************** +HEASARC Queries (`astroquery.heasarc`) +************************************** + +Getting started +=============== + +This is a python interface for querying the +`HEASARC `__ +archive web service. + +The capabilities are currently very limited ... feature requests and contributions welcome! + +Getting lists of available datasets +----------------------------------- + +.. code-block:: python + + >>> from astroquery.heasarc import Heasarc + >>> heasarc = Heasarc() + >>> mission = 'rospublic' + >>> object_name = '3c273' + >>> table = heasarc.query_object(object_name, mission=mission) + >>> table[:3].pprint() + + +Downloading identified datasets +------------------------------- + +Not implemented yet. + +Reference/API +============= + +.. automodapi:: astroquery.heasarc + :no-inheritance-diagram: diff --git a/docs/index.rst b/docs/index.rst index ab0a50b25a..4554acadbc 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -133,6 +133,7 @@ The following modules have been completed using a common API: alma/alma.rst skyview/skyview.rst nasa_ads/nasa_ads.rst + heasarc/heasarc.rst These others are functional, but do not follow a common & consistent API: @@ -191,6 +192,7 @@ generally return a table listing the available data first. alma/alma.rst eso/eso.rst fermi/fermi.rst + heasarc/heasarc.rst irsa/irsa.rst magpis/magpis.rst ned/ned.rst