Skip to content

Commit

Permalink
Gencumulativesky tracking bugfix - half of zero tilt data had been ne…
Browse files Browse the repository at this point in the history
…glected.
  • Loading branch information
cdeline committed Oct 10, 2024
1 parent c5bb3e5 commit 553b32c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions bifacial_radiance/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,13 +794,13 @@ def boolConvert(d):
try: cellModuleDict
except: cellModuleDict = None

#returnParams = Params(simulationParamsDict, sceneParamsDict, timeControlParamsDict, moduleParamsDict, trackingParamsDict, torquetubeParamsDict, analysisParamsDict, cellModuleDict)
#return returnParams
# end readconfigurationinputfile
return (simulationParamsDict, sceneParamsDict, timeControlParamsDict,
moduleParamsDict, trackingParamsDict, torquetubeParamsDict,
analysisParamsDict, cellModuleDict, frameParamsDict, omegaParamsDict)



def savedictionariestoConfigurationIniFile(simulationParamsDict, sceneParamsDict,
timeControlParamsDict=None, moduleParamsDict=None,
trackingParamsDict=None, torquetubeParamsDict=None,
Expand Down
21 changes: 12 additions & 9 deletions bifacial_radiance/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def _subhourlydatatoGencumskyformat(gencumskydata, label='right'):
try:
gencumskydata = gencumskydata.resample('60min', closed='right', label='right').mean()
except TypeError: # Pandas 2.0 error
gencumskydata = gencumskydata.resample('60min', closed='right', label='right').mean(numeric_only=True)
gencumskydata = gencumskydata.resample('60min', closed='right', label='right').mean(numeric_only=True)

if label == 'left': #switch from left to right labeled by adding an hour
gencumskydata.index = gencumskydata.index + pd.to_timedelta('1H')
Expand All @@ -283,8 +283,8 @@ def _subhourlydatatoGencumskyformat(gencumskydata, label='right'):
tzinfo = gencumskydata.index.tzinfo
padstart = pd.to_datetime('%s-%s-%s %s:%s' % (gencumskydata.index.year[0],1,1,1,0 ) ).tz_localize(tzinfo)
padend = pd.to_datetime('%s-%s-%s %s:%s' % (gencumskydata.index.year[0]+1,1,1,0,0) ).tz_localize(tzinfo)
gencumskydata.iloc[0] = 0 # set first datapt to zero to forward fill w zeros
gencumskydata.iloc[-1] = 0 # set last datapt to zero to forward fill w zeros
#gencumskydata.iloc[0] = 0 # set first datapt to zero to forward fill w zeros
#gencumskydata.iloc[-1] = 0 # set last datapt to zero to forward fill w zeros
# check if index exists. I'm sure there is a way to do this backwards.
if any(gencumskydata.index.isin([padstart])):
print("Data starts on Jan. 01")
Expand Down Expand Up @@ -1142,7 +1142,8 @@ def _saveTempTMY(self, tmydata, filename=None, starttime=None, endtime=None,
if gencumskydata is not None:
csvfile = os.path.join('EPWs', filename)
print('Saving file {}, # points: {}'.format(csvfile, gencumskydata.__len__()))
gencumskydata.to_csv(csvfile, index=False, header=False, sep=' ', columns=['GHI','DHI'])
gencumskydata.to_csv(csvfile, index=False, header=False, sep=' ',
columns=['GHI','DHI'], float_format='%i')
self.gencumsky_metfile = csvfile

if gencumdict is not None:
Expand All @@ -1152,7 +1153,8 @@ def _saveTempTMY(self, tmydata, filename=None, starttime=None, endtime=None,
newfilename = filename.split('.')[0]+'_year_'+str(ii)+'.csv'
csvfile = os.path.join('EPWs', newfilename)
print('Saving file {}, # points: {}'.format(csvfile, gencumskydata.__len__()))
gencumskydata.to_csv(csvfile, index=False, header=False, sep=' ', columns=['GHI','DHI'])
gencumskydata.to_csv(csvfile, index=False, header=False, sep=' ',
columns=['GHI','DHI'], float_format='%i')
self.gencumsky_metfile.append(csvfile)

return tmydata
Expand Down Expand Up @@ -3529,7 +3531,7 @@ def _getTrackingAngles(self, azimuth=180, limit_angle=45,
def _roundArbitrary(x, base=angledelta):
# round to nearest 'base' value.
# mask NaN's to avoid rounding error message
return base * (x/float(base)).round()
return base * (x/float(base)).round() + 0 #remove negative zeros

if angledelta == 0:
raise ZeroDivisionError('Angledelta = 0. Use None instead')
Expand Down Expand Up @@ -3600,8 +3602,8 @@ def _makeTrackerCSV(self, theta_list, trackingdata):
else:
# mask out irradiance at this time, since it
# belongs to a different bin
ghi_temp.append(0.0)
dhi_temp.append(0.0)
ghi_temp.append(0)
dhi_temp.append(0)
# save in 2-column GHI,DHI format for gencumulativesky -G
savedata = pd.DataFrame({'GHI':ghi_temp, 'DHI':dhi_temp},
index = self.datetime).tz_localize(None)
Expand All @@ -3615,7 +3617,8 @@ def _makeTrackerCSV(self, theta_list, trackingdata):
index=False,
header=False,
sep=' ',
columns=['GHI','DHI'])
columns=['GHI','DHI'],
float_format='%i')


return trackerdict
Expand Down

0 comments on commit 553b32c

Please sign in to comment.