# Python orbit simulation using TLE-tools and poliastro

I have a source of satellite TLE data - similar to space-track.org. For testing purposes I would like to create a simulation that doesnt rely on the real source of data. I was able to download a json file containing TLEs for all the satellites I am interested in.

My plan was to read in the json file with TLE data and create a python TLE object using TLE-tools and the from_lines() method. Once I have a TLE object I can convert it to a poliastro two body orbit using the to_orbit() method.

So far so go. I'd like my simulation to produce live data - rather than just static TLEs - I created a separate process to propagate all of the orbits using the number of elapsed seconds since the previous update.

I set up a flask REST api to serve the data up. When you request TLE data my intention was to "stop-the-world" temporarily and produce TLE data from the current state of all the orbits that have been nicely ticking along in the backgorund.

I am having trouble generating TLEs from the poliastro two body orbits that I have - there is some canned data that I will need to store along with the orbit but that should be okay. What I am struggling with is I dont know how to get some of the parameters I need to generate my new TLEs. Here is an excerpt of the doco from TLE-tools:

class tletools.tle.TLE(name, norad, classification, int_desig, epoch_year, epoch_day, dn_o2, ddn_o6, bstar, set_num, inc, raan, ecc, argp, M, n, rev_num)

A few of the most confusing parameters are described as shown below:

dn_o2 (float) – First time derivative of the mean motion divided by 2.

ddn_o6 (float) – Second time derivative of the mean motion divided by 6.

bstar (float) – BSTAR coefficient (https://en.wikipedia.org/wiki/BSTAR).

I can get the mean motion from the poliastro two body orbit that I have but I have no idea about getting the first and second time derivates. Do you guys have any suggestions on how to get those values ?

In the picture below describing the TLE format it seems to be suggesting the second derivative of mean motion is usually set to 0.0.

Do you foresee any problem if I:

1. Set 2nd derivative of mean motion to 0
2. Set BSTAR to the value in the original TLE for 1st derivative of mean motion or ballistic coefficient
3. Set 1st derivative of mean motion to the same value as BSTAR ?

I think I can get all the remaining parameters from the poliastro orbit directly.

## 1 Answer

No, you should never attempt to generate your own TLEs. You need to wait until the next one published on space-track.org, because trying to do it on your own is painfully difficult and almost guaranteed to fail.

How to generate TLE file?

There is nothing involved in doing a better job now that would be harder than understanding the process that is used to determine the parameters in TLEs that give the best results when interpreted through SGP4.

Calculate Satellite Coordinates From TLE Data

The mathematics of those two line elements is beyond messy. It's a "math-out". (Think of a blizzard where all you see is whiteness. Blizzards are white-out conditions. The paper describing the two line elements is a math-out. All you see is mathematics.)

How to construct $B^*$ drag term in TLE?

Vallado's textbook says: Be aware that the value of B* is always modified. It’s really an arbitrary free parameter in differential correction. Chapter 10 will introduce how to estimate a drag parameter. The estimated value of B* may be completely unrelated to drag effects in the presence of satellite maneuvers, significant solar pressure and atmospheric perturbations, large third-body effects from the Sun or Moon, or large deflections caused by mismodeling of the Earth’s gravitational field. B* can even appear as a negative number!

Computing a new TLE following a delta-v impulse?

Do you really want to compute a new TLE, or just a new orbit? The TLE format itself is a significant problem, so it's best to avoid if possible. If you just need to look for changes in the orbit state, you should use SGP4 to convert into position and velocity, propagate the state with and without the maneuver using something other than SGP4, and convert each of those to some orbital elements that aren't the excessively complicated mean elements used for TLEs.

Confused about SGP4 implementation published by celestrack

There is no need to integrate the equations of motion, because all the math has already been done for you. This is what SGP4 really does. It is not "propagated linearly with no timesteps", it is implemented as a sequence of nested polynomials and trig functions into which one simply plugs the end time, and the final result is calculated from it in one step. To make this work, of course, that one step must be outlandishly, overwhelmingly complicated. It is!

Mean to Osculating conversion for non-J2 averaged elements

by mean elements we understand osculating elements from which short-periodic and long-periodic perturbations of the earth's potential have been subtracted. In practice, the osculating elements are the ones that are usually available as, for instance, in the case of a stepwise numerical integration or in the case of a set of elements obtained from an orbit injection maneuver. Thus one must resort to osculating elements as a starting point for the generation of mean elements.

Failing at getting apogee and perigee from TLE

To compare among the variables, you could attempt to make the huge effort of reconstructing exactly what those perturbations are and reversing them, or you could just ask SGP4 to tell you mean elements instead of osculating ones.

• Hey Ryan C - thanks for the very detailed reply - lots of good information there. I know you are right - generating my own TLE data is fraught with danger - why am I dumb enough to try this ? Well Im trying to "stub-out" a system that is feeding me with data in TLE format. The real answer might be to get the other side to change to feed me data in something other than TLE format- I will persist for a little longer and then probably accept you are right and try and come up with another solution. Thanks once again. Cheers, Kieran Jul 26 at 9:25
• Just say you had a supplier that was operating a radar facility that tracked LEO satellites - what format would you expect them to supply the position of satellites in - seems like TLE is outdated - is the replacement just x,y,z + vX,vY,vZ ? Jul 26 at 9:29
• If you can get it in another format, do so! The error built into a TLE at birth is on the order of several kilometers and several meters per second, and that grows with time away from epoch. If you want to be able to do better than that, you need to not use TLEs. Personally, I would want the raw measurements (range and range-rate at a long list of times), so I could put them into my favorite orbit determination software and have it tell me what the most likely state is. If they won't part with that, pos & vel can work okay, but you need lots of data points for a good fit. Jul 26 at 21:47
• Thanks for the advice Ryan - I will bring it up at the next opportunity -- i think part of the problem is the UI toolkit we are using cesium + satellitejs seems to know how to deal with TLEs - hopefully it can handle other formats too - if I can get raw pos + velocity what toolkits could i use to determine the orbit - do i need several measurements before I can fit an orbit ? Jul 26 at 23:24
• Whoops looks like i read that wrong - Ryan is suggesting to get range and range-rate measurements at a long list of times. Can you suggest toolkits I can use to fit an orbit if I can get that data ? Jul 26 at 23:41