Skip to content

Commit ed1adc6

Browse files
committed
add/update tests
1 parent 1a91063 commit ed1adc6

File tree

3 files changed

+76
-23
lines changed

3 files changed

+76
-23
lines changed

astroquery/jplhorizons/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ def _location_to_params(loc_dict):
11701170
"CENTER": f"coord@{loc_dict['body']}",
11711171
"COORD_TYPE": "GEODETIC",
11721172
"SITE_COORD": ",".join(
1173-
str(float(loc_dict[k])) for k in ['lat', 'lon', 'elevation']
1173+
str(float(loc_dict[k])) for k in ['lon', 'lat', 'elevation']
11741174
)
11751175
}
11761176
loc_dict["SITE_COORD"] = f"'{loc_dict['SITE_COORD']}'"

astroquery/jplhorizons/tests/test_jplhorizons.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def test_ephemerides_query(patch_request):
8383
assert res['targetname'] == "1 Ceres (A801 AA)"
8484
assert res['datetime_str'] == "2000-Jan-01 00:00:00.000"
8585
assert res['solar_presence'] == ""
86-
assert res['flags'] == ""
86+
assert res['lunar_presence'] == ""
8787
assert res['elongFlag'] == '/L'
8888
assert res['airmass'] == 999
8989

@@ -256,22 +256,23 @@ def test_vectors_query_payload():
256256
res = jplhorizons.Horizons(id='Ceres', location='500@10',
257257
epochs=2451544.5).vectors(
258258
get_query_payload=True)
259-
260259
assert res == OrderedDict([
261-
('format', 'text'),
262-
('EPHEM_TYPE', 'VECTORS'),
263-
('OUT_UNITS', 'AU-D'),
264-
('COMMAND', '"Ceres"'),
265-
('CENTER', "'500@10'"),
266-
('CSV_FORMAT', '"YES"'),
267-
('REF_PLANE', 'ECLIPTIC'),
268-
('REF_SYSTEM', 'ICRF'),
269-
('TP_TYPE', 'ABSOLUTE'),
270-
('VEC_LABELS', 'YES'),
271-
('VEC_CORR', '"NONE"'),
272-
('VEC_DELTA_T', 'NO'),
273-
('OBJ_DATA', 'YES'),
274-
('TLIST', '2451544.5')])
260+
('format', 'text'),
261+
('EPHEM_TYPE', 'VECTORS'),
262+
('OUT_UNITS', 'AU-D'),
263+
('COMMAND', '"Ceres"'),
264+
('CSV_FORMAT', '"YES"'),
265+
('REF_PLANE', 'ECLIPTIC'),
266+
('REF_SYSTEM', 'ICRF'),
267+
('TP_TYPE', 'ABSOLUTE'),
268+
('VEC_LABELS', 'YES'),
269+
('VEC_CORR', '"NONE"'),
270+
('VEC_DELTA_T', 'NO'),
271+
('OBJ_DATA', 'YES'),
272+
('CENTER', "'500@10'"),
273+
('TLIST', '2451544.5')
274+
])
275+
275276

276277

277278
def test_no_H(patch_request):

astroquery/jplhorizons/tests/test_jplhorizons_remote.py

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# Licensed under a 3-clause BSD style license - see LICENSE.rst
22

3+
import random
34

4-
import pytest
55
from numpy.ma import is_masked
6+
import numpy as np
7+
import pytest
68

9+
from astropy.coordinates import spherical_to_cartesian
710
from astropy.tests.helper import assert_quantity_allclose
11+
import astropy.units as u
812
from astropy.utils.exceptions import AstropyDeprecationWarning
913

1014
from ... import jplhorizons
@@ -23,7 +27,7 @@ def test_ephemerides_query(self):
2327
assert res['targetname'] == "1 Ceres (A801 AA)"
2428
assert res['datetime_str'] == "2000-Jan-01 00:00:00.000"
2529
assert res['solar_presence'] == ""
26-
assert res['flags'] == ""
30+
assert res['lunar_presence'] == ""
2731
assert res['elongFlag'] == '/L'
2832
assert res['airmass'] == 999
2933

