forked from santoshphilip/pyclearsky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_clearskyrad.py
205 lines (181 loc) · 7.07 KB
/
test_clearskyrad.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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# Copyright (c) 2013 Santosh Philip
# This file is part of pyclearsky.
# pyclearsky is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# pyclearsky is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with pyclearsky. If not, see <http://www.gnu.org/licenses/>.
"""py.test for clearskyrad.py"""
import clearskyrad
from pytest_helpers import almostequal
from datetime import datetime
def test_degcos():
"""py.test for degcos"""
data = ((60, 0.5), # deg, thecos
)
for deg, thecos in data:
result = clearskyrad.degcos(deg)
assert almostequal(result, thecos) == True
def test_degsin():
"""py.test for degcos"""
data = ((30, 0.5), # deg, thesin
)
for deg, thesin in data:
result = clearskyrad.degsin(deg)
assert almostequal(result, thesin) == True
def test_ETradiation():
"""py.test for ETradiation"""
data = ((21, 1410), # daynum, radiation
(52, 1397), # daynum, radiation
(80, 1378), # daynum, radiation
(111, 1354), # daynum, radiation
(141, 1334), # daynum, radiation
(172, 1323), # daynum, radiation
(202, 1324), # daynum, radiation
(233, 1336), # daynum, radiation
(264, 1357), # daynum, radiation
(294, 1380), # daynum, radiation
(325, 1400), # daynum, radiation
(355, 1411), # daynum, radiation
)
for daynum, radiation in data:
result = clearskyrad.ETradiation(daynum=daynum)
assert almostequal(result, radiation, places=0) == True
from datetime import datetime as dt
data = ((dt(2013, 1, 21), 1410), # thedate, radiation
(dt(2013, 2, 21), 1397), # thedate, radiation
(dt(2013, 3, 21), 1378), # thedate, radiation
(dt(2013, 4, 21), 1354), # thedate, radiations
(dt(2013, 5, 21), 1334), # thedate, radiation
(dt(2013, 6, 21), 1323), # thedate, radiation
(dt(2013, 7, 21), 1324), # thedate, radiation
(dt(2013, 8, 21), 1336), # thedate, radiation
(dt(2013, 9, 21), 1357), # thedate, radiation
(dt(2013, 10, 21), 1380), # thedate, radiation
(dt(2013, 11, 21), 1400), # thedate, radiation
(dt(2013, 12, 21), 1411), # thedate, radiation
)
for thedate, radiation in data:
result = clearskyrad.ETradiation(thedate=thedate)
# print result, radiation
assert almostequal(result, radiation, places=0) == True
def test_airmass():
"""py.test for airmass"""
data = ((30, 1.9942928525), # alt, theairmass
(45, 1.412595252), # alt, theairmass
(60, 1.1539922334), # alt, theairmass
(90, 0.9997119919), # alt, theairmass
)
for alt, theairmass in data:
result = clearskyrad.airmass(alt)
assert almostequal(result, theairmass)
def test_tau():
"""py.test for tau"""
data = ((""" - Displaying Monthly Design Conditions "Climate Design Data 2009 ASHRAE Handbook"
- Monthly Optical Sky Depth Beam (taub) and Diffuse (taud)
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
taub (beam) 0.289 0.29 0.325 0.351 0.377 0.37 0.362 0.352 0.343 0.323 0.302 0.289
taud (diffuse) 2.641 2.681 2.392 2.292 2.224 2.361 2.489 2.561 2.539 2.534 2.618 2.633
taub = Clear Sky Optical Depth for Beam Irradiance
taud = Clear Sky Optical Depth for Diffuse Irradiance
""",
[0.289, 0.29, 0.325, 0.351, 0.377, 0.37,
0.362, 0.352, 0.343, 0.323, 0.302, 0.289],
[2.641, 2.681, 2.392, 2.292, 2.224, 2.361,
2.489, 2.561, 2.539, 2.534, 2.618, 2.633]), # txt, taub, taud
)
for txt, taub, taud in data:
import StringIO
fhandle = StringIO.StringIO(txt)
result = clearskyrad.tau(fhandle)
assert result == (taub, taud)
def test_getab():
"""py.test for getab"""
data = ((0.289, 2.641, 0.652079204), # taub, taud, theab
)
for taub, taud, theab in data:
result = clearskyrad.getab(taub, taud)
assert almostequal(result, theab)
def test_getad():
"""py.test for getad"""
data = ((0.289, 2.641, -0.335194893), # taub, taud, thead
)
for taub, taud, thead in data:
result = clearskyrad.getad(taub, taud)
assert almostequal(result, thead)
def test_directnormal_inner():
"""py.test for directnormal_inner"""
data = ((1409.962705, 0.289, 0.999711992,
0.652079204, 1056.136599), # E0, taub, m, ab, Eb
)
for E0, taub, m, ab, Eb in data:
result = clearskyrad.directnormal_inner(E0, taub, m, ab)
assert almostequal(result, Eb, places=6)
def test_diffhoriz_inner():
"""py.test for diffhoriz_inner"""
data = ((1409.962705, 2.641, 0.999711992,
-0.335194893, 100.490533,), # E0, taud, m, ad, Ed
)
for E0, taud, m, ad, Ed in data:
result = clearskyrad.diffhoriz_inner(E0, taud, m, ad)
assert almostequal(result, Ed, places=6)
def test_directnormal():
"""py.test for directnormal"""
data = ((0.289, 2.641, 90, 21, 1056.136599), # taub, taud, alt, daynum, Eb
)
for taub, taud, alt, daynum, Eb in data:
result = clearskyrad.directnormal(taub, taud, alt, daynum)
assert almostequal(result, Eb, places=5)
def test_diffusehorizontal():
"""py.test for diffusehorizontal"""
data = ((0.289, 2.641, 90, 21, 100.490533), # taub, taud, alt, daynum, Eb
)
for taub, taud, alt, daynum, Eb in data:
result = clearskyrad.diffusehorizontal(taub, taud, alt, daynum=daynum)
assert almostequal(result, Eb)
def test_weatherdata():
"""py.test with real weather data"""
# from USA_AZ_Phoenix.722780_TMY2.ddy
# datetime = month, date, hour = 1, 24, 13
# ET Horizontal Radiation = 852
# ET Direct Normal radiation = 1412
# Direct Normal Radiation = 969
# Diffuse horizontal radiation = 71
# Total Sky cover = 0
# Opaque sky cover = 0
# from USA_AZ_Phoenix.722780_TMY2.stat
# Jan taub = 0.306
# Jan taud = 2.534
# Feb taub = 0.317
# Feb taud = 2.463
# from <http://www.esrl.noaa.gov/gmd/grad/solcalc/azel.html>
# solar azimuth = 185.8 degrees
# solar altitude = 37.36 degrees
Eb = 969
taub = 0.306
taud = 2.534
alt = 37.36
daynum = 24
result = clearskyrad.directnormal(taub, taud, alt, daynum=daynum)
# assert result == Eb
Ed = 71
result = clearskyrad.diffusehorizontal(taub, taud, alt, daynum=daynum)
# assert result == Ed
# other days
# 1975, 2, 16, 14
Eb = 816
taub = 0.317
taud = 2.463
alt = 40.67
daynum = 24
thedate = datetime(1975, 2, 16)
result = clearskyrad.directnormal(taub, taud, alt, thedate=thedate)
# assert result == Eb
Ed = 152
result = clearskyrad.diffusehorizontal(taub, taud, alt, thedate=thedate)
assert result == Ed