question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Discrepancy between Skyfield and manually calculated Orbital Parameters

See original GitHub issue

Hi there,

I am calculating semi-major axis, perigee and apogee altitude values for certain LEO satellites and came across a discrepancy between my theoretically calculated values and Skyfield provided values. To reproduce I am providing the following script:

# https://orbit.ing-now.com/satellite/39444/2013-066ae/funcube-1/
    # Orbit : #704394.00 @ 577 x 658 km x 97.6 deg
    # Spacecraft Age : 8 years, 10 months
    # Distance Travelled : ≈2.1 billion km
from skyfield.api import EarthSatellite, load, utc, wgs84
import numpy as np

mu = 3.986004418 * 1e14 # gravitational parameter of Earth (m^3s^−2)

fun = """\
1 39444U 13066AE  22257.61551127  .00002978  00000+0  35585-3 0  9990
2 39444  97.6337 227.5603 0057973  99.5629 261.2143 14.83718775474743
"""


# satrec = Satrec.twoline2rv(*fun.splitlines(), WGS84)
# sat    = EarthSatellite.from_satrec(satrec, ts)
sat = EarthSatellite(*fun.splitlines())
r_e = sat.model.radiusearthkm
print(f'Skyfield mu value: {sat.model.mu} vs theory: {mu/1e9}')

print(f'Skyfield results -- Axis: {sat.model.a * r_e}, Perigee: {sat.model.altp * r_e}, Apogee: {sat.model.alta * r_e}')

# theoretical computation

T   = 2 * np.pi / sat.model.no_kozai * 60
semi_major = (T**2 * mu / (4 * np.pi**2))**(1/3) / 1e3
print(f'''
        Theoretical results --
        Axis: {semi_major},
        Perigee: {semi_major*(1+sat.model.ecco) - sat.model.radiusearthkm},
        Apogee: {semi_major*(1-sat.model.ecco) - sat.model.radiusearthkm}''')

The results of the above script are:

Skyfield mu value: 398600.8 vs theory: 398600.4418
Skyfield results -- Axis: 6992.769095396103, Perigee: 574.0949151193616,  
Apogee: 655.1732756728427

        Theoretical results --
        Axis: 6995.747293563754,
        Perigee: 658.1687393487309,
        Apogee: 577.0558477787772

Please note that the values (577 x 658 km) I have manually computed seems to be in agreement with the values in the website.

I have tried changing the ellipsoid from WGS72 to WGS84 using from_satrec but that didn’t really change much. There is also some difference in the gravitational constant but that doesn’t seem to really explain the discrepancy either. I have also tested a lower inclination starlink satellite, and in that case the difference seems negligible.

Can you please advise? Best regards

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
brandon-rhodescommented, Sep 16, 2022

Thank you for tracking that down!

Alas, I’m not free to alter that line of code—that’s an official line of C++ code from the SGP4 implementation:

https://github.com/brandon-rhodes/python-sgp4/blob/fca7e90de2467308e7cb62ac2d019f383011dbc8/extension/SGP4.cpp#L1476

(Why does it appear twice, you might ask? The code appears in both propagation.py (which I do control) and in the C++ code because propagation.py is a slow Python implementation of SGP4 that’s used as a fallback on platforms that can’t compile the C++.)

Here’s the source of the official code that the sgp4 module bundles:

https://celestrak.org/publications/AIAA/2006-6753/

If you have found libraries that use alternative math for the semi-major axis, then it may be those libraries that need to be updated—they might not have updated their code to match the latest official code from Vallado, Crawford, Hujsak, and Kelso?

In any case, I can’t, alas, alter that code without breaking the promise that I made in the docs that the sgp4 library uses a verbatim copy of the official SGP4 algorithm. You maybe could contact one of the authors to ask about why they use the formula they do to compute the semi-major axis? If you do, feel free to comment here on what you learn, since I’m also curious about their choice of formula.

1reaction
brandon-rhodescommented, Sep 17, 2022

It’s possible that the SGP4-computed properties like alta are for some special purpose that we don’t know about, and that a straight re-computation of the apogee and perigee per Kepler’s formulae are better for display to users? Let me know if you run into further information clarifying things!

I suppose if one of us had time, we could run a loop with that satellite to find out its actual in-practice apogee and perigee, and see if those numbers are closer to your Kepler-computed one, or the one that SGP4 computes. But it could be that it varies from one satellite to another, whether their real apogee/perigee are close to the SGP4 or Kepler numbers, so one satellite’s result wouldn’t necessarily generalize to all.

Again, good job tracking down the exact difference in formulae!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Earth Satellites — Skyfield documentation - Rhodes Mill
Skyfield is able to predict the positions of Earth satellites by loading satellite orbital elements from Two-Line Element (TLE) files — published by ......
Read more >
Epoch is half-day too early for EarthSatellites built from_satrec
I found that the model calculates position and velocity correctly, but the purported epoch differs by exactly a half-day. I believe the issue...
Read more >
How to find/extract the semi-major axis from a TLE with Skyfield?
And I would like to extract the semi-major axis using Skyfield. I also tried manually calculating it, looking at this answer: How to...
Read more >
Why do calculations provided by Skyfield not match actual data?
I wanted to compare the semimajor axis that Skyfield calculates with ... the semi major axis in 'mean elements' and not osculating elements!...
Read more >
Calculating RA/Dec for solar system comets in poliastro
Idea is to make use of poliastro and astropy in order to calculate RA/Dec coordinates for a comet from the orbital elements published...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found