1
1
# Licensed under a 3-clause BSD style license - see LICENSE.rst
2
-
2
+ from typing import Mapping
3
3
4
4
# 1. standard library imports
5
5
from numpy import nan
@@ -108,8 +108,10 @@ def __init__(self, id=None, *, location=None, epochs=None,
108
108
"""
109
109
110
110
super ().__init__ ()
111
- self .id = id
112
- self .location = location
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
+ )
113
115
114
116
# check for epochs to be dict or list-like; else: make it a list
115
117
if epochs is not None :
@@ -538,13 +540,26 @@ def ephemerides_async(self, *, airmass_lessthan=99,
538
540
# check for required information
539
541
if self .id is None :
540
542
raise ValueError ("'id' parameter not set. Query aborted." )
543
+ 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
+ commandline = (
552
+ f"g:{ self .id ['lon' ]} ,{ self .id ['lat' ]} ,"
553
+ f"{ self .id ['elevation' ]} @{ self .id ['body' ]} "
554
+ )
555
+ else :
556
+ commandline = str (self .id )
541
557
if self .location is None :
542
558
self .location = '500@399'
543
559
if self .epochs is None :
544
560
self .epochs = Time .now ().jd
545
-
546
561
# assemble commandline based on self.id_type
547
- commandline = str ( self . id )
562
+
548
563
if self .id_type in ['designation' , 'name' ,
549
564
'asteroid_name' , 'comet_name' ]:
550
565
commandline = ({'designation' : 'DES=' ,
@@ -580,10 +595,13 @@ def ephemerides_async(self, *, airmass_lessthan=99,
580
595
('EXTRA_PREC' , {True : 'YES' , False : 'NO' }[extra_precision ])])
581
596
582
597
if isinstance (self .location , dict ):
583
- if ('lon' not in self .location or 'lat' not in self .location or
584
- 'elevation' not in self .location ):
585
- raise ValueError (("'location' must contain lon, lat, "
586
- "elevation" ))
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
+ )
587
605
588
606
if 'body' not in self .location :
589
607
self .location ['body' ] = '399'
@@ -1181,14 +1199,23 @@ def _parse_result(self, response, verbose=None):
1181
1199
H , G = nan , nan
1182
1200
M1 , M2 , k1 , k2 , phcof = nan , nan , nan , nan , nan
1183
1201
headerline = []
1202
+ centername = ''
1184
1203
for idx , line in enumerate (src ):
1185
1204
# read in ephemerides header line; replace some field names
1186
1205
if (self .query_type == 'ephemerides' and
1187
1206
"Date__(UT)__HR:MN" in line ):
1188
1207
headerline = str (line ).split (',' )
1189
1208
headerline [2 ] = 'solar_presence'
1190
- headerline [3 ] = 'flags'
1209
+ if 'Earth' in centername :
1210
+ headerline [3 ] = 'lunar_presence'
1211
+ else :
1212
+ headerline [3 ] = 'interfering_body'
1191
1213
headerline [- 1 ] = '_dump'
1214
+ if (
1215
+ isinstance (self .id , dict ) or str (self .id ).startswith ('g:' )
1216
+ ):
1217
+ headerline [4 ] = 'nearside_flag'
1218
+ headerline [5 ] = 'illumination_flag'
1192
1219
# read in elements header line
1193
1220
elif (self .query_type == 'elements' and
1194
1221
"JDTDB," in line ):
@@ -1208,6 +1235,9 @@ def _parse_result(self, response, verbose=None):
1208
1235
# read in targetname
1209
1236
if "Target body name" in line :
1210
1237
targetname = line [18 :50 ].strip ()
1238
+ # read in center body name
1239
+ if "Center body name" in line :
1240
+ centername = line [18 :50 ].strip ()
1211
1241
# read in H and G (if available)
1212
1242
if "rotational period in hours)" in line :
1213
1243
HGline = src [idx + 2 ].split ('=' )
0 commit comments