Created
October 28, 2019 15:52
-
-
Save cbassa/1ec8baadb3d598b08c9e1daad2ed1ba3 to your computer and use it in GitHub Desktop.
Extract LightSail data from spacetrack and plot it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import json | |
import datetime | |
from spacetrack import SpaceTrackClient | |
import matplotlib.pyplot as plt | |
import matplotlib.dates as mdates | |
if __name__ == "__main__": | |
# Login | |
st = SpaceTrackClient("username", "password") | |
# Get data | |
data = json.loads(st.tle(norad_cat_id=44420, orderby="EPOCH", format="json")) | |
# Initialize arrays | |
epoch = [] | |
eccentricity = [] | |
mean_motion = [] | |
# Loop over entries | |
for d in data: | |
# Convert epoch to datetime | |
epoch.append(datetime.datetime.strptime(d["EPOCH"], "%Y-%m-%d %H:%M:%S")) | |
# Convert eccentricity and mean motion to floats | |
eccentricity.append(float(d["ECCENTRICITY"])) | |
mean_motion.append(float(d["MEAN_MOTION"])) | |
# Intialize figure with two panels, share the horizontal axis | |
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(15, 8), sharex=True) | |
# Set formatting for horizontal axis | |
date_format = mdates.DateFormatter("%Y-%m-%d") | |
fig.autofmt_xdate(rotation=0, ha="center") | |
# Plot eccentricity | |
ax1.plot_date(epoch, eccentricity, linestyle="-") | |
ax1.xaxis.set_major_locator(mdates.MonthLocator()) | |
ax1.xaxis.set_major_formatter(date_format) | |
ax1.grid() | |
ax1.set_ylabel("Eccentricity") | |
ax1.set_title("LightSail-A orbital parameters") | |
# Plot mean motion | |
ax2.plot_date(epoch, mean_motion, linestyle="-") | |
ax2.xaxis.set_major_locator(mdates.MonthLocator()) | |
ax2.xaxis.set_major_formatter(date_format) | |
ax2.grid() | |
ax2.set_ylabel("Mean motion (revolutions/day)") | |
plt.tight_layout() | |
plt.savefig("lightsail.png", bbox_inches="tight") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment