I want this code to output the date of every 30 degrees of a planets movement up until the date of today, but for some reason it stops at 360 degrees. Why is the code stopping here and not going through 390 degrees, 420, 450......etc.
from ephem import Venus, Date, degrees, newton
import datetime
v = Venus()
start_date = '2014/2/2 00:00'
v.compute(start_date)
Ls0 = v.hlon
print "VENUS",start_date, Ls0
print ""
arc = 0
while True:
d = start_date
today = datetime.date.today()
arc = arc + degrees('30:00:00')
if d == today:
break
def Ls(date):
v.compute(date)
return degrees(v.hlon - Ls0).norm
def thirty_degrees(date):
return Ls(date) - degrees(arc)
def find_thirty_degrees(start_date):
start_date = Date(start_date)
y0 = Ls(start_date)
y1 = Ls(start_date + 1)
rate = y1 - y0
angle_to_go = degrees(degrees(arc) - y0).norm
closer_date = start_date + angle_to_go / rate
d = newton(thirty_degrees, closer_date, closer_date + 1)
return Date(d)
d = find_thirty_degrees(start_date)
print d, Ls(d)
results are:
VENUS 2014/2/2 00:00 146:05:57.6
2014/2/20 11:27:19 30:00:00.0
2014/3/11 01:17:41 60:00:00.0
2014/3/29 18:50:49 90:00:00.0
2014/4/17 15:55:27 120:00:00.0
2014/5/6 15:00:08 150:00:00.0
2014/5/25 14:10:16 179:59:59.9
2014/6/13 12:02:34 210:00:00.0
2014/7/2 07:57:18 240:00:00.0
2014/7/21 01:36:05 270:00:00.0
2014/8/8 16:44:49 300:00:00.0
2014/8/27 05:27:54 330:00:00.0
2014/9/14 16:38:35 359:59:59.5