Skip to content

Commit

Permalink
Revert "Remove get_raw_response optional parameters."
Browse files Browse the repository at this point in the history
This reverts commit 0dbb4e5.
  • Loading branch information
mkelley committed Jun 9, 2022
1 parent f0a9418 commit 55642bc
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 15 deletions.
30 changes: 27 additions & 3 deletions astroquery/jplhorizons/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def ephemerides_async(self, airmass_lessthan=99,
closest_apparition=False, no_fragments=False,
quantities=conf.eph_quantities,
get_query_payload=False,
cache=True,
get_raw_response=False, cache=True,
extra_precision=False):
"""
Query JPL Horizons for ephemerides.
Expand Down Expand Up @@ -478,6 +478,10 @@ def ephemerides_async(self, airmass_lessthan=99,
When set to `True` the method returns the HTTP request parameters as
a dict, default: False
get_raw_response : boolean, optional
Return raw data as obtained by JPL Horizons without parsing the data
into a table, default: False
extra_precision : boolean, optional
Enables extra precision in RA and DEC values; default: False
Expand Down Expand Up @@ -610,6 +614,10 @@ def ephemerides_async(self, airmass_lessthan=99,
if get_query_payload:
return request_payload

# set return_raw flag, if raw response desired
if get_raw_response:
self.return_raw = True

# query and parse
response = self._request('GET', URL, params=request_payload,
timeout=self.TIMEOUT, cache=cache)
Expand All @@ -629,7 +637,7 @@ def elements_async(self, get_query_payload=False,
refplane='ecliptic',
tp_type='absolute',
closest_apparition=False, no_fragments=False,
cache=True):
get_raw_response=False, cache=True):
"""
Query JPL Horizons for osculating orbital elements.
Expand Down Expand Up @@ -720,6 +728,10 @@ def elements_async(self, get_query_payload=False,
When set to ``True`` the method returns the HTTP request parameters
as a dict, default: False
get_raw_response: boolean, optional
Return raw data as obtained by JPL Horizons without parsing the data
into a table, default: False
Returns
-------
Expand Down Expand Up @@ -820,6 +832,10 @@ def elements_async(self, get_query_payload=False,
if get_query_payload:
return request_payload

# set return_raw flag, if raw response desired
if get_raw_response:
self.return_raw = True

# query and parse
response = self._request('GET', URL, params=request_payload,
timeout=self.TIMEOUT, cache=cache)
Expand All @@ -836,7 +852,7 @@ def elements_async(self, get_query_payload=False,

def vectors_async(self, get_query_payload=False,
closest_apparition=False, no_fragments=False,
cache=True,
get_raw_response=False, cache=True,
refplane='ecliptic', aberrations='geometric',
delta_T=False,):
"""
Expand Down Expand Up @@ -919,6 +935,10 @@ def vectors_async(self, get_query_payload=False,
When set to `True` the method returns the HTTP request parameters as
a dict, default: False
get_raw_response: boolean, optional
Return raw data as obtained by JPL Horizons without parsing the data
into a table, default: False
refplane : string
Reference plane for all output quantities: ``'ecliptic'`` (ecliptic
and mean equinox of reference epoch), ``'earth'`` (Earth mean
Expand Down Expand Up @@ -1058,6 +1078,10 @@ def vectors_async(self, get_query_payload=False,
if get_query_payload:
return request_payload

# set return_raw flag, if raw response desired
if get_raw_response:
self.return_raw = True

# query and parse
response = self._request('GET', URL, params=request_payload,
timeout=self.TIMEOUT, cache=cache)
Expand Down
23 changes: 23 additions & 0 deletions astroquery/jplhorizons/tests/test_jplhorizons_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ def test_ephemerides_query_six(self):

assert len(res) == 32

def test_ephemerides_query_raw(self):
res = (jplhorizons.Horizons(id='Ceres', location='500',
id_type='smallbody', epochs=2451544.5).
ephemerides(get_raw_response=True))

assert len(res) >= 15400

def test_elements_query(self):
res = jplhorizons.Horizons(id='Ceres', location='500@10',
id_type='smallbody',
Expand Down Expand Up @@ -219,6 +226,14 @@ def test_elements_query_two(self):
[res['Omega'], res['w'], res['Tp_jd']],
rtol=1e-3)

def test_elements_query_raw(self):
res = jplhorizons.Horizons(id='Ceres', location='500@10',
id_type='smallbody',
epochs=2451544.5).elements(
get_raw_response=True)

assert len(res) >= 6686

def test_vectors_query(self):
# check values of Ceres for a given epoch
# orbital uncertainty of Ceres is basically zero
Expand All @@ -245,6 +260,14 @@ def test_vectors_query(self):
res['lighttime'], res['range'],
res['range_rate']], rtol=1e-3)

def test_vectors_query_raw(self):
res = jplhorizons.Horizons(id='Ceres', location='500@10',
id_type='smallbody',
epochs=2451544.5).vectors(
get_raw_response=True)

assert len(res) >= 6412

def test_unknownobject(self):
with pytest.raises(ValueError):
jplhorizons.Horizons(id='spamspamspameggsspam', location='500',
Expand Down
28 changes: 16 additions & 12 deletions docs/jplhorizons/jplhorizons.rst
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ limits fragment matching (73P-B would only match 73P-B), respectively. Note
that these options should only be used for comets and will crash the query for
other object types. Extra precision in the queried properties can be requested
using the ``extra_precision`` option. Furthermore, ``get_query_payload=True``
skips the query and only returns the query payload.
skips the query and only returns the query payload, whereas
``get_raw_response=True`` returns the raw query response instead of the astropy
table.

:meth:`~astroquery.jplhorizons.HorizonsClass.ephemerides` queries by default all
available quantities from the JPL Horizons servers. This might take a while. If
Expand Down Expand Up @@ -241,8 +243,9 @@ absolute representation of the time of perihelion passage. For comets, the
options ``closest_apparition`` and ``no_fragments`` are available, which select
the closest apparition in time and reject fragments, respectively. Note that
these options should only be used for comets and will crash the query for other
object types. Also available is ``get_query_payload=True``, which skips the
query and only returns the query payload.
object types. Also available are ``get_query_payload=True``, which skips the
query and only returns the query payload, and ``get_raw_response=True``, which
returns the raw query response instead of the astropy table.

Vectors
-------
Expand Down Expand Up @@ -287,15 +290,16 @@ The following fields are queried:
Similar to the other :class:`~astroquery.jplhorizons.HorizonsClass` functions,
an optional parameter of :meth:`~astroquery.jplhorizons.HorizonsClass.vectors`
is ``get_query_payload=True``, which skips the query and only returns the query
payload for diagnostic purposes. For comets, the options ``closest_apparation``
and ``no_fragments`` are available, which select the closest apparition in time
and reject fragments, respectively. Note that these options should only be used
for comets and will crash the query for other object types. Options
``aberrations`` and ``delta_T`` provide different choices for aberration
corrections as well as a measure for time-varying differences between TDB and UT
time-scales, respectively.
optional parameters of :meth:`~astroquery.jplhorizons.HorizonsClass.vectors` are
``get_query_payload=True``, which skips the query and only returns the query
payload, and ``get_raw_response=True``, which returns the raw query response
instead of the astropy table. For comets, the options ``closest_apparation`` and
``no_fragments`` are available, which select the closest apparition in time and
reject fragments, respectively. Note that these options should only be used for
comets and will crash the query for other object types. Options ``aberrations``
and ``delta_T`` provide different choices for aberration corrections as well as
a measure for time-varying differences between TDB and UT time-scales,
respectively.


How to Use the Query Tables
Expand Down

0 comments on commit 55642bc

Please sign in to comment.