Skip to content

Commit 7b5abae

Browse files
committed
fix table parsing for eph with coordinates, allow eph id dict specification
1 parent a867890 commit 7b5abae

File tree

2 files changed

+44
-11
lines changed

2 files changed

+44
-11
lines changed

astroquery/jplhorizons/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ class Conf(_config.ConfigNamespace):
5050
'k2': ('k2', '---'),
5151
'phasecoeff': ('phasecoeff', 'mag/deg'),
5252
'solar_presence': ('solar_presence', '---'),
53-
'flags': ('flags', '---'),
53+
'lunar_presence': ('lunar_presence', '---'),
54+
'interfering_body': ('interfering_body', '---'),
55+
'illumination_flag': ('illumination_flag', '---'),
56+
'nearside_flag': ('nearside_flag', '---'),
5457
'R.A._(ICRF)': ('RA', 'deg'),
5558
'DEC_(ICRF)': ('DEC', 'deg'),
5659
'R.A.___(ICRF)': ('RA', 'deg'),

astroquery/jplhorizons/core.py

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Licensed under a 3-clause BSD style license - see LICENSE.rst
2-
2+
from typing import Mapping
33

44
# 1. standard library imports
55
from numpy import nan
@@ -108,8 +108,10 @@ def __init__(self, id=None, *, location=None, epochs=None,
108108
"""
109109

110110
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+
)
113115

114116
# check for epochs to be dict or list-like; else: make it a list
115117
if epochs is not None:
@@ -538,13 +540,26 @@ def ephemerides_async(self, *, airmass_lessthan=99,
538540
# check for required information
539541
if self.id is None:
540542
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)
541557
if self.location is None:
542558
self.location = '500@399'
543559
if self.epochs is None:
544560
self.epochs = Time.now().jd
545-
546561
# assemble commandline based on self.id_type
547-
commandline = str(self.id)
562+
548563
if self.id_type in ['designation', 'name',
549564
'asteroid_name', 'comet_name']:
550565
commandline = ({'designation': 'DES=',
@@ -580,10 +595,13 @@ def ephemerides_async(self, *, airmass_lessthan=99,
580595
('EXTRA_PREC', {True: 'YES', False: 'NO'}[extra_precision])])
581596

582597
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+
)
587605

588606
if 'body' not in self.location:
589607
self.location['body'] = '399'
@@ -1181,14 +1199,23 @@ def _parse_result(self, response, verbose=None):
11811199
H, G = nan, nan
11821200
M1, M2, k1, k2, phcof = nan, nan, nan, nan, nan
11831201
headerline = []
1202+
centername = ''
11841203
for idx, line in enumerate(src):
11851204
# read in ephemerides header line; replace some field names
11861205
if (self.query_type == 'ephemerides' and
11871206
"Date__(UT)__HR:MN" in line):
11881207
headerline = str(line).split(',')
11891208
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'
11911213
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'
11921219
# read in elements header line
11931220
elif (self.query_type == 'elements' and
11941221
"JDTDB," in line):
@@ -1208,6 +1235,9 @@ def _parse_result(self, response, verbose=None):
12081235
# read in targetname
12091236
if "Target body name" in line:
12101237
targetname = line[18:50].strip()
1238+
# read in center body name
1239+
if "Center body name" in line:
1240+
centername = line[18:50].strip()
12111241
# read in H and G (if available)
12121242
if "rotational period in hours)" in line:
12131243
HGline = src[idx + 2].split('=')

0 commit comments

Comments
 (0)