Skip to content

Commit fce55ec

Browse files
committed
Better column normalization.
Remove ability to run module via __main__ to avoid package import warning.
1 parent 75b875d commit fce55ec

File tree

3 files changed

+45
-38
lines changed

3 files changed

+45
-38
lines changed

docs/sbpy/data/ephem.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,10 @@ For example to get the ephemeris of comet 2P/Encke from the Minor Planet Center
325325
over the next month::
326326

327327
$ sbpy-ephem mpc 2P
328-
Date RA Dec r Delta Phase Elongation V Proper motion Direction
328+
# requested target: 2P
329+
# returned target: 2P
330+
# location: 500
331+
date RA Dec rh delta phase solarelong V Proper motion Direction
329332
deg deg AU AU deg deg mag arcsec / h deg
330333
----------------------- ----------- ----------- ----- ----- ----- ---------- ---- ------------- ---------
331334
2024-06-27 00:00:00.000 22:46:17.90 -11:05:59.0 3.079 2.485 17.2 116.7 20.8 18.25 249.6
@@ -359,5 +362,3 @@ over the next month::
359362
2024-07-25 00:00:00.000 22:23:58.60 -13:03:20.0 3.245 2.331 9.2 149.1 21.0 42.17 251.1
360363
2024-07-26 00:00:00.000 22:22:52.60 -13:08:49.0 3.25 2.329 8.9 150.3 21.0 42.77 251.2
361364
2024-07-27 00:00:00.000 22:21:45.60 -13:14:21.0 3.256 2.327 8.5 151.6 21.0 43.34 251.3
362-
363-
Alternatively, the script may be run via ``python3 -m sbpy.data.ephem``.

sbpy/data/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Conf():
3838
fieldnames_info = [
3939
# General
4040
{'description': 'Target Identifier',
41-
'fieldnames': ['targetname', 'id', 'Object'],
41+
'fieldnames': ['targetname', 'Targetname', 'id', 'Object', 'object', 'target', 'Target'],
4242
'provenance': ['orbit', 'ephem', 'obs', 'phys'],
4343
'dimension': None},
4444
{'description': 'Target Designation',

sbpy/data/ephem.py

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import os
2121
import argparse
2222
from warnings import warn
23-
from typing import Union
23+
from typing import List, Union
2424

2525
import numpy as np
2626
from numpy import ndarray, hstack, iterable
@@ -484,12 +484,12 @@ def from_mpc(cls, targetids, epochs=None, location='500', ra_format=None,
484484

485485
@classmethod
486486
@requires("astroquery")
487-
@cite({'data source': 'http://vo.imcce.fr/webservices/miriade/',
487+
@cite({'data source': 'https://vo.imcce.fr/webservices/miriade/',
488488
'software: astroquery': '2019AJ....157...98G'})
489489
def from_miriade(cls, targetids, objtype='asteroid',
490490
epochs=None, location='500', **kwargs):
491491
"""Load target ephemerides from
492-
`IMCCE Miriade <http://vo.imcce.fr/webservices/miriade/>`_ using
492+
`IMCCE Miriade <https://vo.imcce.fr/webservices/miriade/>`_ using
493493
`astroquery.imcce.MiriadeClass.get_ephemerides`
494494
495495
Parameters
@@ -984,14 +984,8 @@ def main():
984984
epochs=epochs,
985985
location=args.location,
986986
)
987-
988-
# simplify output
989-
for k in ["Targetname"]:
990-
del eph.table[k]
991987
elif args.service == "horizons":
992-
epochs["step"] = (
993-
int(args.step) if args.step.unit == u.dimensionless_unscaled else args.step
994-
)
988+
epochs["step"] = args.step
995989

996990
# comet specific options: always avoid multiple fragment matches, always
997991
# return closest apparition
@@ -1020,8 +1014,9 @@ def main():
10201014
eph["epoch"].format = "iso"
10211015
eph["ra"] = eph["ra"].unmasked
10221016
eph["dec"] = eph["dec"].unmasked
1023-
for k in ["M1", "k1", "solar_presence", "lunar_presence", "targetname"]:
1024-
del eph.table[k]
1017+
for k in ["M1", "k1", "solar_presence", "lunar_presence"]:
1018+
if k in eph.table.colnames:
1019+
del eph.table[k]
10251020
elif args.service == "miriade":
10261021
if args.step.unit == u.dimensionless_unscaled:
10271022
epochs["number"] = int(args.step)
@@ -1038,8 +1033,7 @@ def main():
10381033

10391034
# simplify output
10401035
eph["epoch"].format = "iso"
1041-
for k in ["target"]:
1042-
del eph.table[k]
1036+
10431037
for k in eph.field_names:
10441038
if hasattr(eph[k], "unmasked"):
10451039
eph[k] = eph[k].unmasked
@@ -1057,28 +1051,40 @@ def main():
10571051
eph["ra"].info.format = lambda x: x.to_string()
10581052
eph["dec"].info.format = lambda x: x.to_string()
10591053

1060-
# unified output order for most common columns
1061-
fields = eph.field_names
1062-
for k in eph._translate_columns(
1063-
[
1064-
"RA*cos(Dec)_rate",
1065-
"DEC_rate",
1066-
"elong",
1067-
"phase",
1068-
"delta",
1069-
"rh",
1070-
"dec",
1071-
"ra",
1072-
"epoch",
1073-
],
1074-
ignore_missing=True,
1075-
):
1054+
# normalize output for most common columns
1055+
first_fields: List[str] = [
1056+
"target",
1057+
"date",
1058+
"RA",
1059+
"Dec",
1060+
"rh",
1061+
"delta",
1062+
"phase",
1063+
"solarelong",
1064+
"DEC_rate",
1065+
"RA*cos(Dec)_rate",
1066+
]
1067+
1068+
k: str
1069+
translated: str
1070+
for k in first_fields:
1071+
if k not in eph:
1072+
continue
1073+
translated = eph._translate_columns(k)[0]
1074+
eph.table.rename_column(translated, k)
1075+
1076+
# re-order
1077+
fields: List[str] = eph.field_names
1078+
for k in reversed(first_fields):
10761079
if k not in fields:
10771080
continue
10781081
fields.insert(0, fields.pop(fields.index(k)))
10791082

1080-
eph[fields].table.pprint_all()
1081-
1083+
eph = eph[fields]
1084+
target = eph["target"][0]
1085+
del eph.table["target"]
10821086

1083-
if __name__ == "__main__":
1084-
main()
1087+
print(f"# requested target: {args.target}")
1088+
print(f"# returned target: {target}")
1089+
print(f"# location: {args.location}")
1090+
eph.table.pprint_all()

0 commit comments

Comments
 (0)