@@ -75,7 +79,7 @@ def test_ephemerides_query_two(self):
7579
assert res['targetname'] == "1P/Halley"
7680
assert res['datetime_str'] == "2080-Jan-11 09:00"
7781
assert res['solar_presence'] == ""
78-
assert res['flags'] == "m"
82+
assert res['lunar_presence'] == "m"
7983
assert res['elongFlag'] == '/L'
8084

8185
for value in ['H', 'G']:
@@ -98,7 +102,7 @@ def test_ephemerides_query_three(self):
98102
assert res['targetname'] == "73P/Schwassmann-Wachmann 3"
99103
assert res['datetime_str'] == "2080-Jan-01 00:00"
100104
assert res['solar_presence'] == "*"
101-
assert res['flags'] == "m"
105+
assert res['lunar_presence'] == "m"
102106
assert res['elongFlag'] == '/L'
103107

104108
for value in ['H', 'G']:
@@ -123,7 +127,7 @@ def test_ephemerides_query_four(self):
123127
assert res['targetname'] == "167P/CINEOS"
124128
assert res['datetime_str'] == "2080-Jan-01 00:00"
125129
assert res['solar_presence'] == "*"
126-
assert res['flags'] == "m"
130+
assert res['lunar_presence'] == "m"
127131
assert res['elongFlag'] == '/T'
128132

129133
for value in ['H', 'G', 'M1', 'k1']:
@@ -150,7 +154,7 @@ def test_ephemerides_query_five(self):
150154
assert res['targetname'] == "12P/Pons-Brooks"
151155
assert res['datetime_str'] == "2080-Jan-01 00:00"
152156
assert res['solar_presence'] == "*"
153-
assert res['flags'] == "m"
157+
assert res['lunar_presence'] == "m"
154158
assert res['elongFlag'] == '/L'
155159

156160
for value in ['H', 'G', 'phasecoeff']:
@@ -405,3 +409,51 @@ def test_ephemerides_extraprecision(self):
405409
vec_highprec = obj.ephemerides(extra_precision=True)
406410

407411
assert (vec_simple['RA'][0]-vec_highprec['RA'][0]) > 1e-7
412+
413+
def test_geodetic_queries(self):
414+
"""
415+
black-box test for observer and vectors queries with geodetic
416+
coordinates. checks spatial sensibility.
417+
"""
418+
phobos = {
419+
'body': 401,
420+
'lon': random.randint(-150, -1),
421+
'lat': random.randint(-80, 80),
422+
'elevation': 0
423+
}
424+
deimos = {
425+
'body': 402,
426+
'lon': random.randint(-150, -1),
427+
'lat': random.randint(-80, 80),
428+
'elevation': 0
429+
}
430+
epochs = [random.randint(int(2.3e6), int(2.5e6))]
431+
deimos_phobos = jplhorizons.Horizons(
432+
phobos, location=deimos, epochs=epochs
433+
)
434+
phobos_deimos = jplhorizons.Horizons(
435+
deimos, location=phobos, epochs=epochs
436+
)
437+
pd_eph = phobos_deimos.ephemerides()
438+
dp_eph = deimos_phobos.ephemerides()
439+
dp_xyz = spherical_to_cartesian(
440+
dp_eph['delta'], dp_eph['DEC'], dp_eph['RA']
441+
)
442+
pd_xyz = spherical_to_cartesian(
443+
pd_eph['delta'], pd_eph['DEC'], pd_eph['RA']
444+
)
445+
elementwise = [(dp_el + pd_el) for dp_el, pd_el in zip(dp_xyz, pd_xyz)]
446+
eph_offset = (sum([off ** 2 for off in elementwise]) ** 0.5).to(u.km)
447+
# horizons can do better than this, but we'd have to go to a little
448+
# more trouble than is necessary for a software test...
449+
assert eph_offset < 10 * u.km
450+
# ...and vectors queries are really what you're meant to use for
451+
# this sort of thing.
452+
pd_vec, dp_vec = phobos_deimos.vectors(), deimos_phobos.vectors()
453+
vec_offset = np.sum(
454+
(
455+
pd_vec.as_array(names=('x', 'y', 'z')).view('f8')
456+
+ dp_vec.as_array(names=('x', 'y', 'z')).view('f8')
457+
) ** 2
458+
)
459+
assert (vec_offset * u.au.to(u.km)) < 1

0 commit comments

Comments
 (0)