I am a fledgling at best when it comes to programing. I am trying to acclimate myself with Python's date and time functions. Below is a program I wrote to calculate the Sun rise and set times for a given lat, long. What I am hoping to find out is if there is a way to obtain the Julian date from a given date input so I do not have to calculate the date ahead of time and input it as a parameter, and avoid having to, otherwise, add several lines just to make this happen myself? Also are there functions, as they have in excel, to convert between radians and degrees so I can avoid the lengthy lines of having to do the conversions within my code? Thanks
#parameter JD is today's current Julian Date
def SunRise(lat,lng,JD,y,m,d):
import math
from datetime import datetime
import time
from datetime import date
now = date.today
day = date(y,m,d)
Day =day.strftime('%j')
J = 2451545.0
n = round(JD-J-.0009*(lng/360.0))
J1 = J+.0009+(lng/360.0)+n
J2 = J1-J
Mi= ((357.5291+(.98560028*J2))/360)
M = (360*(Mi%1))
z = (360/math.pi)*.0167
C = z*math.sin(M*math.pi/180)+0.0200*math.sin(2*M*math.pi/180)+0.0003*math.sin(3*M*math.pi/180)
La = (M+102.9372+C+180)
Jt = J1+(0.0053*math.sin(M*math.pi/180))-(0.0009*math.sin(2*La*math.pi/180))
D =180/math.pi*(math.asin((math.sin(23.45*math.pi/180))*math.sin(La*math.pi/180)))
Phi = (180/math.pi)*(math.acos((math.sin(-5.06/6.0*math.pi/180)-(math.sin(lat*math.pi/180)*math.sin(D*math.pi/180)))/(math.cos(lat*math.pi/180)*math.cos(D*math.pi/180))))
Jset = J+0.0009+((Phi+lng)/360)+n+(0.0053*math.sin(M*math.pi/180)-(0.0069*math.sin(2*La*math.pi/180)))
Jrise = Jt-(Jset-Jt)
DdayS = Jset-(J+0.5)
SShour = int((DdayS%1)*24)-5
if SShour <= 0:
SShour = SShour+24
SSmin = int(((24*(DdayS%1)-5.0)%1)*60)
SSsec = int(((((24*(DdayS%1)-5.0)%1)*60)%1)*60)
DdayR = Jrise-(J+0.5)
SRhour = int((DdayR%1)*24)-5
SRmin = int(((24*(DdayR%1)-5.0)%1)*60)
SRsec = int(((((24*(DdayR%1)-5.0)%1)*60)%1)*60)
DSTstart = date(2012,03,11)
DSTS = DSTstart.strftime('%j')
DSTend = date(2012,11,04)
DSTE = DSTend.strftime('%j')
if Day > DSTS and Day< DSTE:
SShour += 1
SRhour += 1
print "The Sun will rise at:",SRhour,":",SRmin,":",SRsec,"AM EST",d,m,y
print "The Sun will set at:",SShour,":",SSmin,":",SSsec,"PM EST",d,m,y
SunRise(34.1855444444,83.91405278,2456139,2012,07,30)