-
Notifications
You must be signed in to change notification settings - Fork 17
/
bifacialvf.py
334 lines (260 loc) · 19.1 KB
/
bifacialvf.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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# This program calculates irradiances on the front and back surfaces of bifacial PV modules.
# Key dimensions and nomenclature:
# beta = PV module tilt angle from horizontal, in degrees
# sazm = PV module surface azimuth from north, in degrees
# 1.0 = normalized PV module/panel slant height
# C = ground clearance of PV module, in PV module/panel slant heights
# D = distance between rows, from rear of module to front of module in next row, in PV module/panel slant heights
# h = sin(beta), vertical PV module dimension, in PV module/panel slant heights
# x1 = cos(beta), horizontal PV module dimension, in PV module/panel slant heights
# rtr = x1 + D, row-to-row distance, from front of module to front of module in next row, in PV module/panel slant heights
# cellRows = number of horzontal rows of cells in a PV module/panel
# PVfrontSurface = PV module front surface material type, either "glass" or "ARglass"
# PVbackSurface = PV module back surfac ematerial type, either "glass" or "ARglass"
#
# Program flow consists of:
# a. Calculate irradiance distribution on ground
# b. Calculate AOI corrected irradiance on front of PV module, and irradiance reflected from front of PV module
# c. Calculate irradiance on back of PV module
from __future__ import division, print_function # ensure python3 compatible division and printing
import math
import csv
import pvlib
import os
from vf import getBackSurfaceIrradiances, getFrontSurfaceIrradiances, getGroundShadeFactors
from vf import getSkyConfigurationFactors, trackingBFvaluescalculator, rowSpacing
from sun import hrSolarPos, perezComp, solarPos, sunIncident
import pandas as pd
def simulate(TMYtoread, writefiletitle, beta = 0, sazm = 180, C = 0.5, D = None,
rowType = 'interior', transFactor = 0.01, cellRows = 6,
PVfrontSurface = 'glass', PVbackSurface = 'glass', albedo = 0.2,
tracking = False, backtrack = True, rtr = None, Cv = None, offset = 0, max_angle = 45):
if tracking == True:
axis_tilt = 0 # algorithm only allows for zero north-south tilt with SAT
#max_angle = 45 # maximum tracker rotation
axis_azimuth=sazm # axis_azimuth is degrees east of North
beta = 0 # start with tracker tilt = 0
hub_height = C # Ground clearance at tilt = 0. C >= 0.5
if hub_height < 0.5:
print('Warning: tracker hub height C < 0.5 may result in ground clearance errors')
if (D == None) & (rtr != None):
D = rtr - math.cos(beta / 180.0 * math.pi)
elif (rtr == None) & (D != None):
rtr = D + math.cos(beta / 180.0 * math.pi)
elif (D == None) & (rtr == None):
raise Exception('No row distance specified in either D or rtr')
else:
print('Warning: Gap D and rtr passed in. Using ' + ('rtr' if tracking else 'D') )
## Read TMY3 data and start loop ~
(myTMY3,meta)=pvlib.tmy.readtmy3(TMYtoread)
#myAxisTitles=myTMY3.axes
noRows, noCols = myTMY3.shape
lat = meta['latitude']; lng = meta['longitude']; tz = meta['TZ']
name = meta['Name']
## infer the data frequency in minutes
dataInterval = (myTMY3.index[1]-myTMY3.index[0]).total_seconds()/60
## Distance between rows for no shading on Dec 21 at 9 am
print( " ")
print( "********* ")
print( "Running Simulation for TMY3: ", TMYtoread)
print( "Location: ", name)
print( "Lat: ", lat, " Long: ", lng, " Tz ", tz)
print( "Parameters: beta: ", beta, " Sazm: ", sazm, " Height: ", C, " rtr separation: ", rtr, " Row type: ", rowType, " Albedo: ", albedo)
print( "Saving into", writefiletitle)
print( " ")
print( " ")
DD = rowSpacing(beta, sazm, lat, lng, tz, 9, 0.0); ## Distance between rows for no shading on Dec 21 at 9 am
print( "Distance between rows for no shading on Dec 21 at 9 am solar time = ", DD)
print( "Actual distance between rows = ", D )
print( " ")
if tracking==False:
## Sky configuration factors are the same for all times, only based on geometry and row type
[rearSkyConfigFactors, frontSkyConfigFactors, ffConfigFactors] = getSkyConfigurationFactors(rowType, beta, C, D); ## Sky configuration factors are the same for all times, only based on geometry and row type
## Create WriteFile and write labels at this time
#check that the save directory exists
if not os.path.exists(os.path.dirname(writefiletitle)):
os.makedirs(os.path.dirname(writefiletitle))
with open (writefiletitle,'w') as csvfile:
sw = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL, lineterminator='\n')
# Write Simulation Parameters (from setup file)
outputheader=['Latitude(deg)','Longitude(deg)', 'Time Zone','Tilt(deg)',
'PV Azimuth(deg)','GroundClearance(panel slope lengths)', 'Row-to-Row-Distance rtr', 'RowType(first interior last single)',
'TransmissionFactor(open area fraction)','CellRows(# hor rows in panel)',
'PVfrontSurface(glass or AR glass)', 'PVbackSurface(glass or AR glass)',
'CellOffsetFromBack(panel slope lengths)','Albedo', 'Tracking']
outputheadervars=[lat, lng, tz, beta, sazm, C, rtr, rowType, transFactor, cellRows, PVfrontSurface,
PVbackSurface, offset, albedo, tracking]
if tracking==True:
outputheader+=['Backtracking']
outputheadervars.append(backtrack)
sw.writerow(outputheader)
sw.writerow(outputheadervars)
# Write Results names"
allrowfronts=[]
allrowbacks=[]
for k in range(0, cellRows):
allrowfronts.append("No_"+str(k+1)+"_RowFrontGTI")
allrowbacks.append("No_"+str(k+1)+"_RowBackGTI")
outputtitles=['Year', 'Month', 'Day', 'Hour', 'Minute', 'DNI', 'DHI',
'decHRs', 'ghi', 'inc', 'zen', 'azm', 'pvFrontSH',
'aveFrontGroundGHI', 'GTIfrontBroadBand', 'pvBackSH',
'aveBackGroundGHI', 'GTIbackBroadBand', 'maxShadow', 'Tamb', 'Vwind']
outputtitles+=allrowfronts
outputtitles+=allrowbacks
if tracking == True:
print( " ***** IMPORTANT --> THIS SIMULATION Has Tracking Activated")
print( "Backtracking Option is set to: ", backtrack)
outputtitles+=['beta']
outputtitles+=['sazm']
outputtitles+=['height']
outputtitles+=['D']
sw.writerow(outputtitles)
## Loop through file
rl = 0
while (rl < noRows):
myTimestamp=myTMY3.index[rl]
year = myTimestamp.year
month = myTimestamp.month
day = myTimestamp.day
hour = myTimestamp.hour
minute = myTimestamp.minute
dni = myTMY3.DNI[rl]#get_value(rl,5,"False")
dhi = myTMY3.DHI[rl]#get_value(rl,8,"False")
Tamb=myTMY3.DryBulb[rl]#get_value(rl,29,"False")
Vwind=myTMY3.Wspd[rl]#get_value(rl,44,"False")
#
rl = rl+1 # increasing while count
azm = 9999.0; zen = 9999.0; elv = 9999.0;
if (dataInterval == 60):
azm, zen, elv, dec, sunrise, sunset, Eo, tst, suntime = hrSolarPos(year, month, day, hour, lat, lng, tz)
elif (dataInterval == 1 or dataInterval == 5 or dataInterval == 15):
azm, zen, elv, dec, sunrise, sunset, Eo, tst = solarPos(year, month, day, hour, minute - 0.5 * dataInterval, lat, lng, tz)
else :
print("ERROR: data interval not 1, 5, 15, or 60 minutes.");
#123 check abouve this for reading / printing functions
if (zen < 0.5 * math.pi): # If daylight hours
# a. CALCULATE THE IRRADIANCE DISTRIBUTION ON THE GROUND *********************************************************************************************
#double[] rearGroundGHI = new double[100], frontGroundGHI = new double[100]; ; # For global horizontal irradiance for each of 100 ground segments, to the rear and front of front of row edge
# Determine where on the ground the direct beam is shaded for a sun elevation and azimuth
#int[] rearGroundSH = new int[100], frontGroundSH = new int[100]; # Front and rear row-to-row spacing divided into 100 segments, (later becomes 1 if direct beam is shaded, 0 if not shaded)
#double pvFrontSH = 0.0, pvBackSH = 0.0, maxShadow; # Initialize fraction of PV module front and back surfaces that are shaded to zero (not shaded), and maximum shadow projected from front of row.
# TRACKING ROUTINE CALULATING GETSKYCONFIGURATION FACTORS
if tracking == True:
#solpos = pvlib.solarposition.get_solarposition(myTimestamp, lat, lng)
#aazi= solpos['azimuth']
#azen= solpos['zenith']
aazi = pd.Series([azm*180.0/math.pi], index =[myTimestamp])
azen = pd.Series([zen*180.0/math.pi], index =[myTimestamp])
gcr=1/rtr
trackingdata = pvlib.tracking.singleaxis(azen, aazi, axis_tilt, axis_azimuth, max_angle, backtrack, gcr)
## Sky configuration factors are not the same for all times, since the geometry is changing with the tracking.
beta=trackingdata['surface_tilt'][0] # Trackingdata tracker_theta
sazm = trackingdata['surface_azimuth'][0]
if math.isnan(beta):
beta=90
# Rotate system if past sun's zenith ~ #123 Check if system breaks withot doing this.
if beta<0:
#sazm = sazm+180 # Rotate detectors
beta = -beta;
[C, D] = trackingBFvaluescalculator(beta, hub_height, rtr)
[rearSkyConfigFactors, frontSkyConfigFactors, ffConfigFactors] = getSkyConfigurationFactors(rowType, beta, C, D); ## Sky configuration factors are the same for all times, only based on geometry and row type
rearGroundGHI=[]
frontGroundGHI=[]
pvFrontSH, pvBackSH, maxShadow, rearGroundSH, frontGroundSH = getGroundShadeFactors (rowType, beta, C, D, elv, azm, sazm)
# Sum the irradiance components for each of the ground segments, to the front and rear of the front of the PV row
#double iso_dif = 0.0, circ_dif = 0.0, horiz_dif = 0.0, grd_dif = 0.0, beam = 0.0; # For calling PerezComp to break diffuse into components for zero tilt (horizontal)
ghi, iso_dif, circ_dif, horiz_dif, grd_dif, beam = perezComp(dni, dhi, albedo, zen, 0.0, zen)
for k in range (0, 100):
rearGroundGHI.append(iso_dif * rearSkyConfigFactors[k]); # Add diffuse sky component viewed by ground
if (rearGroundSH[k] == 0):
rearGroundGHI[k] += beam + circ_dif; # Add beam and circumsolar component if not shaded
else:
rearGroundGHI[k] += (beam + circ_dif) * transFactor; # Add beam and circumsolar component transmitted thru module spacing if shaded
frontGroundGHI.append(iso_dif * frontSkyConfigFactors[k]); # Add diffuse sky component viewed by ground
if (frontGroundSH[k] == 0):
frontGroundGHI[k] += beam + circ_dif; # Add beam and circumsolar component if not shaded
else:
frontGroundGHI[k] += (beam + circ_dif) * transFactor; # Add beam and circumsolar component transmitted thru module spacing if shaded
# b. CALCULATE THE AOI CORRECTED IRRADIANCE ON THE FRONT OF THE PV MODULE, AND IRRADIANCE REFLECTED FROM FRONT OF PV MODULE ***************************
#double[] frontGTI = new double[cellRows], frontReflected = new double[cellRows];
#double aveGroundGHI = 0.0; # Average GHI on ground under PV array
aveGroundGHI, frontGTI, frontReflected = getFrontSurfaceIrradiances(rowType, maxShadow, PVfrontSurface, beta, sazm, dni, dhi, C, D, albedo, zen, azm, cellRows, pvFrontSH, frontGroundGHI)
#double inc, tiltr, sazmr;
inc, tiltr, sazmr = sunIncident(0, beta, sazm, 45.0, zen, azm) # For calling PerezComp to break diffuse into components for
save_inc=inc
gtiAllpc, iso_dif, circ_dif, horiz_dif, grd_dif, beam = perezComp(dni, dhi, albedo, inc, tiltr, zen) # Call to get components for the tilt
save_gtiAllpc=gtiAllpc
#sw.Write(strLine);
#sw.Write(",{0,6:0.00}", hour - 0.5 * dataInterval / 60.0 + minute / 60.0);
#sw.Write(",{0,6:0.0},{1,5:0.0},{2,5:0.0},{3,5:0.0},{4,4:0.00},{5,6:0.0},{6,6:0.0}",
#dni * Math.Cos(zen) + dhi, inc * 180.0 / Math.PI, zen * 180.0 / Math.PI, azm * 180.0 / Math.PI, pvFrontSH, aveGroundGHI, gtiAllpc);
# CALCULATE THE AOI CORRECTED IRRADIANCE ON THE BACK OF THE PV MODULE,
#double[] backGTI = new double[cellRows];
backGTI, aveGroundGHI = getBackSurfaceIrradiances(rowType, maxShadow, PVbackSurface, beta, sazm, dni, dhi, C, D, albedo, zen, azm, cellRows, pvBackSH, rearGroundGHI, frontGroundGHI, frontReflected, offset)
inc, tiltr, sazmr = sunIncident(0, 180.0-beta, sazm-180.0, 45.0, zen, azm) # For calling PerezComp to break diffuse into components for
gtiAllpc, iso_dif, circ_dif, horiz_dif, grd_dif, beam = perezComp(dni, dhi, albedo, inc, tiltr, zen) # Call to get components for the tilt
## Write output
decHRs = hour - 0.5 * dataInterval / 60.0 + minute / 60.0
ghi_calc = dni * math.cos(zen) + dhi
incd = save_inc * 180.0 / math.pi
zend = zen * 180.0 / math.pi
azmd = azm * 180.0 / math.pi
outputvalues=[year, month, day, hour, minute, dni, dhi, decHRs,
ghi_calc, incd, zend, azmd, pvFrontSH, aveGroundGHI,
save_gtiAllpc, pvBackSH, aveGroundGHI,
gtiAllpc, maxShadow, Tamb, Vwind]
frontGTIrow=[]
backGTIrow=[]
for k in range(0, cellRows):
frontGTIrow.append(frontGTI[k])
backGTIrow.append(backGTI[k])
outputvalues+=frontGTIrow
outputvalues+=backGTIrow
if tracking==True:
outputvalues.append(beta)
outputvalues.append(sazm)
outputvalues.append(C)
outputvalues.append(D)
sw.writerow(outputvalues)
# End of daylight if loop
#strLine = sr.ReadLine(); # Read next line of data
# End of while strLine != null loop
print( "Finished")
return;
if __name__ == "__main__":
#import time
#start_time = time.time()
beta = 10 # PV tilt (deg)
sazm = 180 # PV Azimuth(deg) or tracker axis direction
C = 1 # GroundClearance(panel slope lengths). For tracking this is tilt = 0 hub height
D = 0.51519 # DistanceBetweenRows(panel slope lengths)
rowType = "interior" # RowType(first interior last single)
transFactor = 0.013 # TransmissionFactor(open area fraction)
cellRows = 6 # CellRows(# hor rows in panel) <--> THIS ASSUMES LANDSCAPE ORIENTATION
PVfrontSurface = "glass" # PVfrontSurface(glass or AR glass)
PVbackSurface = "glass" # PVbackSurface(glass or AR glass)
albedo = 0.62 # ground albedo
# Tracking instructions
tracking=False
backtrack=True
rtr = 1.5 # row to row spacing in normalized panel lengths.
TMYtoread="data/724010TYA.csv" # VA Richmond
writefiletitle="data/Output/TEST.csv"
simulate(TMYtoread, writefiletitle, beta, sazm, C, rtr= rtr,
rowType= rowType, transFactor= transFactor, cellRows= cellRows,
PVfrontSurface= PVfrontSurface, PVbackSurface= PVbackSurface,
albedo= albedo, tracking= tracking, backtrack= backtrack)
#Load the results from the resultfile
from loadVFresults import loadVFresults
(data, metadata) = loadVFresults(writefiletitle)
#print data.keys()
# calculate average front and back global tilted irradiance across the module chord
data['GTIFrontavg'] = data[['No_1_RowFrontGTI', 'No_2_RowFrontGTI','No_3_RowFrontGTI','No_4_RowFrontGTI','No_5_RowFrontGTI','No_6_RowFrontGTI']].mean(axis=1)
data['GTIBackavg'] = data[['No_1_RowBackGTI', 'No_2_RowBackGTI','No_3_RowBackGTI','No_4_RowBackGTI','No_5_RowBackGTI','No_6_RowBackGTI']].mean(axis=1)
# Print the annual bifacial ratio.
frontIrrSum = data['GTIFrontavg'].sum()
backIrrSum = data['GTIBackavg'].sum()
print('The bifacial ratio for ground clearance {} and rtr spacing {} is: {:.1f}%'.format(C,rtr,backIrrSum/frontIrrSum*100))
#print("--- %s seconds ---" % (time.time() - start_time))