# Is software available for writing two line element files from Keplerian elements?

I am interested in writing a TLE file from existing Keplerian elements. Is software available on the web to do this?

• @JCRM - The reference in your answer does not provide an answer this question. That reference refers to Keplerian orbital elements, which are distinct from the mean orbital elements used in TLEs and the software that propagates them. – David Hammen Jan 24 '19 at 10:21
• absolutely, that translates state vectors to keplerian elements, not keplerian elements to SGP4 elements. Thanks for pointing that out @DavidHammen – JCRM Jan 24 '19 at 13:18

Keplerian orbital elements and the mean orbital elements used in the simplified perturbation models are rather different beasts. Keplerian elements assume a spherically symmetric central body and no perturbations from other bodies, atmosphere, etc. The simplified perturbation models account for those perturbations (non-spherical Earth, third body accelerations, atmospheric drag, radiation pressure) in a simplified manner. The one thing the two concepts do have in common is that the computational cost of computing position and velocity at some point in time is independent of the time difference between epoch and the point in time; neither approach uses numerical integration.

The way two line elements are created is via a number of measurements of some indicator of satellite state that are spread over time. The numerical values in the TLE are adjusted via an orbit determination process so as to minimize in a least squares sense a weighted sum of the squared errors between measurement and simplified perturbation model prediction. An inverse mapping from measurement (or from Cartesian states, or from Keplerian elements) to mean elements is not needed.

That said, people have tried to do this. An outline of an algorithm:

1. Compute Cartesian state (position and velocity) from your Keplerian orbital elements.
2. Transform that Cartesian state to the True Equator Mean Equinox frame. As far as I can tell, the US Air Force is the only entity that uses TEME. Your Keplerian elements are almost certainly in some other ECI frame (there are a bunch of them).
3. Form an initial guess of the TLE set by
• Setting the epoch time to the time of the Keplerian elements.
• Setting the TLE orbital elements to the TEME Keplerian elements computed from the TEME position and velocity.
• Setting B* to zero or to some informed guess.
4. Repeat until converged:
1. Compute Cartesian state from the TLE set.
2. Compute the differences between the target position and velocity versus the position and velocity computed from the TLE set.
3. Combine the error vectors to form a scalar error value. For example, $$||\Delta \boldsymbol{x}||^2/||\boldsymbol{x}||^2 + ||\Delta \boldsymbol{v}||^2/||\boldsymbol{v}||^2$$.
4. Exit the loop if the error is sufficiently small.
5. Estimate the Jacobian between the TLE elements and the Cartesian state.
6. Use the Jacobian from step 4.5 and the error vectors from step 4.2 to compute an updated TLE set. Care might be needed here, particularly for nearly circular or nearly equatorial orbits. You might want to use singular value decomposition or ANOVA so as to only attack the statistically significant elements.
• "The numerical values in the TLE are adjusted via an orbit determination process so as to minimize in a least squares sense a weighted sum of the squared errors between measurement and simplified perturbation model prediction." I love these sentences, you pack so much into each one! I used to think that predicted trajectories from "master integrators" using advanced models that combined recent plus historical observational data where then "down-fitted" to SGP4 -> TLEs, rather than the TLEs coming directly from observations (cont.) – uhoh Jan 25 '19 at 1:47
• (cont.) But these eccentricity blips 1, 2 support the TLEs being fitted to only recent data. – uhoh Jan 25 '19 at 1:49
• @uhoh - It could go that way, precision orbit determination and from that develop a TLE, but the TLE generation would still be via an orbit determination process. It's also important to keep in mind that NORAD / whichever TLA agency produces TLEs nowadays has to do this for thousands of objects in space based on who knows how many observations per object per day. Performing precision orbit determination on all of them would be a daunting computing task, particular when only a small fraction of those objects warrant high precision scrutiny. – David Hammen Jan 25 '19 at 4:16