简体   繁体   中英

np.loadtxt() How to read a TLE satellite txt file into Python

I am trying to access the data in a TLE file for the space station in Python. However, it is having trouble reading in the data as TLE's have both numbers and letters. I don't need any of the letters and want it to be strictly numerical.

Code:

import numpy as np

fname = 'zarya.txt'
a = np.loadtxt(fname)

yearDigit = a[0,3]
print(yearDigit)
#year = a[:,]
#dayOfYear = a[:,3]
#fractionDay = a[:,7]

Error: ValueError: invalid literal for float(): 25544U

Here are the first two lines of data in my file:

1 25544U 98067A 98324.28472222 -.00003657 11563-4 00000+0 0 10

2 25544 51.5908 168.3788 0125362 86.4185 359.7454 16.05064833 05

Also, is there a way to access just the first two digits (98) of a[0,3] = 98324.28472222 ?

If you do not need any of the TLE values with letters than this solution will work for you.

import numpy as np

filename = 'zarya2000data.txt'
a = np.genfromtxt(filename)

All the values in the TLE with letters, such as 25544U, will show as nan when you print the data. The values that are just numbers will be fine and accessible as normal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM