Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
#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])
scalingfactor_all.append(0)
dni_scaled_all.append(0)
dhi_scaled_all.append(0)
timestamp_all.append(0)
poa2_all.append(0)
else:
times_loc= timestamps_all[rl].replace(tzinfo=pytz.timezone('US/Mountain'))
solpos = pvlib.solarposition.get_solarposition(times_loc, lat, lng)
AM=MYLOC.get_airmass(times_loc, solpos, model='kastenyoung1989')
aazir=math.radians(float(solpos['azimuth'])); azenr=math.radians(float(solpos['apparent_zenith']))
irradiance=pvlib.irradiance.liujordan(float(solpos['apparent_zenith']), transmittance, float(AM['airmass_relative']), pressure=101325.0, dni_extra=1367.0)
dni=float(irradiance['dni']); dhi=float(irradiance['dhi']); ghi=float(irradiance['ghi'])
# pvDAQ sensor 1429 is located in SNL at a tilt of 35 deg.:
inc, tiltr, sazmr = sunIncident(0, poa_tilt, poa_sazm, 180.0, azenr, aazir) # For calling PerezComp to break diffuse into components for
poa, iso_dif, circ_dif, horiz_dif, grd_dif, beam = perezComp(dni, dhi, albedo, inc, tiltr, azenr) # Call to get components for the tilt
# Calculate scaling factor
scalingfactor = 0
if poa > 0:
scalingfactor = float(POA_Measured_all[rl])/((poa)*0.001)
if scalingfactor > 1.3:
scalingfactor = 1.3
#Sanity Check
dni_scaled=dni*scalingfactor; dhi_scaled=dhi*scalingfactor
poa2, iso_dif2, circ_dif2, horiz_dif2, grd_dif2, beam2 = perezComp(dni_scaled, dhi_scaled, albedo, inc, tiltr, azenr) # Call to get components for the tilt
# Save params
scalingfactor_all.append(scalingfactor)
dni_scaled_all.append(dni_scaled)
dhi_scaled_all.append(dhi_scaled)
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
#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])
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
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
dni=float(irradiance['dni']); dhi=float(irradiance['dhi']); ghi=float(irradiance['ghi'])
# pvDAQ sensor 1429 is located in SNL at a tilt of 35 deg.:
inc, tiltr, sazmr = sunIncident(0, poa_tilt, poa_sazm, 180.0, azenr, aazir) # For calling PerezComp to break diffuse into components for
poa, iso_dif, circ_dif, horiz_dif, grd_dif, beam = perezComp(dni, dhi, albedo, inc, tiltr, azenr) # Call to get components for the tilt
# Calculate scaling factor
scalingfactor = 0
if poa > 0:
scalingfactor = float(POA_Measured_all[rl])/((poa)*0.001)
if scalingfactor > 1.3:
scalingfactor = 1.3
#Sanity Check
dni_scaled=dni*scalingfactor; dhi_scaled=dhi*scalingfactor
poa2, iso_dif2, circ_dif2, horiz_dif2, grd_dif2, beam2 = perezComp(dni_scaled, dhi_scaled, albedo, inc, tiltr, azenr) # Call to get components for the tilt
# Save params
scalingfactor_all.append(scalingfactor)
dni_scaled_all.append(dni_scaled)
dhi_scaled_all.append(dhi_scaled)
poa2_all.append(poa2)
timestamp_all.append(times_loc)
#Append to pvDaq.row
IRRAD = ({'Direct': dni_scaled_all, 'Diffuse': dhi_scaled_all, 'POA_Calculated': poa2_all, 'ScalingFactor': scalingfactor_all})
IRRAD = pd.DataFrame.from_records(IRRAD, index=timestamps_all)
IRRAD = IRRAD.fillna(0)
return IRRAD;