There are so many possible circumstances that users may ask about when a satellite crosses a certain longitude; when it reaches a certain latitude; when it reaches a certain height or falls to the lowest height; when its speed is great or less - PyEphem does not try to provide built-in functions for all of them. Instead, it provides a function newton()that allows you to find the zero intersection of any comparison that you want to make between the satellite attribute and the predefined value of that attribute that you want to find.
Please note that the SciPy Python library contains some very thorough search functions, which are much more complicated than the PyEphem function newton()if you are dealing with a particularly poorly executed function:
http://docs.scipy.org/doc/scipy/reference/optimize.html
, - , ISS - , . - , , , , , , , . , , , znorm , . , script !
import ephem
line0 = 'ISS (ZARYA) '
line1 = '1 25544U 98067A 13110.27262069 .00008419 00000-0 14271-3 0 6447'
line2 = '2 25544 51.6474 35.7007 0010356 160.4171 304.1803 15.52381363825715'
sat = ephem.readtle(line0, line1, line2)
target_long = ephem.degrees('-83.8889')
def longitude_difference(t):
'''Return how far the satellite is from the target longitude.
Note carefully that this function does not simply return the
difference of the two longitudes, since that would produce a
terrible jagged discontinuity from 2pi to 0 when the satellite
crosses from -180 to 180 degrees longitude, which could happen to be
a point close to the target longitude. So after computing the
difference in the two angles we run degrees.znorm on it, so that the
result is smooth around the point of zero difference, and the
discontinuity sits as far away from the target position as possible.
'''
sat.compute(t)
return ephem.degrees(sat.sublong - target_long).znorm
t = ephem.date('2013/4/20')
d = longitude_difference(t)
while d > 0:
t += ephem.minute
sat.compute(t)
d = longitude_difference(t)
while d < 0:
t += ephem.minute
sat.compute(t)
d = longitude_difference(t)
tn = ephem.newton(longitude_difference, t - ephem.minute, t)
print 'When did ISS cross this longitude?', target_long
print 'At this specific date and time:', ephem.date(tn)
sat.compute(tn)
print 'To double-check, at that time, sublong =', sat.sublong
, script, , ( ), :
When did ISS cross this longitude? -83:53:20.0
At this specific date and time: 2013/4/20 00:18:21
To double-check, at that time, sublong = -83:53:20.1