Skip to content

Commit 5b38065

Browse files
authored
Merge pull request #1802 from XaviTorello/feature/jplhorizons_add_optional_settings
Add optional_settings param to JPL Horizon Ephemerides
2 parents 9bf69d3 + 0e0b6dd commit 5b38065

File tree

4 files changed

+67
-5
lines changed

4 files changed

+67
-5
lines changed

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ jplhorizons
9090
- Deprecate ``get_raw_response`` options in query methods. The raw response may
9191
be retrieved from the _async() methods. [#2418]
9292

93+
- Adding ``optional_setting`` kwarg to the ephemerides methods to allow
94+
passing additional settings. [#1802]
95+
96+
- Optional keyword arguments are now keyword only. [#1802]
97+
9398
jplsbdb
9499
^^^^^^^
95100

astroquery/jplhorizons/core.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class HorizonsClass(BaseQuery):
4242
"return a response object, and access the content with "
4343
"``response.text``"))
4444

45-
def __init__(self, id=None, location=None, epochs=None,
45+
def __init__(self, id=None, *, location=None, epochs=None,
4646
id_type=None):
4747
"""
4848
Initialize JPL query.
@@ -174,14 +174,15 @@ def __str__(self):
174174

175175
@deprecated_renamed_argument("get_raw_response", None, since="0.4.7",
176176
alternative="async methods")
177-
def ephemerides_async(self, airmass_lessthan=99,
177+
def ephemerides_async(self, *, airmass_lessthan=99,
178178
solar_elongation=(0, 180), max_hour_angle=0,
179179
rate_cutoff=None,
180180
skip_daylight=False,
181181
refraction=False,
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,11 @@ 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+
for key, value in optional_settings.items():
632+
request_payload[key] = value
633+
623634
self.query_type = 'ephemerides'
624635

625636
# return request_payload if desired
@@ -646,7 +657,7 @@ def ephemerides_async(self, airmass_lessthan=99,
646657

647658
@deprecated_renamed_argument("get_raw_response", None, since="0.4.7",
648659
alternative="async methods")
649-
def elements_async(self, get_query_payload=False,
660+
def elements_async(self, *, get_query_payload=False,
650661
refsystem='ICRF',
651662
refplane='ecliptic',
652663
tp_type='absolute',
@@ -870,7 +881,7 @@ def elements_async(self, get_query_payload=False,
870881

871882
@deprecated_renamed_argument("get_raw_response", None, since="0.4.7",
872883
alternative="async methods")
873-
def vectors_async(self, get_query_payload=False,
884+
def vectors_async(self, *, get_query_payload=False,
874885
closest_apparition=False, no_fragments=False,
875886
get_raw_response=False, cache=True,
876887
refplane='ecliptic', aberrations='geometric',

astroquery/jplhorizons/tests/test_jplhorizons.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,50 @@ 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 = {"R_T_S_ONLY": "TVH", "TIME_DIGITS": "SECONDS"}
201+
202+
res = obj.ephemerides(airmass_lessthan=1.2, skip_daylight=True,
203+
closest_apparition=True,
204+
max_hour_angle=10,
205+
solar_elongation=(150, 180),
206+
get_query_payload=True,
207+
optional_settings=optional_settings)
208+
209+
assert res == OrderedDict([
210+
('format', 'text'),
211+
('EPHEM_TYPE', 'OBSERVER'),
212+
('QUANTITIES', "'1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,"
213+
"18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,"
214+
"33,34,35,36,37,38,39,40,41,42,43'"),
215+
('COMMAND', '"COMNAM=Halley; CAP;"'),
216+
('SOLAR_ELONG', '"150,180"'),
217+
('LHA_CUTOFF', '10'),
218+
('CSV_FORMAT', 'YES'),
219+
('CAL_FORMAT', 'BOTH'),
220+
('ANG_FORMAT', 'DEG'),
221+
('APPARENT', 'AIRLESS'),
222+
('REF_SYSTEM', 'ICRF'),
223+
('EXTRA_PREC', 'NO'),
224+
('CENTER', "'290'"),
225+
('START_TIME', '"2080-01-01"'),
226+
('STOP_TIME', '"2080-02-01"'),
227+
('STEP_SIZE', '"3h"'),
228+
('AIRMASS', '1.2'),
229+
('SKIP_DAYLT', 'YES')
230+
] + list(optional_settings.items()),
231+
)
232+
233+
190234
def test_elements_query_payload():
191235
res = (jplhorizons.Horizons(id='Ceres', location='500@10',
192236
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)