0

I want to programm a Code which calculates an Orbit for 2 Satellites to recreate an event. It should read in 2 TLE files, then create Earthsatellite Objects with the skyfield package in python. After that it should search the TLE files for a specific timeframe. Then i want to plot the two satellites in this timeframe (make an orbit propagation) and calculate the minimum distance. ideally it should also mark the epoches which it used from the earthsatellite object in the plot, so i can determine in which direction the satellite moves. I am really really stuck and need help. Does someone know how it's done? Thanks in advance!

I have already programmed a code, but am Stuck...

import skyfield
from skyfield.api import load, EarthSatellite, wgs84
#from AltAzRange TODO install
from skyfield.api import Topos
import numpy as np
from skyfield.timelib import Time
from skyfield.api import utc
import skyfield.positionlib
from datetime import datetime
import csv
import os
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d import proj3d
from matplotlib.text import Annotation

#Read in TLE and TXT files(for event Astrocast x Fossasat)
sat1_file = r'Astrocast_0103_TLE_history.txt'
sat2_file = r'FOSSASAT-2E6_06-2022.tle'
name = ['Astrocast_0103','FOSSASAT-2E6_06-2022']

ts = load.timescale()

# Load TLE data and create EarthSatellite objects
def load_sat_files1(sat_file):
    satellite_file = []
    with open(sat1_file, 'r') as f:
        lines = f.readlines()
        for i in range(0, len(lines), 2):
            line1 = lines[i]
            line2 = lines[i+1]
            satellite = EarthSatellite(line1, line2, name[0], ts)
            satellite_file.append(satellite)
    return satellite_file

def load_sat_files2(sat_file):
    satellite_file = []
    with open(sat1_file, 'r') as f:
        lines = f.readlines()
        for i in range(0, len(lines), 2):
            line1 = lines[i]
            line2 = lines[i+1]
            satellite = EarthSatellite(line1, line2, name[1], ts)
            satellite_file.append(satellite)
    return satellite_file

satellite1 = load_sat_files1(sat1_file)

satellite2 = load_sat_files2(sat2_file)

start_time = datetime(2022, 6, 14, 0, 0, 0)
start_time = start_time.replace(tzinfo=utc)
end_time = datetime(2022, 6, 20, 0, 0, 0)
end_time = end_time.replace(tzinfo= utc)

start_t = ts.from_datetime(start_time)
end_t = ts.from_datetime(end_time)

def filter_times(time_start, time_end, satellit):
    satellite_filtered = []
    for sat in satellit:
        epoch_t = sat.epoch.utc_datetime()
        #print(epoch_t)
        if start_t.utc_datetime() <= epoch_t <= end_t.utc_datetime():
            satellite_filtered.append(sat)
    return satellite_filtered

sat1_filtered = filter_times(start_t, end_t, satellite1)
sat2_filtered = filter_times(start_t, end_t, satellite2)

def positions_sat(sat_filter):
    satellite_positions = []
    for i in range(len(sat_filter)):
        satellite_pos = sat_filter[i].at(sat_filter[i].epoch).position.km
        satellite_positions.append(satellite_pos)
    return satellite_positions

sat1_pos = positions_sat(sat1_filtered)
#sat1_position = np.array(sat1_pos)
sat2_pos = positions_sat(sat2_filtered)
#sat2_position = np.array(sat2_pos)

time_step = np.arange(0, 24*60*60, 10)

sat1_pos_ep_0 = sat1_filtered[0].at(ts.utc(2022, 6, 14, time_step)).position.km
sat2_pos_ep_0 = sat2_filtered[0].at(ts.utc(2022, 6, 14, time_step)).position.km

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot(sat1_pos_ep_0[0,:], sat1_pos_ep_0[1,:], sat1_pos_ep_0[2,:], label=name[0])
ax.plot(sat2_pos_ep_0[0,:], sat2_pos_ep_0[1,:], sat2_pos_ep_0[2,:], label=name[1])
ax.set_xlabel('X (km)')
ax.set_ylabel('Y (km)')
ax.set_zlabel('Z (km)')

plt.legend()
plt.show()

G3nki4
  • 11

0 Answers0