Created
November 25, 2019 20:23
-
-
Save nmk456/59e613c55ace89f471cf3ea0336c250d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pprint | |
def tleparse(line1, line2): | |
""" | |
Parses a TLE (two line elements) and returns a dictionary containing the data from the TLE. | |
For more information on TLE format: https://en.wikipedia.org/wiki/Two-line_element_set | |
Args: | |
line1: The first line of a TLE. | |
line2: The second line of a TLE. | |
Returns: | |
A dictionary containing all the information from the TLE. Example: | |
{ | |
'catalog': '25544', # Satellite catalog number and classification level | |
'class': 'U', # Classification level | |
'id': '98067A', # International designator | |
'id_year': 98, # Year component of ID | |
'id_number': 067, # Launch number component of ID | |
'id_piece': A, # Piece of launch from ID | |
'epoch': '08264.51782528', # Epoch | |
'epoch_year': 8, # Epoch year | |
'epoch_day': 264.51782528, # Epoch day of year and fractional day | |
'bc': 0.00000140, # Ballistic coefficient, or first derivative of mean motion | |
'drag': 0.000011606, # Drag term | |
'inc': 51.6416, # Inclination in degrees | |
'ra_an': 247.4627, # Right ascension of ascending node | |
'ecc': 0.0006703, # Eccentricity | |
'arg_peri': 130.5360, # Argument of perigee | |
'mean_anomaly': 325.0288, # Mean anomaly | |
'mean_motion': 15.72125391, # Number of revolutions per day | |
'revolutions': 56353 | |
} | |
""" | |
line1 = line1.strip() | |
line2 = line2.strip() | |
output = {} | |
assert line1[0:1] == '1', "Line 1 needs to start with 1 to be a valid TLE" | |
assert line2[0:1] == '2', "Line 2 needs to start with 2 to be a valid TLE" | |
output['catalog'] = line1[2:7] | |
output['class'] = line1[7:8] | |
output['id'] = line1[9:17].strip() | |
output['id_year'] = int(line1[9:11]) | |
output['id_number'] = int(line1[11:14]) | |
output['id_piece'] = line1[14:17].strip() | |
output['epoch'] = line1[18:32] | |
output['epoch_year'] = int(line1[18:20]) | |
output['epoch_day'] = float(line1[20:32]) | |
output['bc'] = float(line1[33:43]) | |
output['drag'] = float(line1[53:54] + "0." + "0"*int(line1[60:61]) + line1[54:59]) | |
output['inc'] = float(line2[8:16]) | |
output['ra_an'] = float(line2[17:25]) | |
output['ecc'] = float("0." + line2[26:33]) | |
output['arg_peri'] = float(line2[34:42]) | |
output['mean_anomaly'] = float(line2[43:51]) | |
output['mean_motion'] = float(line2[52:63]) | |
output['revolutions'] = int(line2[63:68]) | |
return output | |
if __name__ == '__main__': | |
sampleTLE = "1 25544U 98067A 08264.51782528 -.00002182 00000-0 -11606-4 0 2927\n2 25544 51.6416 247.4627 0006703 130.5360 325.0288 15.72125391563537" | |
sampleTLE = sampleTLE.split("\n") | |
pprint.pprint(tleparse(sampleTLE[0], sampleTLE[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment