@@ -615,7 +615,7 @@ def ephemerides_async(self, *, airmass_lessthan=99,
615
615
if self .id is None :
616
616
raise ValueError ("'id' parameter not set. Query aborted." )
617
617
elif isinstance (self .id , dict ):
618
- commandline = "g:" + self ._format_site_coords (self .id )
618
+ commandline = self ._format_id_coords (self .id )
619
619
else :
620
620
commandline = str (self .id )
621
621
if self .location is None :
@@ -850,16 +850,20 @@ def elements_async(self, *, get_query_payload=False,
850
850
851
851
URL = conf .horizons_server
852
852
853
- # check for required information
853
+ # check for required information and assemble commandline stub
854
854
if self .id is None :
855
855
raise ValueError ("'id' parameter not set. Query aborted." )
856
+ elif isinstance (self .id , dict ):
857
+ commandline = self ._format_id_coords (self .id )
858
+ else :
859
+ commandline = str (self .id )
860
+
856
861
if self .location is None :
857
862
self .location = '500@10'
858
863
if self .epochs is None :
859
864
self .epochs = Time .now ().jd
860
865
861
- # assemble commandline based on self.id_type
862
- commandline = str (self .id )
866
+ # expand commandline based on self.id_type
863
867
if self .id_type in ['designation' , 'name' ,
864
868
'asteroid_name' , 'comet_name' ]:
865
869
commandline = ({'designation' : 'DES=' ,
@@ -878,7 +882,7 @@ def elements_async(self, *, get_query_payload=False,
878
882
commandline += ' NOFRAG;'
879
883
880
884
if isinstance (self .location , dict ):
881
- raise ValueError (('cannot use topographic position in orbital'
885
+ raise ValueError (('cannot use topographic position in orbital '
882
886
'elements query' ))
883
887
884
888
# configure request_payload for ephemerides query
@@ -1099,7 +1103,7 @@ def vectors_async(self, *, get_query_payload=False,
1099
1103
if self .id is None :
1100
1104
raise ValueError ("'id' parameter not set. Query aborted." )
1101
1105
elif isinstance (self .id , dict ):
1102
- commandline = "g:" + self ._format_site_coords (self .id )
1106
+ commandline = self ._format_id_coords (self .id )
1103
1107
else :
1104
1108
commandline = str (self .id )
1105
1109
if self .location is None :
@@ -1211,6 +1215,7 @@ def _prep_loc_dict(loc_dict, attr_name):
1211
1215
@staticmethod
1212
1216
def _location_to_params (loc_dict ):
1213
1217
"""translate a 'location' dict to request parameters"""
1218
+
1214
1219
location = {
1215
1220
"CENTER" : f"coord@{ loc_dict ['body' ]} " ,
1216
1221
"COORD_TYPE" : "GEODETIC" ,
@@ -1219,10 +1224,20 @@ def _location_to_params(loc_dict):
1219
1224
return location
1220
1225
1221
1226
@staticmethod
1222
- def _format_site_coords (coords ):
1223
- # formats lon/lat/elevation/body (e.g., id and location dictionaries) for the Horizons API
1227
+ def _format_coords (coords ):
1228
+ """Dictionary to Horizons API formatted lon/lat/elevation coordinate triplet."""
1224
1229
return (f"{ coords ['lon' ].to_value ('deg' )} ,{ coords ['lat' ].to_value ('deg' )} ,"
1225
- f"{ coords ['elevation' ].to_value ('km' )} @{ coords ['body' ]} " )
1230
+ f"{ coords ['elevation' ].to_value ('km' )} " )
1231
+
1232
+ @staticmethod
1233
+ def _format_site_coords (coords ):
1234
+ """`location` dictionary to SITE_COORDS parameter."""
1235
+ return HorizonsClass ._format_coords (coords )
1236
+
1237
+ @staticmethod
1238
+ def _format_id_coords (coords ):
1239
+ """`id` dictionary to COMMAND parameter's coordinate format."""
1240
+ return f"g:{ HorizonsClass ._format_coords (coords )} @{ coords ['body' ]} "
1226
1241
1227
1242
def _parse_result (self , response , verbose = None ):
1228
1243
"""
0 commit comments