-
Notifications
You must be signed in to change notification settings - Fork 0
/
ucsspm.py
executable file
·361 lines (269 loc) · 17.7 KB
/
ucsspm.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
#!/usr/bin/env python2
# -*- coding: UTF-8 -*-
################################################################################
#
# @file ucsspm.py
# @authors chrono
# @version V1.0.3 (Argument Tamer)
# @date 2014-11-15
# @brief Unified Clear-Sky Solar output Prediction Model (UCSSPM)
# @status Beta - Request for Comment, Re-Verification & Enhancement
#
################################################################################
# Copyright (c) 2014 Apollo-NG - https://apollo.open-resource.org/
################################################################################
#
# This program 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.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
import sys, argparse, math, time, calendar
################################################################################
## Inputs & Defaults #########################################################
################################################################################
def options(arg):
arg.add_argument( "-v", "--verbose" ,\
action = "store_true" ,\
help = "Verbose output" )
# Decreased Solar Constant - See docs/solar-constant.pdf for update info. ##
# Default value of 1361.0 should IMHO serve as a good average point
# between the min/max values over the 11-year sun cycle.
arg.add_argument( "-sc" ,\
type = float ,\
help = "Solar Constant (@1AU) in kW/m² [Default: 1361.0]" ,\
default = 1361.0 )
# Space/Time Pinpointing ###################################################
arg.add_argument( "-lat" ,\
type = float ,\
help = "Latitude in decimal degrees [Default: 48.0]" ,\
default = 48.00000 )
arg.add_argument( "-lon" ,\
type = float ,\
help = "Longitude in decimal degrees [Default: 11.0]" ,\
default = 11.00000 )
# Optional, only needed if barometric pressure not available to compute it.
# If no value is supplied to either, an altitude of 0m (NN) will be default
# Obviously, this is only a fallback and using the actual barometric pressure
# should always be preferred to yield a less averagish result.
arg.add_argument( "-alt" ,\
type = float ,\
help = "Altitude in meters above NN [Default: 0]" ,\
default = 0 )
arg.add_argument( "-date" ,\
type = str ,\
help = "ISO Date YYYY-MM-DD [Default: " \
+ time.strftime("%Y-%m-%d") + "]" ,\
default = time.strftime("%Y-%m-%d") )
arg.add_argument( "-time" ,\
type = str ,\
help = "ISO Time HH:MM:SS [Default: " \
+ time.strftime("%H:%M:%S") + "]" ,\
default = time.strftime("%H:%M:%S") )
# Environmental Conditions #################################################
arg.add_argument( "-at_t" ,\
type = float ,\
help = "Atmospheric Temperature in °C [Default: 25.0]" ,\
default = 25.0 )
arg.add_argument( "-at_h" ,\
type = float ,\
help = "Atmospheric Relative Humidity in Percent [Default: 50]" ,\
default = 50.0 )
# Can be optional by submitting altitude - but will be less precise then ###
arg.add_argument( "-at_p" ,\
type = float ,\
help = "Atmospheric Air Pressure in hPa [Default: Computed]" )
arg.add_argument( "-at_tc" ,\
type = float ,\
help = "Atmospheric Turbidity Coefficient [Default: 0.95]" ,\
default = 0.95 )
# Photovoltaic Parameters ##################################################
arg.add_argument( "-pv_a" ,\
type = float ,\
help = "Effective PV Panel Surface in m² [Default: 1.67]" ,\
default = 1.67 )
arg.add_argument( "-pv_e" ,\
type = float ,\
help = "PV Panel Efficiency in Percent [Default: 16]" ,\
default = 20 )
arg.add_argument( "-pv_t" ,\
type = float ,\
help = "PV Panel Temperature in °C [Default: 25.0]" ,\
default = 25.0 )
arg.add_argument( "-pv_tc" ,\
type = float ,\
help = "PV Panel negative Temp. Coefficient [Default: 0.35]" ,\
default = 0.35 )
arg.add_argument( "-pv_ac" ,\
type = float ,\
help = "PV Panel age related Coefficient [Default: 0.98]" ,\
default = 0.98 )
################################################################################
## Outputs ###################################################################
################################################################################
def output(opt,res):
if res['sol_z'] > 90:
if opt.verbose:
print "The sun has set - no data"
return 0
else:
print "0.0|0.0|90.0|0.0|0.0"
return 0
elif not opt.verbose:
print "%.1f|%.1f|%.1f|%.1f|%.1f" % \
( \
res['ETR'], res['RSO'], res['sol_z'] ,\
res['pv_max'], res['pv_out'] \
)
return 0
else:
print "--------+--------------------------------------------------------"
print " UCSSPM | Clear-Sky Prediction for %s @ %s" % (opt.date, opt.time )
print "--------+--------------------------------------------------------"
print " Solar Constant : %s kW/m² @ 1AU" % opt.sc
print " Atmospheric turbidity coefficient : %s" % opt.at_tc
print "-----------------------------------------------------------------"
print " Equation of time : %s min" % res['eqt']
print " Inverse relative distance factor : %s" % res['sol_r']
print " Sun declination : %s°" % res['sol_d']
print " Solar Noon : %s " % res['sol_n']
print " Barometric Pressure at site : %s kPa" % opt.at_p
print " Estimated Vapor Pressure at site : %s kPa" % res['at_vp']
print " Estimated Extraterrestrial Radiation : %s W/m²" % res['ETR']
print " Estimated precipitable water in Atmosphere : %s mm" % res['at_pw']
print " Clearness index for direct beam radiation : %s" % res['CIDBR']
print " Transmissivity index for diffuse radiation : %s" % res['TIDR']
print "-----------------------------------------------------------------"
print " Estimated Max. global solar radiation (Rs) : \033[1;33m%3.1f W/m²\033[0m" % res['RSO']
print "-----------------------------------------------------------------"
print " Optimum Elevation of PV-Panel : \033[1;37m%02.1f°\033[0m" % res['sol_z']
print " Estimated Max. Clear-Sky PV-Power Output : \033[1;32m%3.1f W\033[0m \033[1;37m@ %d%% Peff\033[0m" % (res['pv_max'], opt.pv_e)
if res['pv_lp'] >= 0:
print " PV-Panel temperature (%2.1f °C) compensation - \033[1;31m%2.1f W / %2.1f%%\033[0m" % (opt.pv_t, res['pv_lp'] , res['pv_l'] )
else:
print " PV-Panel temperature (%2.1f °C) compensation + \033[1;32m%2.1f W / %2.1f%%\033[0m" % (opt.pv_t, res['pv_lp']*-1 , res['pv_l']*-1 )
print " PV-Panel aging loss - \033[1;31m%03.1f W\033[0m" % res['pv_la']
print "-----------------------------------------------------------------"
print " Compensated Max. Clear-Sky PV-Power Output : \033[1;32m%3.1f W\033[0m" % res['pv_out']
return 0
################################################################################
## MAIN ######################################################################
################################################################################
def main():
arg = argparse.ArgumentParser()
options (arg)
opt = arg.parse_args()
parse_d = opt.date.split("-")
opt.year = int(parse_d[0])
opt.month = int(parse_d[1])
opt.day = int(parse_d[2])
parse_t = opt.time.split(":")
opt.hour = int(parse_t[0])
opt.min = int(parse_t[1])
opt.sec = int(parse_t[2])
dst_off = 0
tz_off_deg = 0 + opt.lon
res = {}
# Compute Julian Day (Day of Year) #########################################
if calendar.isleap(opt.year):
# Leap year (366 days)
lMonth = [0,31,60,91,121,152,182,213,244,274,305,335,366]
else:
# Normal year (365 days)
lMonth = [0,31,59,90,120,151,181,212,243,273,304,334,365]
res['DoY'] = lMonth[opt.month - 1] + opt.day
res['ToD'] = float(opt.hour + (opt.min/60.0) + (opt.sec/3600.0))
# Solve equation of time ###################################################
# (More info on http://www.srrb.noaa.gov/highlights/sunrise/azel.html)
res['eqt'] = (((5.0323-(430.847*math.cos((((2*math.pi)*res['DoY'])/366)+4.8718)))\
+ (12.5024*(math.cos(2*((((2*math.pi)*res['DoY'])/366)+4.8718))))\
+ (18.25*(math.cos(3*((((2*math.pi)*res['DoY'])/366)+4.8718))))\
- (100.976*(math.sin((((2*math.pi)*res['DoY'])/366)+4.8718))))\
+ (595.275*(math.sin(2*((((2*math.pi)*res['DoY'])/366)+4.8718))))\
+ (3.6858*(math.sin(3*((((2*math.pi)*res['DoY'])/366)+4.871))))\
- (12.47*(math.sin(4*((((2*math.pi)*res['DoY'])/366)+4.8718)))))\
/ 60
# Compute inverse relative distance factor (Distance between Earth and Sun)
res['sol_r'] = 1.0 / (1.0 - 9.464e-4 * math.sin(res['DoY']) \
- 0.01671 * math.cos(res['DoY']) \
- 1.489e-4 * math.cos(2.0 * res['DoY']) \
- 2.917e-5 * math.sin(3.0 * res['DoY']) \
- 3.438e-4 * math.cos(4.0 * res['DoY'])) ** 2
# Compute solar declination ################################################
res['sol_d'] = (math.asin(0.39785 * (math.sin(((278.97 \
+ (0.9856 * res['DoY'])) + (1.9165 \
* (math.sin((356.6 + (0.9856 * res['DoY'])) \
* (math.pi / 180))))) * (math.pi / 180)))) * 180) / math.pi
# Compute time of solar noon ###########################################
res['sol_n'] = ((12 + dst_off) - (res['eqt'] / 60)) \
- ((tz_off_deg - opt.lon) / 15)
# Compute solar zenith angle in DEG ####################################
res['sol_z'] = math.acos(((math.sin(opt.lat * (math.pi / 180))) \
* (math.sin(res['sol_d'] * (math.pi / 180)))) \
+ (((math.cos(opt.lat * ((math.pi / 180)))) \
* (math.cos(res['sol_d'] * (math.pi / 180)))) \
* (math.cos((res['ToD'] - res['sol_n']) \
* (math.pi /12))))) * (180/math.pi)
# A solar zenith angle value of > 90 usually indicates that the sun has set
# (from observer's perspective at the given location for this computation).
# However, in extreme latitudes, valid values over 90 may occur. If you live
# in such a place and happen to stumble upon this code, please report back
# when you use it so we can find a better fix for this than the follwing hack.
# Unfortunately, if we don't fail safely here, we are confronted with some
# nasty division by zero business further on, so...
if res['sol_z'] > 90:
output (opt, res)
sys.exit (0)
# Barometric pressure at site ##############################################
# (this should be replaced by the real measured value) in kPa
if opt.at_p:
# Real value given, convert hPa to kPa
opt.at_p = opt.at_p / 10
else:
# Estimate Pressure from given altitude
opt.at_p = math.pow(((288 - (0.0065 * (opt.alt - 0))) / 288), \
(9.80665 / (0.0065 * 287))) * 101.325
# Estimate air vapor pressure in kPa #######################################
res['at_vp'] = (0.61121 * math.exp((17.502 * opt.at_t) \
/ (240.97 + opt.at_t))) \
* (opt.at_h / 100)
# Extraterrestrial radiation in W/m2 #######################################
res['ETR'] = (opt.sc * res['sol_r']) \
* (math.cos(res['sol_z'] * (math.pi / 180)))
# Precipitable water in the atmosphere in mm ###############################
res['at_pw'] = ((0.14 * res['at_vp']) * opt.at_p) + 2.1
# Clearness index for direct beam radiation [unitless] #####################
res['CIDBR'] = 0.98 * (math.exp(((-0.00146 * opt.at_p) \
/ (opt.at_tc * (math.sin((90 - res['sol_z']) \
* (math.pi / 180))))) - (0.075 * (math.pow((res['at_pw'] \
/ (math.sin((90 - res['sol_z']) * (math.pi / 180)))),0.4)))))
# Transmissivity index for diffuse radiation [unitless] ####################
if (res['CIDBR'] > 0.15):
res['TIDR'] = 0.35 - (0.36 * res['CIDBR'])
else:
res['TIDR'] = 0.18 + (0.82 * res['CIDBR'])
# Model Estimated Shortwave Radiation (W/m2) ###############################
res['RSO'] = (res['CIDBR'] + res['TIDR']) * res['ETR']
# Estimate Theoretical Max. Power Output (Panel at nominal Efficiency) #####
res['pv_max'] = (res['RSO'] * opt.pv_a) / 100 * opt.pv_e
# Estimate conversion loss due to module temperature #######################
res['pv_l'] = (opt.pv_t-25 ) * opt.pv_tc
res['pv_lp'] = (res['pv_max'] / 100) * res['pv_l']
# Estimate conversion loss due to module age
res['pv_la'] = res['pv_max'] - (res['pv_max'] * opt.pv_ac)
# Estimate final System Power output
res['pv_out'] = res['pv_max'] - res['pv_la'] - res['pv_lp']
output (opt, res)
################################################################################
if __name__ == '__main__':
rc = main()
sys.exit (rc)