Source code for astroquery.dace.core
# Licensed under a 3-clause BSD style license - see LICENSE.rst
from collections import defaultdict
from json import JSONDecodeError
from astropy.table import Table
from ..query import BaseQuery
from ..utils import async_to_sync
from . import conf
__all__ = ['Dace', 'DaceClass']
class ParseException(Exception):
"""Raised when parsing Dace data fails"""
[docs]@async_to_sync
class DaceClass(BaseQuery):
"""
DACE class to access DACE (Data Analysis Center for Exoplanets) data based in Geneva Observatory
"""
__DACE_URL = conf.server
__DACE_TIMEOUT = conf.timeout
__OBSERVATION_ENDPOINT = 'ObsAPI/observation/'
__RADIAL_VELOCITIES_ENDPOINT = __OBSERVATION_ENDPOINT + 'radialVelocities/'
__HEADERS = {'Accept': 'application/json'}
[docs] def query_radial_velocities_async(self, object_name):
"""
Get radial velocities data for an object_name. For example : HD40307
Parameters
----------
object_name : str
The target you want radial velocities data
Returns
-------
response : a ``requests.Response`` from DACE
"""
return self._request("GET", ''.join([self.__DACE_URL, self.__RADIAL_VELOCITIES_ENDPOINT, object_name]),
timeout=self.__DACE_TIMEOUT, headers=self.__HEADERS)
def _parse_result(self, response, verbose=False):
try:
json_data = response.json()
dace_dict = self.transform_data_as_dict(json_data)
return Table(dace_dict)
except JSONDecodeError as error:
raise ParseException("Failed to parse DACE result. Request response : {}".format(response.text)) from error
Dace = DaceClass()