-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday_length.html
More file actions
122 lines (101 loc) · 3.8 KB
/
day_length.html
File metadata and controls
122 lines (101 loc) · 3.8 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<!-- Local files containing the website icon and stylesheet. -->
<link rel="stylesheet" type="text/css" href="theme.css">
<!--<link rel="stylesheet" type="text/css" href="https://sagecell.sagemath.org/static/sagecell_embed.css">-->
<!-- Imports needed to use the Sage cell server. -->
<script type="text/javascript" src="https://sagecell.sagemath.org/static/jquery.min.js"></script>
<script type="text/javascript" src="https://sagecell.sagemath.org/embedded_sagecell.js"></script>
<!--<script>sagecell.makeSagecell({"inputLocation": ".sage"});</script>-->
<!--<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="embedded_sagecell.js"></script>-->
<script type="text/javascript" src="sagecell.js"></script>
<script type="text/javascript" src="sage-text.js"></script>
<!-- Additional CSS customizations -->
<style type="text/css"></style>
<!-- Page title -->
<title>Computational Dendrochronology Toolbox (CDTBX)</title>
</head>
<body>
<h2>Computational Dendrochronology Toolbox (CDTBX)</h2>
<p>Deriving the formulas to calculate the length of day.
<div class="sagecell-plot" id="sagecell2">
<script type="application/sage">
# coding=utf-8
__author__ = 'vilyin'
def day_length(Day, Latitude=(-(36+51/60.))):
"""
This calculates the number of hours (hours) and fraction of the day (b) in %daylight.
http://www.gandraxa.com/length_of_day.xml
"""
if Day < 0:
Day=0
Pi=n(pi)
Axis=23.439*Pi/180.
j=Pi/182.625 #constant (radians)
m=1-tan(Latitude*Pi/180.)*tan(Axis*cos(j*Day))
b=arccos(1-m)/Pi #fraction of the day the sun is up
if b < 0:
b=0
if b > 1:
b=1
hours=b*24 #hours of sunlight
return [b, hours]
def daylight_year(Latitude):
"""
The length of daylight hours in a year
"""
Days=range(365)
for idx in range(365):
Days[idx] = day_length(idx, Latitude)
Days[idx][0] = idx
return Days
def plot_daylight_year(Latitude, LatStr):
dy=daylight_year(Latitude)
plt=list_plot(dy, color='steelblue',legend_label=LatStr)
plt.ymax(25.0); plt.ymin(-1.0)
plt.xmax(400.0); plt.xmin(0.0)
plt.axes_labels(['Day', 'Hours'])
plt.show(aspect_ratio=10,frame=True, gridlines=["major", True])
@interact
def plotDaylight(
clr=Color('green'),
manual=checkbox(True, 'Manual'),
redraw=checkbox(False, 'Redraw'),
Degrees=slider(0,90, 1, default=66, label='Degrees'),
Minutes=slider(0,60, 1, default=33,label='Minutes'),
#plotpoints=('Value of Latitude',[100,500,1000]),
Sity=('Value of Latitude',['Chokurdakh','Yakutsk','Arizona'])):
"""
http://www.gandraxa.com/length_of_day.xml
"""
Latitude=N(Degrees+Minutes/60)
if Sity == 'Chokurdakh' and manual == False:
Latitude=N(70.62); LatStr='Chokurdakh=70.62' #https://www.wolframalpha.com/input/?i=Chokurdakh
elif Sity == 'Yakutsk' and manual == False:
Latitude=N(62.03); LatStr='Yakutsk=62.03'
elif Sity == 'Arizona' and manual == False:
Latitude=N(70.62); LatStr='Arizona'
elif Latitude == 0:
LatStr='Equator'
elif Latitude == 90:
LatStr='Northpole'
else:
LatStr='Latitude=' + ("%2.2f" % N(Degrees+Minutes/60.)).rjust(6)
if redraw == True:
dy=daylight_year(N(Latitude))
plt=list_plot(dy, color='steelblue',legend_label=LatStr)
plt.ymax(25.0); plt.ymin(-1.0)
plt.xmax(370.0); plt.xmin(0.0)
plt.axes_labels(['Day of Year', 'Hours'])
plt.show(aspect_ratio=10,frame=True, gridlines=["major", True])
else:
print daylight_year(N(Latitude))
var('m')
show(arccos(1-m)/pi)
</script>
</div>
<script type="text/javascript">sageFooter()</script>
</body>
</html>