@@ -550,7 +550,7 @@ def ephemerides_async(self, *, airmass_lessthan=99,
550
550
551
551
URL = conf .horizons_server
552
552
553
- # check for required information
553
+ # check for required information and assemble commanddline stub
554
554
if self .id is None :
555
555
raise ValueError ("'id' parameter not set. Query aborted." )
556
556
elif isinstance (self .id , dict ):
@@ -564,7 +564,7 @@ def ephemerides_async(self, *, airmass_lessthan=99,
564
564
self .location = '500@399'
565
565
if self .epochs is None :
566
566
self .epochs = Time .now ().jd
567
- # assemble commandline based on self.id_type
567
+ # expand commandline based on self.id_type
568
568
569
569
if self .id_type in ['designation' , 'name' ,
570
570
'asteroid_name' , 'comet_name' ]:
@@ -601,12 +601,9 @@ def ephemerides_async(self, *, airmass_lessthan=99,
601
601
('EXTRA_PREC' , {True : 'YES' , False : 'NO' }[extra_precision ])])
602
602
603
603
if isinstance (self .location , dict ):
604
- request_payload ['CENTER' ] = 'coord@{:s}' .format (
605
- str (self .location ['body' ]))
606
- request_payload ['COORD_TYPE' ] = 'GEODETIC'
607
- request_payload ['SITE_COORD' ] = "'{:f},{:f},{:f}'" .format (
608
- self .location ['lon' ], self .location ['lat' ],
609
- self .location ['elevation' ])
604
+ request_payload = dict (
605
+ ** request_payload , ** self ._location_to_params (self .location )
606
+ )
610
607
else :
611
608
request_payload ['CENTER' ] = "'" + str (self .location ) + "'"
612
609
@@ -1046,17 +1043,21 @@ def vectors_async(self, *, get_query_payload=False,
1046
1043
1047
1044
URL = conf .horizons_server
1048
1045
1049
- # check for required information
1046
+ # check for required information and assemble commandline stub
1050
1047
if self .id is None :
1051
1048
raise ValueError ("'id' parameter not set. Query aborted." )
1049
+ elif isinstance (self .id , dict ):
1050
+ commandline = (
1051
+ f"g:{ self .id ['lon' ]} ,{ self .id ['lat' ]} ,"
1052
+ f"{ self .id ['elevation' ]} @{ self .id ['body' ]} "
1053
+ )
1054
+ else :
1055
+ commandline = str (self .id )
1052
1056
if self .location is None :
1053
1057
self .location = '500@10'
1054
1058
if self .epochs is None :
1055
1059
self .epochs = Time .now ().jd
1056
-
1057
- # assemble commandline based on self.id_type
1058
- commandline = str (self .id )
1059
-
1060
+ # expand commandline based on self.id_type
1060
1061
if self .id_type in ['designation' , 'name' ,
1061
1062
'asteroid_name' , 'comet_name' ]:
1062
1063
commandline = ({'designation' : 'DES=' ,
@@ -1074,18 +1075,17 @@ def vectors_async(self, *, get_query_payload=False,
1074
1075
commandline += ' CAP{:s};' .format (closest_apparition )
1075
1076
if no_fragments :
1076
1077
commandline += ' NOFRAG;'
1077
-
1078
- if isinstance (self .location , dict ):
1079
- raise ValueError (('cannot use topographic position in state'
1080
- 'vectors query' ))
1078
+ #
1079
+ # if isinstance(self.location, dict):
1080
+ # raise ValueError(('cannot use topographic position in state'
1081
+ # 'vectors query'))
1081
1082
1082
1083
# configure request_payload for ephemerides query
1083
1084
request_payload = OrderedDict ([
1084
1085
('format' , 'text' ),
1085
1086
('EPHEM_TYPE' , 'VECTORS' ),
1086
1087
('OUT_UNITS' , 'AU-D' ),
1087
1088
('COMMAND' , '"' + commandline + '"' ),
1088
- ('CENTER' , ("'" + str (self .location ) + "'" )),
1089
1089
('CSV_FORMAT' , ('"YES"' )),
1090
1090
('REF_PLANE' , {'ecliptic' : 'ECLIPTIC' ,
1091
1091
'earth' : 'FRAME' ,
@@ -1100,7 +1100,12 @@ def vectors_async(self, *, get_query_payload=False,
1100
1100
('VEC_DELTA_T' , {True : 'YES' , False : 'NO' }[delta_T ]),
1101
1101
('OBJ_DATA' , 'YES' )]
1102
1102
)
1103
-
1103
+ if isinstance (self .location , dict ):
1104
+ request_payload = dict (
1105
+ ** request_payload , ** self ._location_to_params (self .location )
1106
+ )
1107
+ else :
1108
+ request_payload ['CENTER' ] = "'" + str (self .location ) + "'"
1104
1109
# parse self.epochs
1105
1110
if isinstance (self .epochs , (list , tuple , ndarray )):
1106
1111
request_payload ['TLIST' ] = "\n " .join ([str (epoch ) for epoch in
@@ -1148,6 +1153,7 @@ def vectors_async(self, *, get_query_payload=False,
1148
1153
# ---------------------------------- parser functions
1149
1154
@staticmethod
1150
1155
def _prep_loc_dict (loc_dict , attr_name ):
1156
+ """prepare coord specification dict for 'location' or 'id'"""
1151
1157
if {'lat' , 'lon' , 'elevation' } - set (loc_dict .keys ()) != set ():
1152
1158
raise ValueError (
1153
1159
f"dict values for '{ attr_name } ' must contain 'lat', 'lon', "
@@ -1157,6 +1163,19 @@ def _prep_loc_dict(loc_dict, attr_name):
1157
1163
loc_dict ['body' ] = 399
1158
1164
return loc_dict
1159
1165
1166
+ @staticmethod
1167
+ def _location_to_params (loc_dict ):
1168
+ """translate a 'location' dict to a dict of request parameters"""
1169
+ loc_dict = {
1170
+ "CENTER" : f"coord@{ loc_dict ['body' ]} " ,
1171
+ "COORD_TYPE" : "GEODETIC" ,
1172
+ "SITE_COORD" : "," .join (
1173
+ str (float (loc_dict [k ])) for k in ['lat' , 'lon' , 'elevation' ]
1174
+ )
1175
+ }
1176
+ loc_dict ["SITE_COORD" ] = f"'{ loc_dict ['SITE_COORD' ]} '"
1177
+ return loc_dict
1178
+
1160
1179
def _parse_result (self , response , verbose = None ):
1161
1180
"""
1162
1181
Parse query result to a `~astropy.table.Table` object.
0 commit comments