How to generate TLE file?

What is the way of generation of TLE file for a satellite? How to deal with BSTAR drag term, mean orbital elements, etc.?

The generated TLE will be used as the input for sgp4 algorithm. Is there already developed package for generation in python?

• search for book "COMPUTING NORAD MEAN ORBITAL ELEMENTS FROM A STATE VECTOR" it might help to write code for converting state vector to TLE, it has code in fortran printed in the book. I am dealing with the same problem right now. Apr 11, 2019 at 11:46

In fact, your question is quite important. I will disagree with my colleagues who discourage the generation of custom TLEs. There are plenty of reasons to do so, mostly linked to the fact that most tracking systems (either for an antenna or a telescope) accept TLEs as input, so if you have precise ephemeris for some object you want to track you need to generate TLEs from this ephemeris to feed your hardware. I did it for two GEO satellite LEOPs and I need to do it again to command a telescope to follow a LEO. So, generally speaking there are two ways to generate synthetic TLEs:

1. Direct method: it starts with the keplerian elements in any frame (EME2000 should work well). You also will need the corresponding state vector X0, in the same frame. Then, if T (x) is a function to convert a state vector from the TEME frame to whichever frame you started from (say, EME2000), you can build the equation T (SGP4(M)) = X0, where M is your desired set of TLE elements. This equation can be solver iteratively, starting from a M0 you can easily build from the keplerian elements you started from. Of course, these elements can't be assumed to be the same as the TLE elements, but they should be close enough to get a convergence in a few iterations.
2. Trajectory sampling: this method uses BLS to find the set of mean elements which minimizes the residuals computed from the propagated orbit with SGP4 and the precise ephemeris you should have of your satellite (converting the TEME frame of SGP4 output to whichever frame your starting ephemeris uses). You can find a sample code in CelesTrak (SGP4DC) but it didn't work for me.

As for which method is better, it depends a lot on your application. If you are trying to compute the TLE to feed it to some tracking system from precise ephemeris generated with other propagator, then trajectory sampling should give you the best results. But some people form a well known space agency preferred the direct method for some applications.

Do not make FAKE TLEs!

Step 2: Review all of the links in the answer. I'll repeat them here:

Step 3: Decide that this is a Bad Idea for the following reasons:

• Making Fake TLEs is dangerous!! You (or others) may end up confusing them with officially produced TLEs at some later time. It could "poison the deck." The deck could be yours, or somebody else's. What is a "deck"? See the next two items.
• The TLE + SGP4 ecosystem were produced at a time in history when computing power was quite limited, it does not make sense to start a new effort in 2018 based on these approximations.

• The TLE + SGP4 ecosystem were produced at a time in history when distributing data was quite limited, it does not make sense to start a new effort in 2018 based on parameters that can fit on two cards using a method developed by Herman Hollerith.

• The TLE + SGP4 ecosystem use several approximations that are just not necessary to make. 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. This is a closed system and it is best to leave it undisturbed and unmodified and used as-is. That process is:
1. Obtain TLEs from an official source.

2. Propagate those TLEs using a widely distributed software package for SGP4 or similar propagator.

• I think you are using SGP4 in your project because you want to avoid learning how to propagate orbits. That resulted in the previous question, and the answer there (which is not helpful) has lead to this question. These are both examples of what is called the XY problem. In short, you are asking "How to solve this problem the wrong way?" Your actual question is "How can I propagate Earth satellite orbits?" and this question requires a text book to answer, rather than a SE answer.
– uhoh
Mar 21, 2018 at 12:57
• While there is merit for this answer and I agree we have likely an XY problem here, I myself have been required to generate TLEs for simulated orbits in the past. And the TLE message has plenty space for leaving warnings such as satellite number 00000, classification F for Fake, international designation year =49 (before sputnik), wrong checksums, etc. So I don't see much of a danger here. Jan 18, 2019 at 16:17
• – uhoh
Mar 24, 2021 at 19:55
• One note, @Mefitico, wrong checksums results in gpredict failing to import TLEs without explanation. Mar 25, 2021 at 22:22
• @uhoh Thanks for pointing your question out. I just posted an answer based on my experience. Mar 25, 2021 at 22:38

What exactly do you mean by ‚generate‘?

TLEs are mainly used by NORAD, you can find a specification on their website, telling you what exactly any particiluar character of the TLE means. That will be helpful if you want to create your own.

If you just want to read TLEs for existing spacecraft, there is a big list on NORAD‘s website, where you can download any TLE for any tracked object.

There are quite a few python libraries for dealing with TLEs, using those you can just plug in a string and get SGP4 computed locations for any time in the future or past of the vessel.

I am not sure however if there is a python library for creating TLEs from orbital data, you will have to just do it yourself using the specification.

• Thanks for the answer. I've already implemented sgp4, which reads data from NORAD's service. What I've asked is, how to generate the characters of TLE, such as BSTAR drag term, mean orbital elements, etc.? Mar 21, 2018 at 0:14
• There are several reasons why there aren't such libraries!
– uhoh
Mar 21, 2018 at 4:44
• A perfectly valid reason to be willing to do it (and to ask for it in SE) is to learn. I don't think there's any harm in sharing this type of knowledge or in writing open-source libraries. Even if it's just for the fun of it... Nov 27, 2018 at 20:55