-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsat_pos_samples.py
64 lines (52 loc) · 1.75 KB
/
sat_pos_samples.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""
Sample code to excercise skyfield functions
on TLE data.
"""
from skyfield.api import EarthSatellite
from skyfield.api import load, wgs84
from skyfield.positionlib import Geocentric
# TLE entries for 3 satellites
starlink1="""
STARLINK-31857
1 59843U 24097J 24152.50001157 -.00832730 00000+0 -40214-2 0 9991
2 59843 43.0045 5.2275 0001736 273.1057 88.8863 15.83654368 2541
"""
starlink2="""
STARLINK-30948
1 58525U 23191T 24151.80439894 .00009599 00000+0 72464-3 0 9996
2 58525 43.0012 26.3148 0000805 284.9345 75.1408 15.02538244 28019
"""
kuiper = """
KUIPER-P2
1 58013U 23154A 24151.54837047 .00017317 00000+0 50948-3 0 9990
2 58013 29.9766 310.4754 0012935 307.8864 52.0592 15.33643649 36251
"""
def dump_sat_info(tle_text: str) -> None:
"""
Report current location based on TLE information.
"""
# Load TLE data
lines = tle_text.strip().splitlines()
sat = EarthSatellite(lines[1], lines[2], lines[0])
# Report static information
print(f"Epoch: {sat.epoch.utc_jpl()}")
print(f"Satellite name: {sat.name}")
# Calculate current location
ts = load.timescale()
geo = sat.at(ts.now())
# Convert from geo location to latitude, longitude, and hieght
lat, lon = wgs84.latlon_of(geo)
height = wgs84.height_of(geo)
# Report location information
print(f"Geocentric Position {geo.position.km}")
print(f"Latitude: {lat}")
print(f"Longitude: {lon}")
print(f"Height above sea level: {height.km:.2f}km")
print(f"Distance from center of earth: {geo.distance().km}km")
print()
def test_sat_functions():
dump_sat_info(starlink1)
dump_sat_info(starlink2)
dump_sat_info(kuiper)
if __name__ == "__main__":
test_sat_functions()