Skip to content

Commit

Permalink
Merge pull request #7 from NREL/development
Browse files Browse the repository at this point in the history
Pull from Development to address issues 2, 4 and 6
  • Loading branch information
cdeline committed Apr 8, 2018
2 parents eae845c + 8448500 commit bb4316e
Show file tree
Hide file tree
Showing 7 changed files with 9,138 additions and 107 deletions.
1 change: 1 addition & 0 deletions bifacialvf/__init__.py
Expand Up @@ -3,3 +3,4 @@
from vf import getSkyConfigurationFactors, trackingBFvaluescalculator, rowSpacing # helper functions
from sun import hrSolarPos, perezComp, solarPos, sunIncident # solar position and value
from loadVFresults import loadVFresults # utility for reading result files
from readepw import readepw
70 changes: 55 additions & 15 deletions bifacialvf/bifacialvf.py
Expand Up @@ -31,14 +31,43 @@
from vf import getSkyConfigurationFactors, trackingBFvaluescalculator, rowSpacing
from sun import hrSolarPos, perezComp, solarPos, sunIncident
import pandas as pd
from readepw import readepw



def simulate(TMYtoread, writefiletitle, beta = 0, sazm = 180, C = 0.5, D = None,
def simulate(TMYtoread=None, writefiletitle=None, 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):

tracking = False, backtrack = True, rtr = None, max_angle = 45):
'''
Description
-----------
Main function to run the bifacialvf routines
Parameters
----------
TMYtoread: TMY3 .csv weather file, which can be downloaded at http://rredc.nrel.gov/solar/old_data/nsrdb/1991-2005/tmy3/by_state_and_city.html
Also .epw weather files, which can be downloaded here: https://energyplus.net/weather and here: http://re.jrc.ec.europa.eu/pvg_tools/en/tools.html#TMY
writefiletitle: name of output file
beta: tilt angle in degrees. Not used for tracking
sazm: surface azimuth orientation in degrees east of north. For tracking this is the tracker axis orientation
C: normalized ground clearance. For trackers, this is the module height at zero tilt
D: normalized gap between PV module rows. For trackers use rtr
rtr: row-to-row normalized distance. = 1/GCR
transFactor: PV module transmission fraction. Default 1% (0.01)
cellRows: Number of points along the module chord to return irradiance values. Default 6 (1-up landscape module)
max_angle: 1-axis tracking maximum limits of rotation
tracking, backtrack: boolean to enable 1-axis tracking and pvlib backtracking algorithm, respectively
Returns
-------
none
'''



if tracking == True:
axis_tilt = 0 # algorithm only allows for zero north-south tilt with SAT
#max_angle = 45 # maximum tracker rotation
Expand All @@ -56,9 +85,21 @@ def simulate(TMYtoread, writefiletitle, beta = 0, sazm = 180, C = 0.5, D = 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') )
if writefiletitle == None:
writefiletitle = "data/Output/TEST.csv"

## Read TMY3 data and start loop ~
(myTMY3,meta)=pvlib.tmy.readtmy3(TMYtoread)
if TMYtoread is None: # if no file passed in, the readtmy3 graphical file picker will open.
(myTMY3,meta)=pvlib.tmy.readtmy3(TMYtoread)
elif TMYtoread.endswith('.csv') :
(myTMY3,meta)=pvlib.tmy.readtmy3(TMYtoread)
elif TMYtoread.endswith('.epw') :
(myTMY3,meta) = readepw(TMYtoread)
# rename different field parameters to match DNI, DHI, DryBulb, Wspd
myTMY3.rename(columns={'Direct normal radiation in Wh/m2':'DNI','Diffuse horizontal radiation in Wh/m2':'DHI','Dry bulb temperature in C':'DryBulb','Wind speed in m/s':'Wspd'}, inplace=True)
else:
raise Exception('Incorrect extension for TMYtoread. Either .csv (TMY3) .epw or None')

#myAxisTitles=myTMY3.axes
noRows, noCols = myTMY3.shape
lat = meta['latitude']; lng = meta['longitude']; tz = meta['TZ']
Expand All @@ -85,7 +126,7 @@ def simulate(TMYtoread, writefiletitle, beta = 0, sazm = 180, C = 0.5, D = None

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
[rearSkyConfigFactors, frontSkyConfigFactors] = 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
Expand All @@ -101,10 +142,10 @@ def simulate(TMYtoread, writefiletitle, beta = 0, sazm = 180, C = 0.5, D = None
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']
'PVfrontSurface(glass or ARglass)', 'PVbackSurface(glass or ARglass)',
'Albedo', 'Tracking']
outputheadervars=[lat, lng, tz, beta, sazm, C, rtr, rowType, transFactor, cellRows, PVfrontSurface,
PVbackSurface, offset, albedo, tracking]
PVbackSurface, albedo, tracking]


if tracking==True:
Expand Down Expand Up @@ -138,7 +179,7 @@ def simulate(TMYtoread, writefiletitle, beta = 0, sazm = 180, C = 0.5, D = None

sw.writerow(outputtitles)

## Loop through file
## Loop through file. TODO: replace this with for loop.
rl = 0

while (rl < noRows):
Expand Down Expand Up @@ -184,7 +225,6 @@ def simulate(TMYtoread, writefiletitle, beta = 0, sazm = 180, C = 0.5, D = None
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)
Expand All @@ -200,7 +240,7 @@ def simulate(TMYtoread, writefiletitle, beta = 0, sazm = 180, C = 0.5, D = None
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
[rearSkyConfigFactors, frontSkyConfigFactors] = getSkyConfigurationFactors(rowType, beta, C, D); ## Sky configuration factors are the same for all times, only based on geometry and row type



Expand Down Expand Up @@ -245,7 +285,7 @@ def simulate(TMYtoread, writefiletitle, beta = 0, sazm = 180, C = 0.5, D = None

# 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)
backGTI, aveGroundGHI = getBackSurfaceIrradiances(rowType, maxShadow, PVbackSurface, beta, sazm, dni, dhi, C, D, albedo, zen, azm, cellRows, pvBackSH, rearGroundGHI, frontGroundGHI, frontReflected, offset=0)

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
Expand Down Expand Up @@ -300,8 +340,8 @@ def simulate(TMYtoread, writefiletitle, beta = 0, sazm = 180, C = 0.5, D = None
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)
PVfrontSurface = "glass" # PVfrontSurface(glass or ARglass)
PVbackSurface = "glass" # PVbackSurface(glass or ARglass)
albedo = 0.62 # ground albedo


Expand Down

0 comments on commit bb4316e

Please sign in to comment.