2023-06-23 13:39:10 -06:00
|
|
|
|
#!/usr/bin/env python3
|
2022-05-22 12:16:00 -06:00
|
|
|
|
"""
|
|
|
|
|
tle2ssc
|
|
|
|
|
Convert TLE orbit to Solar System Catalog (SSC) format for Celestia.
|
|
|
|
|
|
2023-06-23 13:39:10 -06:00
|
|
|
|
Copyright (C) 2022, 2023, Jeff Moe
|
2022-05-22 12:16:00 -06:00
|
|
|
|
Authors: Jeff Moe
|
|
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
"""
|
|
|
|
|
|
2022-05-21 12:39:21 -06:00
|
|
|
|
# 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 22:36:50 -06:00
|
|
|
|
|
2022-05-22 12:49:52 -06:00
|
|
|
|
satellites = load.tle_file(satellites_url,reload=True)
|
2022-05-21 17:54:49 -06:00
|
|
|
|
|
|
|
|
|
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 22:36:50 -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"')
|
2022-05-22 14:34:33 -06:00
|
|
|
|
print(' Mesh "galileo-gnss.cmod"')
|
2022-05-23 00:56:20 -06:00
|
|
|
|
print(' Radius', "%.3f" %satellite_radius)
|
2022-05-21 22:31:23 -06:00
|
|
|
|
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
|
|
|
|
|