Skip to content

Commit 96f0c2d

Browse files
XaviTorellobsipocz
authored andcommitted
Add optional_settings param to Ephemerides
It permits to easily extend the Ephemerides behaviour being able to pass some non-hardcoded settings. The idea is to be able to pass a key-value based dictionary to inject some additional payload to the Ephemerides request. This will simplify the process to change optional settings without the need to touch any line of code :) It will also work for any table setting, or some other setting that needs to define/change the `request_payload` More info about possible settings at https://ssd.jpl.nasa.gov/horizons.cgi?s_tset=1 Fix #1801
1 parent 9bf69d3 commit 96f0c2d

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

astroquery/jplhorizons/core.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ def ephemerides_async(self, airmass_lessthan=99,
182182
refsystem='ICRF',
183183
closest_apparition=False, no_fragments=False,
184184
quantities=conf.eph_quantities,
185+
optional_settings=None,
185186
get_query_payload=False,
186187
get_raw_response=False, cache=True,
187188
extra_precision=False):
@@ -487,6 +488,11 @@ def ephemerides_async(self, airmass_lessthan=99,
487488
<https://ssd.jpl.nasa.gov/?horizons_doc#table_quantities>`_;
488489
default: all quantities
489490
491+
optional_settings: dict, optional
492+
key-value based dictionary to inject some additional optional settings
493+
See `Optional observer-table settings" <https://ssd.jpl.nasa.gov/horizons.cgi?s_tset=1>`_;
494+
default: empty optional setting
495+
490496
get_query_payload : boolean, optional
491497
When set to `True` the method returns the HTTP request parameters as
492498
a dict, default: False
@@ -620,6 +626,14 @@ def ephemerides_async(self, airmass_lessthan=99,
620626
else:
621627
request_payload['SKIP_DAYLT'] = 'NO'
622628

629+
# inject optional settings if provided
630+
if optional_settings:
631+
assert isinstance(
632+
optional_settings, dict
633+
), "optional_settings should be a dict"
634+
for key, value in optional_settings.items():
635+
request_payload[key] = value
636+
623637
self.query_type = 'ephemerides'
624638

625639
# return request_payload if desired

astroquery/jplhorizons/tests/test_jplhorizons.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,52 @@ def test_ephemerides_query_payload():
187187
('SKIP_DAYLT', 'YES')])
188188

189189

190+
def test_ephemerides_query_payload_with_optional_settings():
191+
"""
192+
Assert that all optional settings are provided at query payload
193+
"""
194+
obj = jplhorizons.Horizons(id='Halley', id_type='comet_name',
195+
location='290',
196+
epochs={'start': '2080-01-01',
197+
'stop': '2080-02-01',
198+
'step': '3h'})
199+
200+
optional_settings = {
201+
"R_T_S_ONLY": "TVH",
202+
"TIME_DIGITS": "SECONDS",
203+
}
204+
res = obj.ephemerides(airmass_lessthan=1.2, skip_daylight=True,
205+
closest_apparition=True,
206+
max_hour_angle=10,
207+
solar_elongation=(150, 180),
208+
get_query_payload=True,
209+
optional_settings=optional_settings)
210+
211+
assert res == OrderedDict([
212+
('batch', 1),
213+
('TABLE_TYPE', 'OBSERVER'),
214+
('QUANTITIES', "'1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,"
215+
"18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,"
216+
"33,34,35,36,37,38,39,40,41,42,43'"),
217+
('COMMAND', '"COMNAM=Halley; CAP;"'),
218+
('SOLAR_ELONG', '"150,180"'),
219+
('LHA_CUTOFF', '10'),
220+
('CSV_FORMAT', 'YES'),
221+
('CAL_FORMAT', 'BOTH'),
222+
('ANG_FORMAT', 'DEG'),
223+
('APPARENT', 'AIRLESS'),
224+
('REF_SYSTEM', 'J2000'),
225+
('EXTRA_PREC', 'NO'),
226+
('CENTER', "'290'"),
227+
('START_TIME', '"2080-01-01"'),
228+
('STOP_TIME', '"2080-02-01"'),
229+
('STEP_SIZE', '"3h"'),
230+
('AIRMASS', '1.2'),
231+
('SKIP_DAYLT', 'YES')
232+
] + list(optional_settings.items()),
233+
)
234+
235+
190236
def test_elements_query_payload():
191237
res = (jplhorizons.Horizons(id='Ceres', location='500@10',
192238
epochs=2451544.5).elements(

docs/jplhorizons/jplhorizons.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,9 @@ limits fragment matching (73P-B would only match 73P-B), respectively. Note
189189
that these options should only be used for comets and will crash the query for
190190
other object types. Extra precision in the queried properties can be requested
191191
using the ``extra_precision`` option. Furthermore, ``get_query_payload=True``
192-
skips the query and only returns the query payload.
192+
skips the query and only returns the query payload. To pass additional settings
193+
to the request use the ``optional_settings`` passing a key-value
194+
dictionary.
193195

194196
:meth:`~astroquery.jplhorizons.HorizonsClass.ephemerides` queries by default all
195197
available quantities from the JPL Horizons servers. This might take a while. If

0 commit comments

Comments
 (0)