plot ground track of a satellite given tle in python

To plot the ground track of a satellite given Two-Line Elements (TLE) data in Python, we can use pyorbital library. Here's an example code that shows how to do that:

main.py
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime, timedelta
from pyorbital.orbital import Orbital

# TLE data for the ISS
tle_lines = ['1 25544U 98067A   20235.52673106  .00000834  00000-0  25311-4 0  9998',
             '2 25544  51.6445  61.5455 0004225  94.8535 265.3286 15.49461585239667']

satellite = Orbital("ISS", line1=tle_lines[0], line2=tle_lines[1])

# specify the start and end time
start_time = datetime.utcnow()
end_time = start_time + timedelta(days=1)

# create an array of time steps between start and end time
time_steps = np.arange(start_time, end_time, timedelta(minutes=1))

# calculate the position of the satellite at each time step
positions = [satellite.get_position(when) for when in time_steps]

# extract latitudes and longitudes from the positions array
lats = [position[0] for position in positions]
lons = [position[1] for position in positions]

# plot the ground track
fig, ax = plt.subplots()
ax.plot(lons, lats, '.', markersize=1)
ax.set_xlabel('Longitude (deg)')
ax.set_ylabel('Latitude (deg)')
ax.set_title('ISS Ground Track')
plt.show()
1108 chars
33 lines

In this code, we used the TLE data for the International Space Station (ISS) and created an Orbital object using the pyorbital library. Then, we specified the start and end times and created an array of time steps between them. Using these time steps, we calculated the position of the satellite at each time step using the get_position method of the Orbital object. Finally, we extracted the latitudes and longitudes from the positions array and plotted them using matplotlib.

gistlibby LogSnag