|
| 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() |
0 commit comments