Skip to content

Instantly share code, notes, and snippets.

@jorgepiloto
Last active May 4, 2019 12:32
Show Gist options
  • Save jorgepiloto/acb36f0b995bf7f9619ca605bef1581d to your computer and use it in GitHub Desktop.
Save jorgepiloto/acb36f0b995bf7f9619ca605bef1581d to your computer and use it in GitHub Desktop.
This gist holds the groundtrack plotter function
""" This script holds the function for plotting the groundtracks. """
# Poliastro modules
from poliastro.twobody import Orbit
from poliastro.bodies import Earth
# Astropy modules
from astropy import coordinates as coord
from astropy import units as u
# Plotting modules
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
def groundtrack(ss):
""" Plots the groundtrack of an Orbit.
Parameters
----------
ss: poliastro.twobody.orbit.Orbit
Orbit for making the groundtrack
"""
# Transform GCRS to ITRS
ss_gcrs = ss.sample()
ss_itrs = coord.GCRS(coord.CartesianRepresentation(ss_gcrs.x, ss_gcrs.y, ss_gcrs.z)).transform_to(coord.ITRS)
# Convert both systems to lat and lon
latlon_gcrs = ss_gcrs.represent_as(coord.SphericalRepresentation)
latlon_itrs = ss_itrs.represent_as(coord.SphericalRepresentation)
# Plotting the groundtrack
fig, ax = plt.subplots()
ax = plt.axes(projection=ccrs.PlateCarree())
ax.stock_img()
ax.plot(latlon_gcrs.lon.to(u.deg), latlon_gcrs.lat.to(u.deg), 'r', transform=ccrs.Geodetic(), label='GCRS');
ax.plot(latlon_itrs.lon.to(u.deg), latlon_itrs.lat.to(u.deg), 'b', transform=ccrs.Geodetic(), label='ITRS');
ax.legend(loc='upper center', shadow=True, fontsize='x-large')
ax.plot()
if __name__ == '__main__':
# Creating the orbit
r = [-6045, -3490, 2500] * u.km
v = [-3.457, 6.618, 2.533] * u.km / u.s
ss = Orbit.from_vectors(Earth, r, v)
groundtrack(ss)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment