-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSimplePythonSunPositionCalculator.py
94 lines (68 loc) · 2.97 KB
/
SimplePythonSunPositionCalculator.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
86
87
88
89
90
91
92
93
94
import math
import datetime
def getSEA(latitude, longitude, utc_offset):
date = datetime.datetime.now().timetuple()
print('date', date)
hour = date[3]
minute = date[4]
# Check your timezone to add the offset
hour_minute = (hour + minute / 60) - utc_offset
day_of_year = date[7]
g = (360 / 365.25) * (day_of_year + hour_minute / 24)
g_radians = math.radians(g)
declination = 0.396372 - 22.91327 * math.cos(g_radians) + 4.02543 * math.sin(g_radians) - 0.387205 * math.cos(
2 * g_radians) + 0.051967 * math.sin(2 * g_radians) - 0.154527 * math.cos(3 * g_radians) + 0.084798 * math.sin(
3 * g_radians)
time_correction = 0.004297 + 0.107029 * math.cos(g_radians) - 1.837877 * math.sin(g_radians) - 0.837378 * math.cos(
2 * g_radians) - 2.340475 * math.sin(2 * g_radians)
SHA = (hour_minute - 12) * 15 + longitude + time_correction
if (SHA > 180):
SHA_corrected = SHA - 360
elif (SHA < -180):
SHA_corrected = SHA + 360
else:
SHA_corrected = SHA
lat_radians = math.radians(latitude)
d_radians = math.radians(declination)
SHA_radians = math.radians(SHA)
SZA_radians = math.acos(
math.sin(lat_radians) * math.sin(d_radians) + math.cos(lat_radians) * math.cos(d_radians) * math.cos(
SHA_radians))
SZA = math.degrees(SZA_radians)
SEA = 90 - SZA
return SEA
def getAZ(latitude, longitude, utc_offset):
date = datetime.datetime.now().timetuple()
hour = date[3]
minute = date[4]
# Check your timezone to add the offset
hour_minute = (hour + minute / 60) - utc_offset
day_of_year = date[7]
g = (360 / 365.25) * (day_of_year + hour_minute / 24)
g_radians = math.radians(g)
declination = 0.396372 - 22.91327 * math.cos(g_radians) + 4.02543 * math.sin(g_radians) - 0.387205 * math.cos(
2 * g_radians) + 0.051967 * math.sin(2 * g_radians) - 0.154527 * math.cos(3 * g_radians) + 0.084798 * math.sin(
3 * g_radians)
time_correction = 0.004297 + 0.107029 * math.cos(g_radians) - 1.837877 * math.sin(g_radians) - 0.837378 * math.cos(
2 * g_radians) - 2.340475 * math.sin(2 * g_radians)
SHA = (hour_minute - 12) * 15 + longitude + time_correction
if (SHA > 180):
SHA_corrected = SHA - 360
elif (SHA < -180):
SHA_corrected = SHA + 360
else:
SHA_corrected = SHA
lat_radians = math.radians(latitude)
d_radians = math.radians(declination)
SHA_radians = math.radians(SHA)
SZA_radians = math.acos(
math.sin(lat_radians) * math.sin(d_radians) + math.cos(lat_radians) * math.cos(d_radians) * math.cos(
SHA_radians))
SZA = math.degrees(SZA_radians)
cos_AZ = (math.sin(d_radians) - math.sin(lat_radians) * math.cos(SZA_radians)) / (
math.cos(lat_radians) * math.sin(SZA_radians))
AZ_rad = math.acos(cos_AZ)
AZ = math.degrees(AZ_rad)
# You may need to use this check github description
#AZ_NORTH_TO_EAST = 360 - AZ
return AZ