diff --git a/space/tle.py b/space/tle.py index ff2433d..ccde75a 100644 --- a/space/tle.py +++ b/space/tle.py @@ -20,6 +20,9 @@ from .wspace import ws +from space.tle_dir.plot import plot + + log = logging.getLogger(__name__) @@ -422,6 +425,7 @@ def space_tle(*argv): space-tle find ... space-tle history [--last ] ... space-tle dump [--all] + space-tle plot ... space-tle stats Options: @@ -434,6 +438,7 @@ def space_tle(*argv): history Display all the recorded TLEs for a given object insert Insert TLEs into the database (file or stdin) stats Display statistics on the database + plot Display the (altitude) history of an object Selector of the object, see `space sat` File to insert in the database -l, --last Get the last TLE @@ -543,6 +548,9 @@ def space_tle(*argv): print("{0.name}\n{0}\n".format(tle)) elif args["stats"]: print_stats() + elif args["plot"]: + sats = list(Sat.from_selector(*args[""])) + plot(db, sats) else: try: sats = list(Sat.from_selector(*args[""])) diff --git a/space/tle_dir/plot.py b/space/tle_dir/plot.py new file mode 100644 index 0000000..758fac6 --- /dev/null +++ b/space/tle_dir/plot.py @@ -0,0 +1,41 @@ +import matplotlib.pyplot as plt + +from beyond.constants import Earth + + +def plot(db, sats): + fig = plt.figure() # figsize=[10,8]) + ax = fig.add_subplot(111) + + for sat in sats: + tles = list(db.history(number=None, cospar_id=sat.cospar_id)) + + color = next(ax._get_lines.prop_cycler)['color'] + + epochs = [tle.epoch for tle in tles] + perigee = [(tle.orbit().infos.rp - Earth.equatorial_radius)/1e3 for tle in tles] + apogee = [(tle.orbit().infos.ra - Earth.equatorial_radius)/1e3 for tle in tles] + + ax.plot( + epochs, + perigee, + label='{sat.norad_id} / {sat.cospar_id}'.format(sat=sat), + color=color, + marker = 'v', + linestyle='--' + ) + ax.plot( + epochs, apogee, + color=color, + marker = '^', + linestyle='--' + ) + + ax.set_xlabel('Epoch') + ax.set_ylabel('Altitude / km') + + fig.autofmt_xdate() + plt.legend() + + ax.grid() + plt.show()