pythonpyephem

Pyephem and pypredict/gpredict differences


I am trying to use pyephem to predict satellite passes for a ground station. However, the results I get are quite different from the ones I get with pypredict and gpredict. Here is the code I wrote.

import ephem
import predict
import datetime as dt

def passes(station, satellite, start=None, duration=7):
    result = []
    if start is not None:
        station.date = ephem.date(start)
    end = ephem.date(station.date + duration)
    while station.date < end:
        t_aos, azr, t_max, elt, t_los, azs = station.next_pass(satellite)
        result.append({'aos': t_aos.datetime(), 'los': t_los.datetime()})
        station.date = t_los + ephem.second
    return result

tle = """ISS (ZARYA)
1 25544U 98067A   18274.33960752  .00001880  00000-0  36095-4 0  9991
2 25544  51.6416 209.7138 0003794 227.2741 275.6194 15.53757611135029"""

station = ephem.Observer()
station.lat = 20
station.long = 0
station.elev = 0

epoch = dt.datetime.utcnow()

for i in passes(station, ephem.readtle(*tle.split("\n")), epoch, 1):
    print(i['aos'], i['los'])

print("===============")
p = predict.transits(tle, (station.lat, -station.long, station.elev), (epoch - dt.datetime(1970,1,1)).total_seconds())
for i in range(1, 8):
        transit = p.next()
        print(dt.datetime.utcfromtimestamp(transit.start), dt.datetime.utcfromtimestamp(transit.end))

And the results

(datetime.datetime(2018, 10, 1, 17, 4, 43, 552230), datetime.datetime(2018, 10, 1, 17, 11, 12, 744164))
(datetime.datetime(2018, 10, 1, 18, 39, 4, 59194), datetime.datetime(2018, 10, 1, 18, 47, 5, 185600))
(datetime.datetime(2018, 10, 1, 20, 14, 28, 126953), datetime.datetime(2018, 10, 1, 20, 22, 3, 101339))
(datetime.datetime(2018, 10, 1, 21, 51, 6, 130556), datetime.datetime(2018, 10, 1, 21, 55, 21, 829297))
(datetime.datetime(2018, 10, 2, 16, 13, 51, 767026), datetime.datetime(2018, 10, 2, 16, 19, 13, 556850))
===============
(datetime.datetime(2018, 10, 1, 13, 43, 6, 584816), datetime.datetime(2018, 10, 1, 13, 53, 21, 721679))
(datetime.datetime(2018, 10, 1, 15, 20, 13, 473098), datetime.datetime(2018, 10, 1, 15, 29, 13, 799433))
(datetime.datetime(2018, 10, 1, 21, 58, 25, 378030), datetime.datetime(2018, 10, 1, 22, 1, 54, 993473))
(datetime.datetime(2018, 10, 1, 23, 32, 5, 284033), datetime.datetime(2018, 10, 1, 23, 42, 37, 942300))
(datetime.datetime(2018, 10, 2, 1, 9, 49, 741668), datetime.datetime(2018, 10, 2, 1, 17, 12, 346213))
(datetime.datetime(2018, 10, 2, 12, 51, 59, 647871), datetime.datetime(2018, 10, 2, 13, 0, 57, 292565))
(datetime.datetime(2018, 10, 2, 14, 27, 39, 19468), datetime.datetime(2018, 10, 2, 14, 37, 48, 730909))

What am I doing wrong with pyephem?


Solution

  • If I'm remembering correctly, a very awkward interface decision in PyEphem was that angles provided as floats are radians. (One reason I started writing Skyfield was to have an astronomy library without that problem!)

    Try:

    station.lat = '20.0'