TLE Processing : Get the Cartesian position & velocity vectors of a satellite at a given time from a Two-Line Element with python

Joséphine Picot
5 min readJul 19, 2020

--

source : Google Image

Part I

What is a TLE?

Where and how to get TLE files?

What information can we get from it?

Part II

Position & velocity vectors of a satellite from its TLE with the python module sgp4, example with one TLE and then a bunch of TLEs.

Image by author

Part III : bibliography

Part I

What is a TLE?

A TLE (two-line element set) is a two-line text containing information about the movement of an object in orbit around the Earth at a given time (noted “epoch”). It looks like this:

 ISS (ZARYA) 
1 25544U 98067A 14273.50403866 .00012237 00000–0 21631–3 0 1790
2 25544 51.6467 297.5710 0002045 126.1182 27.2142 15.50748592907666

On line 0 we have the object’s name. Lines 1 and 2 are the payload of the TLE. Here are the elements given in a TLE :

Composition of a TLE

You can click on this link to see more details about TLE’s composition.

Where to find TLE files?

I made a special tutorial for extracting TLE files thanks to the NORAD site at the following link :

Where and how to get the orbital parameters two line element of a satellite over a period of time?

The TLE file you will get by downloading from the NORAD site will look like this:

Image by author

What information can we get from it ?

We can retrieve the position and velocity vectors for a given instant called the epoch, as well as all the orbital parameters regarding the satellite’s position at a date close to the epoch. How? We pick a date (or epoch) that should be close enough to the date where the TLE was generated (about two weeks before or after) with the following format : (year, month, day, hours, minutes, seconds). Make sure the date falls into that range, otherwise the data will end up being distorted.

Then, we can use the sgp4 module like in the following part.

Part II

Position and velocity vectors of a satellite from its TLE using sgp4

You can do the tutorial with the whole code available on my github at this link.

First install the sgp4 library by running a simple

pip install sgp4

Once we manage to get a TLE using the method described above, we can start working on it using sgp4. We start off by importing the Satrec and jday module using the following code:

from sgp4.api import Satrec
from sgp4.api import jday

We can retrieve the content of the TLE in the variables s (first row) & t (second row)

# Reminder - our TLE looks like this :
# ISS (ZARYA)
# 1 25544U 98067A 19249.04864348 .00001909 00000–0 40858–4 0 9990
# 2 25544 51.6464 320.1755 0007999 10.9066 53.2893 15.50437522187805
s = '1 28446U 04041A 19002.21559949 -.00000090 00000-0 00000+0 0 9998'
t = '2 28446 0.0198 37.5572 0002596 225.6438 170.9111 1.00271812 52071'
satellite = Satrec.twoline2rv(s, t)

We then pick a date, for example (2019, 1, 1, 11, 59, 33) and store it in the variables jd (Julian Date) and fr (fraction of Julian Date).

jd, fr = jday(2019, 1, 1, 11, 59, 33)

Then we can get the error e, position vector r and velocity vector v all in Cartesian coordinates.

e, r, v = satellite.sgp4(jd, fr)

Ok now lets process more TLEs!

This time we are gonna need the pandas library :

pip install pandas
import pandas as pd

Go back to this link : https://celestrak.com/satcat/search-results.php and click on the TLE icon in the first column : “Internal Designator” (also available at this link : https://celestrak.com/satcat/tle.php?INTDES=1998-067)

Right click anywhere on the page an save the file where this code is saved. The file will be saved as tle.txt

Image by author
TLE_file = “tle.txt”

We then open the file and save the values in three lists :

  • L_Name (containing the satellites’ names)
  • L_1, L_2 (containing respectively the first and second rows of each TLE)
TLEs = open(TLE_file, 'r')L_Name = []
L_1 = []
L_2 = []
i = 1for line in TLEs:
j = i
if i == 1:
L_Name.append(line)
j = 2
elif i == 2:
L_1.append(line[:69])
j = 3
elif i == 3:
L_2.append(line[:69])
j = 1
i = j

We create a dataframe to gather our data :

dataframe = pd.DataFrame(columns = ['Satellite_name', 'Line_1', 'Line_2', 'Position_vector', 'Speed_vector']) 
dataframe

We fill in the columns of our dataframe with our data :

dataframe.Satellite_name = L_Name
dataframe.Line_1 = L_1
dataframe.Line_2 = L_2

We pick a date & associate it with the variables jd (Julian Date) and fr (fraction of Julian Date).

Then for each line we compute the position and speed vectors and we put the results in lists :

jd, fr = jday(2021, 2, 4, 18, 5, 0)L_PosVector = []
L_SpeedVector = []
for i in range(len(dataframe)):

s = dataframe.Line_1[i]
t = dataframe.Line_2[i]
satellite = Satrec.twoline2rv(s, t)
e, r, v = satellite.sgp4(jd, fr)
L_PosVector.append(r)
L_SpeedVector.append(v)

Finally, we assign the values of the position and speed vectors to the respectiv columns of our dataset :

dataframe.Position_vector = L_PosVector
dataframe.Speed_vector = L_SpeedVector
dataframe
Image by author

Part III : bibliography

  1. Definition of a TLE

2. Understanding of the SQP4 library

By the way! Brandon Rhodes is the author of the SGP4 library that allows us to process the information composing a TLE, so big thank you to him!

I hope you found this article useful!

--

--

Joséphine Picot
Joséphine Picot

Written by Joséphine Picot

We can do so many things with data, we just have to find a project that thrills us!

Responses (1)