-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSunriseClass.py
85 lines (73 loc) · 2.49 KB
/
SunriseClass.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import time
import math
import datetime
class Sunrise:
def __init__(self):
self.dt = datetime.datetime.now()
self.day = 1
self.month = 1
self.year = 1900
def sunrise(self,month, year, day):
self.month = month
self.year = year
self.day= day
global R2D
R2D = 180/math.pi
global D2R
D2R = math.pi/180
self.day_of_the_year( month, year, day)
self.longitude_to_hour()
self.sun()
return self.dt
def sun(self):
M = (0.9856 * rise_time) - 3.289
L = M + ( 1.916 * math.sin(M* D2R)) + (0.020 * math.sin(2*M*D2R)) + 282.63
if L < 0:
L = L+360
elif L > 360:
L = L - 360
RA =R2D* math.atan(0.91764 * math.tan(L*D2R))
if RA < 0 :
RA = RA + 360
elif RA > 360:
RA = RA - 360
Lquad = ( math.floor( L/ 90)) * 90
RAquad = ( math.floor(RA/90)) *90
RA = RA + (Lquad - RAquad)
RA = RA/15
sinDec = 0.39782 * math.sin(L*D2R)
cosDec = math.cos(math.asin(sinDec))
cosH = ( math.cos(90.83*D2R) - (sinDec * math.sin(latitude*D2R))) / (cosDec * math.cos(latitude*D2R))
Hrise = 360 -(R2D * math.acos( cosH))
Hrise = Hrise/15
T = Hrise + RA - ( 0.06571 * rise_time) - 6.622
UT = T - lngHour
if UT < 0:
UT = UT + 24
elif UT > 24:
UT = UT - 24
UT=UT+2
UT = (UT*3600)
UT = time.gmtime(UT)
self.dt = datetime.datetime(self.year,self.month,self.day, UT.tm_hour, UT.tm_min,0,0,None)
#self.dt = datetime.datetime(1900,1,1,UT.tm_hour,UT.tm_min,0,0,None)
# print(self.dt)
# return self.dt
#print("Sunrise time is %s:%s "%(UT.tm_hour, UT.tm_min))
def longitude_to_hour(self):
global longitude
longitude = 31.2357116
global latitude
latitude = 30.0444196
global lngHour
lngHour = longitude / 15
global rise_time
global set_time
rise_time = N + ( (6 - lngHour) / 24)
set_time = N + ( (18 - lngHour) / 24)
def day_of_the_year(self, month, year, day):
N1 = math.floor(275 * month / 9)
N2 = math.floor( (month+ 9) / 12)
N3 = ( 1 + math.floor( (year - 4 * math.floor(year/4) + 2 ) / 3))
global N
N = N1 - (N2 * N3) + day - 30