Skip to content

Commit 2dfa100

Browse files
emolterbsipocz
authored andcommitted
small fixes to tests, improved documentation
1 parent 72a34be commit 2dfa100

File tree

3 files changed

+72
-59
lines changed

3 files changed

+72
-59
lines changed

astroquery/solarsystem/pds/core.py

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from bs4 import BeautifulSoup
1414

1515
# 3. local imports - use relative imports
16-
# commonly required local imports shown below as example
1716
# all Query classes should inherit from BaseQuery.
1817
from ...query import BaseQuery
1918
from ...utils import async_to_sync
@@ -25,26 +24,21 @@
2524
@async_to_sync
2625
class RingNodeClass(BaseQuery):
2726
"""
28-
for querying the Planetary Ring Node ephemeris tools
27+
a class for querying the Planetary Ring Node ephemeris tools
2928
<https://pds-rings.seti.org/tools/>
30-
3129
"""
3230

3331
TIMEOUT = conf.timeout
3432

35-
def __init__(self, planet=None, obs_time=None):
36-
"""Instantiate Planetary Ring Node query
37-
38-
Parameters
39-
----------
40-
41-
"""
42-
33+
def __init__(self):
34+
'''
35+
Instantiate Planetary Ring Node query
36+
'''
4337
super().__init__()
4438

4539
def __str__(self):
4640
"""
47-
String representation of RingNodeClass object instance
41+
String representation of `~RingNodeClass` object instance
4842
4943
Examples
5044
--------
@@ -68,46 +62,61 @@ def ephemeris_async(
6862
cache=True,
6963
):
7064
"""
71-
send query to server
72-
73-
note this interacts with utils.async_to_sync to be called as ephemeris()
65+
send query to Planetary Ring Node server
7466
7567
Parameters
7668
----------
77-
self : RingNodeClass instance
69+
self : `~RingNodeClass` instance
7870
planet : str, required. one of Mars, Jupiter, Saturn, Uranus, Neptune, or Pluto
79-
obs_time : astropy.Time object, or str in format YYYY-MM-DD hh:mm, optional.
80-
If str is provided then UTC is assumed. If no obs_time is provided,
81-
the current time is used.
71+
obs_time : `~astropy.Time` object, or str in format YYYY-MM-DD hh:mm, optional.
72+
If str is provided then UTC is assumed.
73+
If no obs_time is provided, the current time is used.
8274
location : array-like, or `~astropy.coordinates.EarthLocation`, optional
8375
Observer's location as a
8476
3-element array of Earth longitude, latitude, altitude, or
85-
a `~astropy.coordinates.EarthLocation`. Longitude and
77+
`~astropy.coordinates.EarthLocation`. Longitude and
8678
latitude should be anything that initializes an
8779
`~astropy.coordinates.Angle` object, and altitude should
8880
initialize an `~astropy.units.Quantity` object (with units
89-
of length). If ``None``, then the geocenter (code 500) is
90-
used.
81+
of length). If ``None``, then the geocenter is used.
9182
neptune_arcmodel : float, optional. which ephemeris to assume for Neptune's ring arcs
9283
must be one of 1, 2, or 3 (see https://pds-rings.seti.org/tools/viewer3_nep.shtml for details)
9384
has no effect if planet != 'Neptune'
85+
get_query_payload : boolean, optional
86+
When set to `True` the method returns the HTTP request parameters as
87+
a dict, default: False
88+
get_raw_response : boolean, optional
89+
Return raw data as obtained by the Planetary Ring Node without parsing the data
90+
into a table, default: False
91+
9492
9593
Returns
9694
-------
9795
response : `requests.Response`
9896
The response of the HTTP request.
9997
98+
10099
Examples
101100
--------
102101
>>> from astroquery.solarsystem.pds import RingNode
103-
>>> nodeobj = RingNode()
104-
>>> eph = obj.ephemeris(planet='Uranus',
105-
... obs_time='2017-01-01 00:00') # doctest: +SKIP
106-
>>> print(eph) # doctest: +SKIP
107-
table here...
102+
>>> systemtable, bodytable, ringtable = RingNode().ephemeris(planet='Uranus',
103+
... obs_time='2024-05-08 22:39',
104+
... location = (-23.029 * u.deg, -67.755 * u.deg, 5000 * u.m)) # doctest: +SKIP
105+
>>> print(ringtable) # doctest: +SKIP
106+
ring pericenter ascending node
107+
deg deg
108+
------- ---------- --------------
109+
Six 293.129 52.0
110+
Five 109.438 81.1
111+
Four 242.882 66.9
112+
Alpha 184.498 253.9
113+
Beta 287.66 299.2
114+
Eta 0.0 0.0
115+
Gamma 50.224 0.0
116+
Delta 0.0 0.0
117+
Lambda 0.0 0.0
118+
Epsilon 298.022 0.0
108119
"""
109-
planet = planet
110-
obs_time = obs_time
111120

112121
URL = conf.pds_server
113122
# URL = 'https://pds-rings.seti.org/cgi-bin/tools/viewer3_xxx.pl?'
@@ -126,7 +135,7 @@ def ephemeris_async(
126135
"pluto",
127136
]:
128137
raise ValueError(
129-
"illegal value for 'planet' parameter (must be 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune', or 'Pluto'"
138+
"illegal value for 'planet' parameter (must be 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune', or 'Pluto')"
130139
)
131140

132141
if obs_time is None:
@@ -181,7 +190,6 @@ def ephemeris_async(
181190
)
182191

183192
# configure request_payload for ephemeris query
184-
# start with successful query and incrementally de-hardcode stuff
185193
# thankfully, adding extra planet-specific keywords here does not break query for other planets
186194
request_payload = OrderedDict(
187195
[
@@ -262,7 +270,9 @@ def _parse_ringnode(self, src):
262270
263271
Returns
264272
-------
265-
data : `astropy.Table`
273+
systemtable : dict
274+
bodytable : `astropy.Table`
275+
ringtable : `astropy.Table`
266276
"""
267277

268278
self.raw_response = src
@@ -448,7 +458,6 @@ def _parse_ringnode(self, src):
448458
def _parse_result(self, response, verbose=None):
449459
"""
450460
Routine for managing parser calls
451-
note this MUST be named exactly _parse_result so it interacts with async_to_sync properly
452461
453462
Parameters
454463
----------
@@ -458,7 +467,9 @@ def _parse_result(self, response, verbose=None):
458467
459468
Returns
460469
-------
461-
data : `astropy.Table`
470+
systemtable : dict
471+
bodytable : `astropy.Table`
472+
ringtable : `astropy.Table`
462473
"""
463474
self.last_response = response
464475
try:
@@ -475,7 +486,7 @@ def _parse_result(self, response, verbose=None):
475486
systemtable,
476487
bodytable,
477488
ringtable,
478-
) # astropy table, astropy table, astropy table
489+
)
479490

