Skip to content

Commit 745b81e

Browse files
committed
Add HEASARC service (very limited functionality for now)
1 parent b9c6ae6 commit 745b81e

File tree

8 files changed

+154
-0
lines changed

8 files changed

+154
-0
lines changed

astroquery/heasarc/__init__.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Licensed under a 3-clause BSD style license - see LICENSE.rst
2+
"""
3+
HEASARC
4+
-------
5+
6+
The High Energy Astrophysics Science Archive Research Center (HEASARC)
7+
is the primary archive for NASA's (and other space agencies') missions.
8+
9+
The initial version of this was coded in a sprint at the
10+
"Python in astronomy" workshop in April 2015 by Jean-Christophe Leyder,
11+
Abigail Stevens, Antonio Martin-Carrillo and Christoph Deil.
12+
"""
13+
from astropy import config as _config
14+
15+
16+
class Conf(_config.ConfigNamespace):
17+
"""
18+
Configuration parameters for `astroquery.heasarc`.
19+
"""
20+
server = _config.ConfigItem(
21+
['http://heasarc.gsfc.nasa.gov/cgi-bin/W3Browse/w3query_noredir.pl'],
22+
'Name of the HEASARC server to use.'
23+
)
24+
timeout = _config.ConfigItem(
25+
30,
26+
'Time limit for connecting to HEASARC server.'
27+
)
28+
29+
conf = Conf()
30+
31+
from .core import Heasarc, HeasarcClass
32+
33+
__all__ = ['Heasarc', 'HeasarcClass',
34+
'Conf', 'conf',
35+
]

astroquery/heasarc/core.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Licensed under a 3-clause BSD style license - see LICENSE.rst
2+
from __future__ import print_function
3+
from astropy.extern.six import BytesIO
4+
from astropy.table import Table
5+
from ..query import BaseQuery
6+
from ..utils import commons
7+
from ..utils import async_to_sync
8+
from . import conf
9+
10+
__all__ = ['Heasarc', 'HeasarcClass']
11+
12+
13+
@async_to_sync
14+
class HeasarcClass(BaseQuery):
15+
"""HEASARC query class.
16+
"""
17+
18+
URL = conf.server
19+
TIMEOUT = conf.timeout
20+
21+
def query_object_async(self, object_name, mission, cache=True,
22+
get_query_payload=False):
23+
"""TODO: document this!
24+
25+
(maybe start by copying over from some other service.)
26+
"""
27+
request_payload = dict()
28+
request_payload['object_name'] = object_name
29+
request_payload['tablehead'] = 'BATCHRETRIEVALCATALOG_2.0 {}'.format(mission)
30+
request_payload['Action'] = 'Query'
31+
request_payload['displaymode'] = 'FitsDisplay'
32+
33+
if get_query_payload:
34+
return request_payload
35+
36+
response = self._request('GET', self.URL, params=request_payload,
37+
timeout=self.TIMEOUT, cache=cache)
38+
return response
39+
40+
def _parse_result(self, response, verbose=False):
41+
# if verbose is False then suppress any VOTable related warnings
42+
if not verbose:
43+
commons.suppress_vo_warnings()
44+
45+
data = BytesIO(response.content)
46+
table = Table.read(data, hdu=1)
47+
return table
48+
49+
50+
Heasarc = HeasarcClass()

astroquery/heasarc/tests/__init__.py

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Licensed under a 3-clause BSD style license - see LICENSE.rst
2+
import os
3+
4+
5+
def get_package_data():
6+
paths = [os.path.join('data', '*.dat'),
7+
os.path.join('data', '*.xml'),
8+
]
9+
return {'astroquery.heasarc.tests': paths}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#Licensed under a 3-clause BSD style license - see LICENSE.rst
2+
from __future__ import print_function
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Licensed under a 3-clause BSD style license - see LICENSE.rst
2+
from __future__ import print_function
3+
from astropy.tests.helper import remote_data, pytest
4+
from ...heasarc import Heasarc
5+
6+
@remote_data
7+
class TestHeasarc:
8+
9+
def test_basic_example(self):
10+
mission = 'rospublic'
11+
object_name = '3c273'
12+
13+
heasarc = Heasarc()
14+
table = heasarc.query_object(object_name, mission=mission)
15+
16+
assert len(table) == 1000

docs/heasarc/heasarc.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
.. doctest-skip-all
2+
3+
.. _astroquery.heasarc:
4+
5+
**************************************
6+
HEASARC Queries (`astroquery.heasarc`)
7+
**************************************
8+
9+
Getting started
10+
===============
11+
12+
This is a python interface for querying the
13+
`HEASARC <http://heasarc.gsfc.nasa.gov/>`__
14+
archive web service.
15+
16+
The capabilities are currently very limited ... feature requests and contributions welcome!
17+
18+
Getting lists of available datasets
19+
-----------------------------------
20+
21+
.. code-block:: python
22+
23+
>>> from astroquery.heasarc import Heasarc
24+
>>> heasarc = Heasarc()
25+
>>> mission = 'rospublic'
26+
>>> object_name = '3c273'
27+
>>> table = heasarc.query_object(object_name, mission=mission)
28+
>>> table[:3].pprint()
29+
30+
31+
Downloading identified datasets
32+
-------------------------------
33+
34+
Not implemented yet.
35+
36+
Reference/API
37+
=============
38+
39+
.. automodapi:: astroquery.heasarc
40+
:no-inheritance-diagram:

docs/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ The following modules have been completed using a common API:
133133
alma/alma.rst
134134
skyview/skyview.rst
135135
nasa_ads/nasa_ads.rst
136+
heasarc/heasarc.rst
136137

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

@@ -191,6 +192,7 @@ generally return a table listing the available data first.
191192
alma/alma.rst
192193
eso/eso.rst
193194
fermi/fermi.rst
195+
heasarc/heasarc.rst
194196
irsa/irsa.rst
195197
magpis/magpis.rst
196198
ned/ned.rst

0 commit comments

Comments
 (0)