Repository navigation
Expand file tree
/
Copy pathpython_sgp4.py
More file actions
46 lines (33 loc) · 1.49 KB
/
Copy pathpython_sgp4.py
File metadata and controls
46 lines (33 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
"""SGP4 orbit propagation with astroz Python bindings (python-sgp4 compatible API)."""
import time
import numpy as np
from astroz.api import Satrec, SatrecArray, WGS72
LINE1 = "1 25544U 98067A 24127.82853009 .00015698 00000+0 27310-3 0 9995"
LINE2 = "2 25544 51.6393 160.4574 0003580 140.6673 205.7250 15.50957674452123"
def main():
sat = Satrec.twoline2rv(LINE1, LINE2, WGS72)
print(f"Satellite: {sat.satnum}")
print(f"Inclination: {np.degrees(sat.inclo):.2f}°")
print(f"Eccentricity: {sat.ecco:.6f}")
# One time: epoch + 30 minutes
jd, fr = sat.jdsatepoch, sat.jdsatepochF + 30.0 / 1440.0
error, pos, vel = sat.sgp4(jd, fr)
print(f"Position at t=30min: {pos[0]:.1f}, {pos[1]:.1f}, {pos[2]:.1f} km")
# Many times at once: one day at 1-minute steps
n = 1440
sat_array = SatrecArray([sat])
base_jd, base_fr = sat.jdsatepoch, sat.jdsatepochF
jd_arr = np.full(n, base_jd, dtype=np.float64)
fr_arr = base_fr + np.arange(n, dtype=np.float64) / 1440.0
start = time.perf_counter()
errors, positions, _ = sat_array.sgp4(jd_arr, fr_arr, velocities=False)
elapsed = time.perf_counter() - start
print(
f"Batch: {n:,} points in {elapsed * 1000:.1f} ms ({elapsed / n * 1e6:.2f} μs/prop)"
)
# positions is (n_sats, n_times, 3) in km, TEME
radius = np.linalg.norm(positions[0], axis=1)
print(f"Orbit radius over the day: {radius.min():.0f}-{radius.max():.0f} km")
if __name__ == "__main__":
main()