skyfielders / python-skyfield

Elegant astronomy for Python
MIT License
1.38k stars 208 forks source link

SGP4 twoline2rv Gives Output of Mean Motion Way Off From TLE #915

Closed frankxu787 closed 8 months ago

frankxu787 commented 8 months ago

Hello, I am new to orbit mechanics. When I imported twoline2rv from sgp4.io and used it to extract the mean motion from my TLE, it gave me some number that is totally different from what is in the TLE second line. I try multiple ways to troubleshoot this including using different TLE's, but the issue remains. Would like to see if anyone has an idea what I have done wrong. Many Thanks!

TLE: 1 37746U 11034A 20198.42848830 -.00000156 +00000-0 +00000-0 0 09996 2 37746 000.0326 279.0481 0010723 180.2829 072.6623 01.00271441021823

Code:

tle_line1 = "1 37746U 11034A   20198.42848830 -.00000156 +00000-0 +00000-0 0 09996"
tle_line2 = "2 37746 000.0326 279.0481 0010723 180.2829 072.6623 01.00271441021823"
satellite = twoline2rv(tle_line1, tle_line2, wgs84)
mean_motion = satellite.no
print(mean_motion)

Ouput: 0.004375166977923089

brandon-rhodes commented 8 months ago

Here's what's happening — the TLE uses the units revolutions per day:

https://en.wikipedia.org/wiki/Two-line_element_set#Line_2

Whereas the official SGP4 code instead uses the units:

Mean motion (radians/minute).

https://pypi.org/project/sgp4/#attributes

And:

01.00271441021823 * 2*pi / (24*60) = 0.004375167 🙂
frankxu787 commented 8 months ago

Thank you very much Brandon. It really enlightened me. I guess, I only have one follow up question as follows. When calculating the semi-major axis (a) from the mean motion, I used the mean motion in rad/min generated by twoline2rv to manually calculate the semi-major axis. Then I used the '.a' method from the twoline2rv object to generate the semi major axis. Does the semi major axis (a) in SGP4 us a different unit as well? Thank you very much in advance!!

from sgp4.earth_gravity import wgs84
from sgp4.io import twoline2rv
import math
tle_line1 = "1 37746U 11034A   20198.42848830 -.00000156 +00000-0 +00000-0 0 09996"
tle_line2 = "2 37746 000.0326 279.0481 0010723 180.2829 072.6623 01.00271441021823"
satellite = twoline2rv(tle_line1, tle_line2, wgs84)
mean_motion_rad_per_min = satellite.no
mean_motion_rev_per_day =  (mean_motion_rad_per_min * 1440) / (2 * math.pi)
mu = 398600.4418
a_calculated_from_mm_rad_per_min = (mu / ((mean_motion_rad_per_min / 60)**2))**(1/3)
a_sgp4_generated = satellite.a
print("mean_motion_rad_per_min: " , mean_motion_rad_per_min)
print("mean_motion_rev_per_day: " , mean_motion_rev_per_day)
print("a_calculated_from_mm_rad_per_min: " , a_calculated_from_mm_rad_per_min)
print("a_sgp4_generated: " , a_sgp4_generated)

Output: mean_motion_rad_per_min: 0.004375166977923089 mean_motion_rev_per_day: 1.00271441 a_calculated_from_mm_rad_per_min: 42164.82839715394 a_sgp4_generated: 6.611001769251309

frankxu787 commented 8 months ago

OK, I think I figured it out, but I need a second verification. I think the SGP4 semi major axis value is the ratio that actual distance to the mean radius of the Earth. Can you verify this with me? Thank you!

frankxu787 commented 8 months ago

And if my above assumption is true (let's hope so), when calculating the semi-latus rectum (p) with the formula p = a * (1 - e^2), do I use the a in km or the ratio a from SGP4? Just wondering because semi-latus rectum seems to be a game changer responsible to the different between the position (r) and velocity (v) I calculated and the r and v SGP4 gave me. the difference takes place at the z-axis of r and v which have semi-latus rectum as their dependency. Any idea?

brandon-rhodes commented 7 months ago

(Just so you know that I'm not ignoring you: I am currently preparing a conference talk, and so won't have time to work through your question for probably a couple of more weeks. Let me know if you get further with your calculations on your own, though, so that I know where things stand. Thanks!)

brandon-rhodes commented 7 months ago

@frankxu787 — I am now back at the keyboard, and wanted to check back in to see if your question still stands, or if you have resolved it in the weeks I have been away?