2022-05-21 12:39:21 -06:00
|
|
|
|
#!/usr/bin/python3
|
|
|
|
|
# tle2ssc
|
|
|
|
|
# Convert a TLE into an .ssc file for Celestia
|
|
|
|
|
#
|
|
|
|
|
# Usage:
|
2022-05-21 22:31:23 -06:00
|
|
|
|
# tle2ssc
|
2022-05-21 12:39:21 -06:00
|
|
|
|
# Example:
|
2022-05-21 22:31:23 -06:00
|
|
|
|
# ./tle2ssc > /usr/share/celestia/extras-standard/gnss/gnss.ssc
|
2022-05-21 12:39:21 -06:00
|
|
|
|
|
2022-05-21 17:54:49 -06:00
|
|
|
|
import os
|
|
|
|
|
import math
|
2022-05-21 20:32:35 -06:00
|
|
|
|
from math import remainder
|
2022-05-21 13:51:34 -06:00
|
|
|
|
from datetime import datetime
|
2022-05-21 17:54:49 -06:00
|
|
|
|
from sgp4.api import Satrec, WGS72
|
2022-05-21 20:32:35 -06:00
|
|
|
|
from skyfield.api import EarthSatellite, load, wgs84
|
2022-05-21 17:54:49 -06:00
|
|
|
|
|
2022-05-21 19:04:08 -06:00
|
|
|
|
xpdotp = 1440.0 / (2.0 * math.pi)
|
|
|
|
|
|
2022-05-21 22:31:23 -06:00
|
|
|
|
# Use GNSS to get all four systems
|
|
|
|
|
satellites_url = 'https://celestrak.com/NORAD/elements/gnss.txt'
|
|
|
|
|
#satellites_url = 'https://celestrak.com/NORAD/elements/galileo.txt'
|
|
|
|
|
#satellites_url = 'https://celestrak.com/NORAD/elements/gps-ops.txt'
|
|
|
|
|
#satellites_url = 'https://celestrak.com/NORAD/elements/glo-ops.txt'
|
|
|
|
|
#satellites_url = 'https://celestrak.com/NORAD/elements/beidou.txt'
|
2022-05-21 17:54:49 -06:00
|
|
|
|
satellites = load.tle_file(satellites_url)
|
|
|
|
|
|
|
|
|
|
ts = load.timescale()
|
2022-05-21 19:04:08 -06:00
|
|
|
|
t = ts.now()
|
2022-05-21 21:49:49 -06:00
|
|
|
|
|
|
|
|
|
|
2022-05-21 22:31:23 -06:00
|
|
|
|
for satellite in satellites:
|
|
|
|
|
satellite_name=satellite.name
|
2022-05-21 17:54:49 -06:00
|
|
|
|
|
2022-05-21 21:38:00 -06:00
|
|
|
|
# Static radius
|
2022-05-21 22:31:23 -06:00
|
|
|
|
satellite_radius=0.005
|
2022-05-21 21:38:00 -06:00
|
|
|
|
|
2022-05-21 22:31:23 -06:00
|
|
|
|
# Epoch XXX
|
2022-05-21 21:38:00 -06:00
|
|
|
|
#satellite_epoch=satellite.model.jdsatepoch
|
2022-05-21 22:31:23 -06:00
|
|
|
|
satellite_epoch=t.tdb
|
2022-05-21 21:38:00 -06:00
|
|
|
|
|
2022-05-21 17:54:49 -06:00
|
|
|
|
# The unique satellite NORAD catalog number given in the TLE file.
|
2022-05-21 22:31:23 -06:00
|
|
|
|
satellite_number=satellite.model.satnum
|
2022-05-21 19:04:08 -06:00
|
|
|
|
|
2022-05-21 17:54:49 -06:00
|
|
|
|
# Satellite classification, or else 'U' for “Unknown”
|
2022-05-21 22:31:23 -06:00
|
|
|
|
satellite_classification=satellite.model.classification
|
2022-05-21 19:04:08 -06:00
|
|
|
|
|
2022-05-21 17:54:49 -06:00
|
|
|
|
# International designator
|
2022-05-21 22:31:23 -06:00
|
|
|
|
satellite_intldesg=satellite.model.intldesg
|
2022-05-21 19:04:08 -06:00
|
|
|
|
|
2022-05-21 17:54:49 -06:00
|
|
|
|
# Full four-digit year of this element set’s epoch moment.
|
2022-05-21 22:31:23 -06:00
|
|
|
|
satellite_epochyr=satellite.model.epochyr
|
2022-05-21 19:04:08 -06:00
|
|
|
|
|
2022-05-21 17:54:49 -06:00
|
|
|
|
# Fractional days into the year of the epoch moment.
|
2022-05-21 22:31:23 -06:00
|
|
|
|
satellite_epochdays=satellite.model.epochdays
|
2022-05-21 19:04:08 -06:00
|
|
|
|
|
2022-05-21 17:54:49 -06:00
|
|
|
|
# Julian date of the epoch (computed from epochyr and epochdays).
|
2022-05-21 22:31:23 -06:00
|
|
|
|
satellite_jdsatepoch=satellite.model.jdsatepoch
|
2022-05-21 19:04:08 -06:00
|
|
|
|
|
2022-05-21 17:54:49 -06:00
|
|
|
|
# First time derivative of the mean motion (ignored by SGP4).
|
2022-05-21 22:31:23 -06:00
|
|
|
|
satellite_ndot=satellite.model.ndot
|
2022-05-21 19:04:08 -06:00
|
|
|
|
|
2022-05-21 17:54:49 -06:00
|
|
|
|
# Second time derivative of the mean motion (ignored by SGP4).
|
2022-05-21 22:31:23 -06:00
|
|
|
|
satellite_nddot=satellite.model.nddot
|
2022-05-21 19:04:08 -06:00
|
|
|
|
|
2022-05-21 17:54:49 -06:00
|
|
|
|
# Ballistic drag coefficient B* in inverse earth radii.
|
2022-05-21 22:31:23 -06:00
|
|
|
|
satellite_bstar=satellite.model.bstar
|
2022-05-21 19:04:08 -06:00
|
|
|
|
|
2022-05-21 17:54:49 -06:00
|
|
|
|
# Ephemeris type (ignored by SGP4 as determination now automatic)
|
2022-05-21 22:31:23 -06:00
|
|
|
|
satellite_ephtype=satellite.model.ephtype
|
2022-05-21 21:38:00 -06:00
|
|
|
|
|
2022-05-21 17:54:49 -06:00
|
|
|
|
# Element number
|
2022-05-21 22:31:23 -06:00
|
|
|
|
satellite_elnum=satellite.model.elnum
|
2022-05-21 13:51:34 -06:00
|
|
|
|
|
2022-05-21 17:54:49 -06:00
|
|
|
|
# Inclination in radians. Convert radians to degrees.
|
2022-05-21 22:31:23 -06:00
|
|
|
|
satellite_inclination=math.degrees(satellite.model.inclo)
|
2022-05-21 19:04:08 -06:00
|
|
|
|
|
|
|
|
|
# Satellite Inclination and Obliquity are the same
|
2022-05-21 22:31:23 -06:00
|
|
|
|
satellite_obliquity=math.degrees(satellite.model.inclo)
|
2022-05-21 13:51:34 -06:00
|
|
|
|
|
2022-05-21 17:54:49 -06:00
|
|
|
|
# Right ascension of ascending node in radians. Convert to degrees.
|
2022-05-21 22:31:23 -06:00
|
|
|
|
satellite_ascending_node=math.degrees(satellite.model.nodeo)
|
2022-05-21 21:38:00 -06:00
|
|
|
|
|
|
|
|
|
# Equator Ascending Node, in degrees
|
2022-05-21 22:31:23 -06:00
|
|
|
|
satellite_equator_ascending_node=math.degrees(satellite.model.nodeo)
|
2022-05-21 13:51:34 -06:00
|
|
|
|
|
2022-05-21 17:54:49 -06:00
|
|
|
|
# Eccentricity.
|
2022-05-21 22:31:23 -06:00
|
|
|
|
satellite_eccentricity=satellite.model.ecco
|
2022-05-21 13:51:34 -06:00
|
|
|
|
|
2022-05-21 17:54:49 -06:00
|
|
|
|
# Argument of perigee in radians.
|
2022-05-21 22:31:23 -06:00
|
|
|
|
satellite_arg_of_pericenter=math.degrees(satellite.model.argpo)
|
2022-05-21 13:51:34 -06:00
|
|
|
|
|
2022-05-21 17:54:49 -06:00
|
|
|
|
# Mean anomaly in radians.
|
2022-05-21 22:31:23 -06:00
|
|
|
|
satellite_mean_anomaly=math.degrees(satellite.model.mo)
|
2022-05-21 17:54:49 -06:00
|
|
|
|
|
|
|
|
|
# Mean motion in radians per minute.
|
2022-05-21 22:31:23 -06:00
|
|
|
|
satellite_period=(1 / (satellite.model.no_kozai * xpdotp))
|
2022-05-21 17:54:49 -06:00
|
|
|
|
|
|
|
|
|
# Revolution number at epoch [Revs]
|
2022-05-21 22:31:23 -06:00
|
|
|
|
satellite_revnum=satellite.model.revnum
|
2022-05-21 17:54:49 -06:00
|
|
|
|
|
2022-05-21 20:32:35 -06:00
|
|
|
|
# Semi-Major Axis
|
2022-05-21 22:31:23 -06:00
|
|
|
|
satellite_semimajor_axis=pow((pow(satellite_period,2) * 75371000000000),0.33333333)
|
2022-05-21 17:54:49 -06:00
|
|
|
|
|
2022-05-21 20:32:35 -06:00
|
|
|
|
# Rotation Offset
|
2022-05-21 22:31:23 -06:00
|
|
|
|
satellite_rotation_offset=((satellite_arg_of_pericenter)+(satellite_mean_anomaly)+360*
|
|
|
|
|
((2451545-satellite_epochdays)/satellite_period-
|
|
|
|
|
round((2451545-satellite_epochdays)/satellite_period)))
|
2022-05-21 20:32:35 -06:00
|
|
|
|
|
|
|
|
|
# Output for .ssc file
|
2022-05-21 22:31:23 -06:00
|
|
|
|
print('"', satellite_name, '" "Sol/Earth" {',sep="")
|
|
|
|
|
print(' Class "spacecraft"')
|
|
|
|
|
print(' # Mesh "foo.3ds" XXX')
|
|
|
|
|
print(' radius', "%.3f" %satellite_radius)
|
|
|
|
|
print()
|
|
|
|
|
print(' EllipticalOrbit {')
|
|
|
|
|
print(' Epoch', "%.8f" %satellite_epoch)
|
|
|
|
|
print(' Period', "%.8f" %satellite_period)
|
|
|
|
|
print(' SemiMajorAxis', "%.3f" %satellite_semimajor_axis)
|
|
|
|
|
print(' Eccentricity', "%.8f" %satellite_eccentricity)
|
|
|
|
|
print(' Inclination', "%.4f" %satellite_inclination)
|
|
|
|
|
print(' AscendingNode', "%.4f" %satellite_ascending_node)
|
|
|
|
|
print(' ArgOfPericenter', "%.4f" %satellite_arg_of_pericenter)
|
|
|
|
|
print(' MeanAnomaly', "%.4f" %satellite_mean_anomaly)
|
|
|
|
|
print(' }')
|
|
|
|
|
print(' Obliquity', "%.4f" %satellite_obliquity)
|
|
|
|
|
print(' EquatorAscendingNode', "%.4f" %satellite_equator_ascending_node)
|
|
|
|
|
print(' RotationOffset', "%.4f" %satellite_rotation_offset)
|
|
|
|
|
print(' # Orientation [ ]')
|
|
|
|
|
print('}')
|
|
|
|
|
print()
|
2022-05-21 13:51:34 -06:00
|
|
|
|
|