Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions astroquery/heasarc/__init__.py
Original file line number Diff line number Diff line change
@@ -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',
]
50 changes: 50 additions & 0 deletions astroquery/heasarc/core.py
Original file line number Diff line number Diff line change
@@ -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()
Empty file.
9 changes: 9 additions & 0 deletions astroquery/heasarc/tests/setup_package.py
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 2 additions & 0 deletions astroquery/heasarc/tests/test_heasarc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#Licensed under a 3-clause BSD style license - see LICENSE.rst
from __future__ import print_function
16 changes: 16 additions & 0 deletions astroquery/heasarc/tests/test_heasarc_remote.py
Original file line number Diff line number Diff line change
@@ -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
40 changes: 40 additions & 0 deletions docs/heasarc/heasarc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.. doctest-skip-all

.. _astroquery.heasarc:

**************************************
HEASARC Queries (`astroquery.heasarc`)
**************************************

Getting started
===============

This is a python interface for querying the
`HEASARC <http://heasarc.gsfc.nasa.gov/>`__
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:
2 changes: 2 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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
Expand Down