Skip to content

Commit 343c7a5

Browse files
committed
Revise id_type behavior in jplhorizons.
Rename 'majorbody' to '', in better alignment with the API. Set default to `None`, but preserve the current behavior as a 'smallbody'. In the future, replace this with ''. Raise a deprecation warning if 'majorbody' or `None` are used.
1 parent 1aba55e commit 343c7a5

File tree

4 files changed

+76
-18
lines changed

4 files changed

+76
-18
lines changed

CHANGES.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ jplhorizons
3434
Included in this update, the default reference system is changed from
3535
J2000 to ICRF, following API documentation. [#2154]
3636

37+
- Query `id_type` behavior and options are changing:
38+
- `'majorbody'` has been renamed to `''` (empty string) to represent the
39+
Horizons default behavior. The Horizons default to search major bodies
40+
first, then fall back to a small body search. Horizons does not have
41+
a major body only search.
42+
- The default behavior was `'smallbody'` but this will be changed to the
43+
Horizons default in a future version.
44+
- Deprecation warnings are raised if `id_type` is `'majorbody'` or
45+
was not specified by the user.
46+
3747
Infrastructure, Utility and Other Changes and Additions
3848
-------------------------------------------------------
3949

astroquery/jplhorizons/core.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from astropy.table import Table, Column
1313
from astropy.io import ascii
1414
from astropy.time import Time
15+
from astropy.utils.exceptions import AstropyDeprecationWarning
1516

1617
# 3. local imports - use relative imports
1718
# commonly required local imports shown below as example
@@ -35,7 +36,7 @@ class HorizonsClass(BaseQuery):
3536
TIMEOUT = conf.timeout
3637

3738
def __init__(self, id=None, location=None, epochs=None,
38-
id_type='smallbody'):
39+
id_type=None):
3940
"""Instantiate JPL query.
4041
4142
Parameters
@@ -64,11 +65,19 @@ def __init__(self, id=None, location=None, epochs=None,
6465
element and vector queries. If no epochs are provided, the current
6566
time is used.
6667
id_type : str, optional
67-
Identifier type, options: ``'smallbody'``, ``'majorbody'`` (planets
68-
but also anything that is not a small body), ``'designation'``,
69-
``'name'``, ``'asteroid_name'``, ``'comet_name'``, ``'id'``
70-
(Horizons id number), or ``'smallbody'`` (find the closest match
71-
under any id_type), default: ``'smallbody'``
68+
Controls Horizons's object selection for ``id``
69+
[HORIZONSDOC_SELECTION]_ . Options: ``'majorbody'`` (DEPRECATED,
70+
use ``''``), ``'designation'`` (small body designation), ``'name'``
71+
(asteroid or comet name), ``'asteroid_name'``, ``'comet_name'``,
72+
``'id'`` (Horizons ID number), ``'smallbody'`` (asteroid and comet
73+
search), or ``''`` (empty string; first search search planets,
74+
natural satellites, spacecraft, and special cases, then small
75+
bodies).
76+
77+
References
78+
----------
79+
80+
.. [HORIZONSDOC_SELECTION] https://ssd.jpl.nasa.gov/?horizons_doc#selection (retrieved 2021 Sep 23).
7281
7382
7483
Examples
@@ -101,8 +110,18 @@ def __init__(self, id=None, location=None, epochs=None,
101110
self.epochs = epochs
102111

103112
# check for id_type
104-
if id_type not in ['smallbody', 'majorbody',
105-
'designation', 'name',
113+
if id_type is None:
114+
warnings.warn('id_type was not specified, defaulting to a '
115+
'"smallbody" search. This behavior is deprecated and will be '
116+
'changed to "" (empty string / Horizons default) in the future.',
117+
AstropyDeprecationWarning)
118+
id_type = 'smallbody'
119+
elif id_type == 'majorbody':
120+
warnings.warn('id_type "majorbody" is deprecated and will be '
121+
'removed. For the equivalent search behavior, use "" (empty '
122+
'string).', AstropyDeprecationWarning)
123+
id_type = ''
124+
if id_type not in ['', 'smallbody', 'designation', 'name',
106125
'asteroid_name', 'comet_name', 'id']:
107126
raise ValueError('id_type ({:s}) not allowed'.format(id_type))
108127
self.id_type = id_type

astroquery/jplhorizons/tests/test_jplhorizons.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
from collections import OrderedDict
77

88
from numpy.ma import is_masked
9-
from ...utils.testing_tools import MockResponse
109
from astropy.tests.helper import assert_quantity_allclose
10+
from astropy.utils.exceptions import AstropyDeprecationWarning
1111

12+
from ...utils.testing_tools import MockResponse
1213
from ... import jplhorizons
1314

1415
# files in data/ for different query types
@@ -218,3 +219,18 @@ def test_no_H(patch_request):
218219
"""testing missing H value (also applies for G, M1, k1, M2, k2)"""
219220
res = jplhorizons.Horizons(id='1935 UZ').ephemerides()[0]
220221
assert 'H' not in res
222+
223+
224+
def test_id_type_deprecation():
225+
"""Test deprecation warnings based on issue 1742.
226+
227+
Remove when id_type behavior is changed.
228+
229+
https://github.com/astropy/astroquery/pull/1742
230+
231+
"""
232+
with pytest.warns(AstropyDeprecationWarning):
233+
res = jplhorizons.Horizons(id='Ceres')
234+
235+
with pytest.warns(AstropyDeprecationWarning):
236+
res = jplhorizons.Horizons(id='Ceres', id_type='majorbody')

astroquery/jplhorizons/tests/test_jplhorizons_remote.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def test_ephemerides_query(self):
1515
# check values of Ceres for a given epoch
1616
# orbital uncertainty of Ceres is basically zero
1717
res = jplhorizons.Horizons(id='Ceres', location='500',
18+
id_type='smallbody',
1819
epochs=2451544.5).ephemerides()[0]
1920

2021
assert res['targetname'] == "1 Ceres (A801 AA)"
@@ -152,7 +153,7 @@ def test_ephemerides_query_five(self):
152153

153154
def test_ephemerides_query_six(self):
154155
# tests optional constrains for ephemerides queries
155-
obj = jplhorizons.Horizons(id='3552',
156+
obj = jplhorizons.Horizons(id='3552', id_type='smallbody',
156157
location='I33',
157158
epochs={'start': '2018-05-01',
158159
'stop': '2018-08-01',
@@ -169,13 +170,14 @@ def test_ephemerides_query_six(self):
169170

170171
def test_ephemerides_query_raw(self):
171172
res = (jplhorizons.Horizons(id='Ceres', location='500',
172-
epochs=2451544.5).
173+
id_type='smallbody', epochs=2451544.5).
173174
ephemerides(get_raw_response=True))
174175

175176
assert len(res) >= 15400
176177

177178
def test_elements_query(self):
178179
res = jplhorizons.Horizons(id='Ceres', location='500@10',
180+
id_type='smallbody',
179181
epochs=[2451544.5,
180182
2451545.5]).elements()[0]
181183

@@ -204,6 +206,7 @@ def test_elements_query(self):
204206

205207
def test_elements_query_two(self):
206208
obj = jplhorizons.Horizons(id='Ceres', location='500@10',
209+
id_type='smallbody',
207210
epochs=[2451544.5,
208211
2451545.5])
209212

@@ -219,6 +222,7 @@ def test_elements_query_two(self):
219222

220223
def test_elements_query_raw(self):
221224
res = jplhorizons.Horizons(id='Ceres', location='500@10',
225+
id_type='smallbody',
222226
epochs=2451544.5).elements(
223227
get_raw_response=True)
224228

@@ -228,6 +232,7 @@ def test_vectors_query(self):
228232
# check values of Ceres for a given epoch
229233
# orbital uncertainty of Ceres is basically zero
230234
res = jplhorizons.Horizons(id='Ceres', location='500@10',
235+
id_type='smallbody',
231236
epochs=2451544.5).vectors()[0]
232237

233238
assert res['targetname'] == "1 Ceres (A801 AA)"
@@ -251,6 +256,7 @@ def test_vectors_query(self):
251256

252257
def test_vectors_query_raw(self):
253258
res = jplhorizons.Horizons(id='Ceres', location='500@10',
259+
id_type='smallbody',
254260
epochs=2451544.5).vectors(
255261
get_raw_response=True)
256262

@@ -259,20 +265,20 @@ def test_vectors_query_raw(self):
259265
def test_unknownobject(self):
260266
try:
261267
jplhorizons.Horizons(id='spamspamspameggsspam', location='500',
262-
epochs=2451544.5).ephemerides()
268+
id_type='', epochs=2451544.5).ephemerides()
263269
except ValueError:
264270
pass
265271

266272
def test_multipleobjects(self):
267273
try:
268-
jplhorizons.Horizons(id='73P', location='500',
274+
jplhorizons.Horizons(id='73P', location='500', id_type='smallbody',
269275
epochs=2451544.5).ephemerides()
270276
except ValueError:
271277
pass
272278

273279
def test_uri(self):
274280
target = jplhorizons.Horizons(id='3552', location='500',
275-
epochs=2451544.5)
281+
id_type='smallbody', epochs=2451544.5)
276282
assert target.uri is None
277283

278284
target.ephemerides()
@@ -299,10 +305,12 @@ def test__userdefinedlocation_ephemerides_query(self):
299305

300306
am_res = jplhorizons.Horizons(id='Ceres',
301307
location='688',
308+
id_type='smallbody',
302309
epochs=2451544.5).ephemerides()[0]
303310

304311
user_res = jplhorizons.Horizons(id='Ceres',
305312
location=anderson_mesa,
313+
id_type='smallbody',
306314
epochs=2451544.5).ephemerides()[0]
307315

308316
assert_quantity_allclose([am_res['RA'], am_res['DEC']],
@@ -321,7 +329,8 @@ def test_majorbody(self):
321329
quantities = ('1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,'
322330
'21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,'
323331
'38,39,40,41,42,43')
324-
target = jplhorizons.Horizons(id='301', location='688', epochs=epochs)
332+
target = jplhorizons.Horizons(id='301', location='688', epochs=epochs,
333+
id_type='')
325334
eph = target.ephemerides(quantities=quantities)
326335
assert len(eph) == 2
327336

@@ -342,6 +351,7 @@ def test_airmass(self):
342351

343352
# verify data['a-mass'].filled(99) works:
344353
target = jplhorizons.Horizons('Ceres', location='I41',
354+
id_type='smallbody',
345355
epochs=[2458300.5])
346356
eph = target.ephemerides(quantities='1,8')
347357
assert len(eph) == 1
@@ -352,7 +362,8 @@ def test_airmass(self):
352362

353363
def test_vectors_aberrations(self):
354364
"""Check functionality of `aberrations` options"""
355-
obj = jplhorizons.Horizons(id='1', epochs=2458500, location='500@0')
365+
obj = jplhorizons.Horizons(id='1', epochs=2458500, location='500@0',
366+
id_type='smallbody')
356367

357368
vec = obj.vectors(aberrations='geometric')
358369
assert_quantity_allclose(vec['x'][0], -2.086487005013347)
@@ -364,7 +375,8 @@ def test_vectors_aberrations(self):
364375
assert_quantity_allclose(vec['x'][0], -2.086576286974797)
365376

366377
def test_vectors_delta_T(self):
367-
obj = jplhorizons.Horizons(id='1', epochs=2458500, location='500@0')
378+
obj = jplhorizons.Horizons(id='1', epochs=2458500, location='500@0',
379+
id_type='smallbody')
368380

369381
vec = obj.vectors(delta_T=False)
370382
assert 'delta_T' not in vec.columns
@@ -373,7 +385,8 @@ def test_vectors_delta_T(self):
373385
assert_quantity_allclose(vec['delta_T'][0], 69.184373)
374386

375387
def test_ephemerides_extraprecision(self):
376-
obj = jplhorizons.Horizons(id='1', epochs=2458500, location='G37')
388+
obj = jplhorizons.Horizons(id='1', epochs=2458500, location='G37',
389+
id_type='smallbody')
377390

378391
vec_simple = obj.ephemerides(extra_precision=False)
379392
vec_highprec = obj.ephemerides(extra_precision=True)

0 commit comments

Comments
 (0)