Skip to content
This repository was archived by the owner on May 2, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions space/tle.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

from .wspace import ws

from space.tle_dir.plot import plot


log = logging.getLogger(__name__)


Expand Down Expand Up @@ -422,6 +425,7 @@ def space_tle(*argv):
space-tle find <text> ...
space-tle history [--last <nb>] <selector>...
space-tle dump [--all]
space-tle plot <selector>...
space-tle stats

Options:
Expand All @@ -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> Selector of the object, see `space sat`
<file> File to insert in the database
-l, --last <nb> Get the last <nb> TLE
Expand Down Expand Up @@ -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["<selector>"]))
plot(db, sats)
else:
try:
sats = list(Sat.from_selector(*args["<selector>"]))
Expand Down
41 changes: 41 additions & 0 deletions space/tle_dir/plot.py
Original file line number Diff line number Diff line change
@@ -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()