I am trying to predict calculate the positions and predict passes of a LEO satellite from a TLE file. For convenience I just take the international space station.
What I did so far, is to download the spg4 libraries sgp4 libraries for C++ and looked at the two example programs sattrak and passpredict. The former gives the positions of an earth satellite in an ECI coordinate system and the lattter predicts when it will be visible from a certain location on earth.
The only thing I did so far is to enter a recent TLE file, change the observer position and compiled it, once with the included makefile and once via g++ foo.cpp -o bar /usr/lib/libsgp4
Comparing the results with the predicted passes in Heavens Above, the results differ significantly. For the predicted passes, for example, between some seconds up to about 90 secs. The maximum altitude seams not so wrong, though Heavens Above rounds on full degrees, which makes it hard to compare. To exclude, that they just differ on their algorithm of determining whether the satellite is visible, I compared it with the data from sattrak, confirming that the calculated positions are actually different.
I also tried the same using the pyephem library for python, which seems vary convenient. I tried the following to calculate the next five passes:
#!/usr/bin/python
import sys
import math
import ephem
iss = ephem.readtle("ISS Zarya",
"1 25544U 98067A 16034.21638441 .00007171 00000-0 11436-3 0 9997",
"2 25544 51.6442 11.1183 0006796 73.3436 50.5136 15.54391313983985")
observer = ephem.Observer()
observer.lat = '48'
observer.lon = '16'
observer.elevation = 179
observer.horizon = '10'
print("observer:\nLattitude: ", observer.lat,"\n Longitude: ", observer.lon,"\n", "horizon: ", observer.horizon,"\n")
for p in range(5):
tr, azr, tt, altt, ts, azs = observer.next_pass(iss)
rise = tr
print("===============================")
while tr < ts:
observer.date = tr
iss.compute(observer)
tr = ephem.Date(tr + 10 * ephem.minute)
print("Rise: ", rise)
print("Set time: ", ts)
print("Duration: ",math.floor((ts-rise)*60*24), "min", math.floor(((ts-rise)*60*24)%1*60), "s")
print("Max. Alt: %4.2f \n" % (math.degrees(altt)))
observer.date = tr + ephem.minute
However, the results do not match with Heavens Above (or the C++ code) either, though the difference is always below 10s.
Honestly, I do not know anything about the libastro routines used in pyephem and hence do not trust them to 100%. Please correct me, if I am wrong.
Does anyone has an idea, why I do not get the expected results? In my opinion, using the unchanged passpredict program gives very few possibility to mess it up.
I do not really care about whether I will use C++ or python as long as I get good results. Besides, the python-sgp4 looks so good, I am quite confident, that I can exchange between python and C++ easily once I get it right.
I really hope, there is someone who can help me as I am quite helpless right now, with not even a minimal example working. I know, that there already is a similar post, but I do not think, that I gave it a chance to confuse coordinate systems, which was the problem in the other post.
Thank you very much in advance!