@@ -51,8 +51,16 @@ def __init__(self, id=None, *, location=None, epochs=None,
51
51
Parameters
52
52
----------
53
53
54
- id : str, required
55
- Name, number, or designation of the object to be queried.
54
+ id : str or dict, required
55
+ Name, number, or designation of target object. Uses the same codes
56
+ as JPL Horizons. Arbitrary topocentric coordinates can be added
57
+ in a dict. The dict has to be of the form
58
+ {``'lon'``: longitude in deg (East positive, West
59
+ negative), ``'lat'``: latitude in deg (North positive, South
60
+ negative), ``'elevation'``: elevation in km above the reference
61
+ ellipsoid, [``'body'``: Horizons body ID of the central body;
62
+ optional; if this value is not provided it is assumed that this
63
+ location is on Earth]}.
56
64
57
65
location : str or dict, optional
58
66
Observer's location for ephemerides queries or center body name for
@@ -108,11 +116,16 @@ def __init__(self, id=None, *, location=None, epochs=None,
108
116
"""
109
117
110
118
super ().__init__ ()
111
- self .id = id if not isinstance (id , Mapping ) else dict (id )
112
- self .location = (
113
- location if not isinstance (location , Mapping ) else dict (location )
114
- )
115
-
119
+ # check & format coordinate dictionaries for id and location; simply
120
+ # treat other values as given
121
+ if isinstance (id , Mapping ):
122
+ self .id = self ._prep_loc_dict (dict (id ), "id" )
123
+ else :
124
+ self .id = id
125
+ if isinstance (location , Mapping ):
126
+ self .location = self ._prep_loc_dict (dict (location ), "location" )
127
+ else :
128
+ self .location = location
116
129
# check for epochs to be dict or list-like; else: make it a list
117
130
if epochs is not None :
118
131
if isinstance (epochs , (list , tuple , ndarray )):
@@ -541,13 +554,6 @@ def ephemerides_async(self, *, airmass_lessthan=99,
541
554
if self .id is None :
542
555
raise ValueError ("'id' parameter not set. Query aborted." )
543
556
elif isinstance (self .id , dict ):
544
- if {'lat' , 'lon' , 'elevation' } - set (self .id .keys ()) != set ():
545
- raise ValueError (
546
- "dict values for 'id' must contain 'lat', 'lon', "
547
- "'elevation' (and optionally 'body')"
548
- )
549
- if 'body' not in self .id :
550
- self .id ['body' ] = 399
551
557
commandline = (
552
558
f"g:{ self .id ['lon' ]} ,{ self .id ['lat' ]} ,"
553
559
f"{ self .id ['elevation' ]} @{ self .id ['body' ]} "
@@ -595,16 +601,6 @@ def ephemerides_async(self, *, airmass_lessthan=99,
595
601
('EXTRA_PREC' , {True : 'YES' , False : 'NO' }[extra_precision ])])
596
602
597
603
if isinstance (self .location , dict ):
598
- if (
599
- {'lat' , 'lon' , 'elevation' } - set (self .location .keys ())
600
- ) != set ():
601
- raise ValueError (
602
- "dict values for 'location' must contain 'lat', 'lon', "
603
- "'elevation' (and optionally 'body')"
604
- )
605
-
606
- if 'body' not in self .location :
607
- self .location ['body' ] = '399'
608
604
request_payload ['CENTER' ] = 'coord@{:s}' .format (
609
605
str (self .location ['body' ]))
610
606
request_payload ['COORD_TYPE' ] = 'GEODETIC'
@@ -1150,6 +1146,16 @@ def vectors_async(self, *, get_query_payload=False,
1150
1146
return response
1151
1147
1152
1148
# ---------------------------------- parser functions
1149
+ @staticmethod
1150
+ def _prep_loc_dict (loc_dict , attr_name ):
1151
+ if {'lat' , 'lon' , 'elevation' } - set (loc_dict .keys ()) != set ():
1152
+ raise ValueError (
1153
+ f"dict values for '{ attr_name } ' must contain 'lat', 'lon', "
1154
+ "'elevation' (and optionally 'body')"
1155
+ )
1156
+ if 'body' not in loc_dict :
1157
+ loc_dict ['body' ] = 399
1158
+ return loc_dict
1153
1159
1154
1160
def _parse_result (self , response , verbose = None ):
1155
1161
"""
0 commit comments