480491

481492
RingNode = RingNodeClass()

astroquery/solarsystem/pds/tests/test_ringnode.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def patch_request(request):
3535

3636

3737
# --------------------------------- actual test functions
38+
3839
def test_ephemeris_query(patch_request):
3940

4041
systemtable, bodytable, ringtable = pds.RingNode().ephemeris(
@@ -140,7 +141,7 @@ def test_ephemeris_query_payload():
140141
(
141142
"observatory",
142143
"Earth's center",
143-
), # has no effect if viewpoint != observatory so can hardcode. no plans to implement calling observatories by name since ring node only names like 8 observatories
144+
),
144145
("latitude", 10),
145146
("longitude", -120.355),
146147
("lon_dir", "east"),
@@ -167,3 +168,27 @@ def test_ephemeris_query_payload():
167168
("output", "html"),
168169
]
169170
)
171+
172+
173+
def test_bad_query_exception_throw():
174+
175+
with pytest.raises(ValueError):
176+
pds.RingNode().ephemeris(planet="Mercury", obs_time="2022-05-03 00:00")
177+
178+
with pytest.raises(ValueError):
179+
pds.RingNode().ephemeris(planet="Uranus", obs_time="2022-13-03 00:00")
180+
181+
with pytest.raises(ValueError):
182+
pds.RingNode().ephemeris(
183+
planet="Neptune",
184+
obs_time="2022-05-03 00:00",
185+
location=(10.0 * u.deg, -120.355 * u.deg),
186+
)
187+
188+
with pytest.raises(ValueError):
189+
pds.RingNode().ephemeris(
190+
planet="Neptune",
191+
obs_time="2022-05-03 00:00",
192+
location=(10.0 * u.deg, -120.355 * u.deg, 1000 * u.m),
193+
neptune_arcmodel=0,
194+
)

astroquery/solarsystem/pds/tests/test_ringnode_remote.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -88,26 +88,3 @@ def test_ephemeris_query(self):
8888
beta = ringtable[ringtable.loc_indices["Beta"]]
8989
assert np.isclose(beta["pericenter"].to(u.deg).value, 231.051, rtol=1e-3)
9090
assert np.isclose(beta["ascending node"].to(u.deg).value, 353.6, rtol=1e-2)
91-
92-
def test_bad_query_exception_throw(self):
93-
94-
with pytest.raises(ValueError):
95-
pds.RingNode().ephemeris(planet="Mercury", obs_time="2022-05-03 00:00")
96-
97-
with pytest.raises(ValueError):
98-
pds.RingNode().ephemeris(planet="Uranus", obs_time="2022-13-03 00:00")
99-
100-
with pytest.raises(ValueError):
101-
pds.RingNode().ephemeris(
102-
planet="Neptune",
103-
obs_time="2022-05-03 00:00",
104-
location=(10.0 * u.deg, -120.355 * u.deg),
105-
)
106-
107-
with pytest.raises(ValueError):
108-
pds.RingNode().ephemeris(
109-
planet="Neptune",
110-
obs_time="2022-05-03 00:00",
111-
location=(10.0 * u.deg, -120.355 * u.deg, 1000 * u.m),
112-
neptune_arcmodel=0,
113-
)

0 commit comments

Comments
 (0)