Skip to content

Commit 3c92254

Browse files
emolterbsipocz
authored andcommitted
made adding units with QTable back-compatible with 3.7
1 parent 65f5167 commit 3c92254

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

astroquery/solarsystem/pds/core.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,21 +270,29 @@ def _parse_result(self, response, verbose=None):
270270
# minor body table part 1
271271
elif group.startswith("Body"):
272272
group = "NAIF " + group # fixing lack of header for NAIF ID
273+
bodytable_names = ("NAIF ID", "Body", "RA", "Dec", "RA (deg)", "Dec (deg)", "dRA", "dDec")
274+
bodytable_units = [None, None, None, None, u.deg, u.deg, u.arcsec, u.arcsec]
273275
bodytable = table.QTable.read(group, format="ascii.fixed_width",
274276
col_starts=(0, 4, 18, 35, 54, 68, 80, 91),
275277
col_ends=(4, 18, 35, 54, 68, 80, 91, 102),
276-
names=("NAIF ID", "Body", "RA", "Dec", "RA (deg)", "Dec (deg)", "dRA", "dDec"),
277-
units=([None, None, None, None, u.deg, u.deg, u.arcsec, u.arcsec]))
278+
names=bodytable_names)
279+
# units=(bodytable_units)) # this much cleaner way of adding units is supported in later versions but not in 3.7
280+
for name, unit in zip(bodytable_names, bodytable_units):
281+
bodytable[name].unit = unit
278282

279283
# minor body table part 2
280284
elif group.startswith("Sub-"):
281285
group = "\n".join(group.split("\n")[1:]) # fixing two-row header
282286
group = "NAIF" + group[4:]
287+
bodytable2_names = ("NAIF ID", "Body", "sub_obs_lon", "sub_obs_lat", "sub_sun_lon", "sub_sun_lat", "phase", "distance")
288+
bodytable2_units = [None, None, u.deg, u.deg, u.deg, u.deg, u.deg, u.km * 1e6]
283289
bodytable2 = table.QTable.read(group, format="ascii.fixed_width",
284290
col_starts=(0, 4, 18, 28, 37, 49, 57, 71),
285291
col_ends=(4, 18, 28, 37, 49, 57, 71, 90),
286-
names=("NAIF ID", "Body", "sub_obs_lon", "sub_obs_lat", "sub_sun_lon", "sub_sun_lat", "phase", "distance"),
287-
units=([None, None, u.deg, u.deg, u.deg, u.deg, u.deg, u.km * 1e6]))
292+
names=bodytable2_names)
293+
# units=(bodytable_units)) # this much cleaner way of adding units is supported in later versions but not in 3.7
294+
for name, unit in zip(bodytable2_names, bodytable2_units):
295+
bodytable2[name].unit = unit
288296

289297
# ring plane data
290298
elif group.startswith("Ring s"):
@@ -293,7 +301,7 @@ def _parse_result(self, response, verbose=None):
293301
l = line.split(":")
294302
if "Ring sub-solar latitude" in l[0]:
295303
[sub_sun_lat, sub_sun_lat_min, sub_sun_lat_max] = [
296-
float(s.strip(", \n()")) for s in re.split("\(|to", l[1])
304+
float(s.strip(", \n()")) for s in re.split(r"\(|to", l[1])
297305
]
298306
systemtable = {
299307
"sub_sun_lat": sub_sun_lat * u.deg,
@@ -343,11 +351,15 @@ def _parse_result(self, response, verbose=None):
343351
# --------- below this line, planet-specific info ------------
344352
# Uranus individual rings data
345353
elif group.startswith("Ring "):
354+
ringtable_names = ("ring", "pericenter", "ascending node")
355+
ringtable_units = [None, u.deg, u.deg]
346356
ringtable = table.QTable.read(" " + group, format="ascii.fixed_width",
347357
col_starts=(5, 18, 29),
348358
col_ends=(18, 29, 36),
349-
names=("ring", "pericenter", "ascending node"),
350-
units=([None, u.deg, u.deg]))
359+
names=ringtable_names)
360+
# units=(ringtable_units)) # this much cleaner way of adding units is supported in later versions but not in 3.7
361+
for name, unit in zip(ringtable_names, ringtable_units):
362+
ringtable[name].unit = unit
351363

352364
# Saturn F-ring data
353365
elif group.startswith("F Ring"):

0 commit comments

Comments
 (0)