plot the ground track of a satellite in python

To plot the ground track of a satellite, you will need to calculate the latitude and longitude of the satellite at different points in time, based on its orbital parameters. Here's some sample code that uses the skyfield library to calculate the ground track of the International Space Station (ISS):

main.py
from skyfield.api import load, EarthSatellite
import numpy as np
import matplotlib.pyplot as plt

# Load the satellite data
tle_text = """
1 25544U 98067A   21066.03644377  .00001043  00000-0  28659-4 0  9998
2 25544  51.6440  98.4988 0002384  73.8823  47.6565 15.48970718398728
"""
ts = load.timescale()
sat = EarthSatellite(*tle_text.strip().splitlines())

# Define the start and end times
start_time = ts.utc(2021, 3, 7, 0, 0, 0)
end_time = ts.utc(2021, 3, 8, 0, 0, 0)
times = ts.range(start_time, end_time, step=600.0)

# Calculate the latitude and longitude of the satellite at each time step
lats, lons = [], []
for time in times:
    lat, lon, _ = sat.at(time).geodetic()
    lats.append(lat.degrees)
    lons.append(lon.degrees)

# Plot the ground track on a map
fig = plt.figure(figsize=(8, 8))
plt.plot(lons, lats, '.', ms=1, alpha=0.5)
plt.xlabel('Longitude (deg)')
plt.ylabel('Latitude (deg)')
plt.title('ISS Ground Track: Mar 7-8, 2021')
plt.grid()
plt.show()
973 chars
33 lines

This code loads the Two-Line Element (TLE) data for the ISS, calculates its geodetic coordinates using the skyfield library at 10-minute intervals, and then plots the results on a map using matplotlib. You can modify the TLE data and time range to calculate the ground track for any satellite at any time period.

gistlibby LogSnag