Skip to content

Commit

Permalink
rename to demo.calculateResults1axis. Fix modelchains
Browse files Browse the repository at this point in the history
  • Loading branch information
cdeline committed May 21, 2024
1 parent 557146f commit 28e2d60
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 35 deletions.
48 changes: 17 additions & 31 deletions bifacial_radiance/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2986,7 +2986,7 @@ def analysis1axisground(self, trackerdict=None, singleindex=None, accuracy='low'
return trackerdict


def calculateResults(self, CECMod=None, glassglass=False, bifacialityfactor=None,
def calculateResults1axis(self, trackerdict=None, module=None,
CECMod2=None, agriPV=False):
'''
Loops through all results in trackerdict and calculates performance,
Expand All @@ -2996,17 +2996,10 @@ def calculateResults(self, CECMod=None, glassglass=False, bifacialityfactor=None
Parameters
----------
CECMod : Dict
Dictionary with CEC Module PArameters for the module selected. Must
contain at minimum alpha_sc, a_ref, I_L_ref, I_o_ref, R_sh_ref,
R_s, Adjust. If 'None' passed, a default module type is selected
glassglass : boolean, optional
If True, module packaging is set to glass-glass for thermal
coefficients for module temperature calculation. Else it is
assumes it is a glass-polymer package.
bifacialityfactor : float, optional
bifaciality factor to be used on calculations, range 0 to 1. If
not passed, it uses the module object's stored bifaciality factor.
module: ModuleObj from scene.module
It's best to set this in advance in the ModuleObj.
If passed in here, it overrides the value that may be set in the
trackerdict already.
CEcMod2 : Dict
Dictionary with CEC Module Parameters for a Monofacial module. If None,
same module as CECMod is used for the BGE calculations, but just
Expand All @@ -3030,7 +3023,8 @@ def calculateResults(self, CECMod=None, glassglass=False, bifacialityfactor=None
from bifacial_radiance import performance
import pandas as pd

trackerdict = self.trackerdict
if trackerdict is None:
trackerdict = self.trackerdict

keys = list(trackerdict.keys())

Expand Down Expand Up @@ -3060,7 +3054,6 @@ def _printRow(analysisobj, key):
# loop over module and row values in 'Results'
keys_all = []
self.CompiledResults = pd.DataFrame(None)
bifi_factor_internal = None

if not self.cumulativesky:

Expand All @@ -3074,23 +3067,15 @@ def _printRow(analysisobj, key):
try:
for analysis in trackerdict[key]['AnalysisObj']: # loop over multiple row & module in trackerDict['AnalysisObj']
keys_all.append(key)
# Search for module object bifaciality
if (bifacialityfactor is None) & (bifi_factor_internal is None):
try:
bifi_factor_internal = trackerdict[key]['scenes'][analysis.sceneNum].module.bifi
print("Bifaciality factor of module stored is ", bifi_factor_internal)
except(TypeError, KeyError):
bifi_factor_internal = 1
elif (bifacialityfactor is None) :
try:
bifi_factor_internal = trackerdict[key]['scenes'][analysis.sceneNum].module.bifi
except(TypeError, KeyError):
bifi_factor_internal = 1
# Search for module object
if module is None:
module_local = trackerdict[key]['scenes'][analysis.sceneNum].module
else:
bifi_factor_internal = bifacialityfactor
power_data = analysis.calc_performance(meteo_data=meteo_data, CECMod=CECMod,
cumulativesky=self.cumulativesky, glassglass=glassglass,
bifacialityfactor=bifi_factor_internal, CECMod2=CECMod2,
module_local = None
power_data = analysis.calc_performance(meteo_data=meteo_data,
module=module_local,
cumulativesky=self.cumulativesky,
CECMod2=CECMod2,
agriPV=agriPV)
self.CompiledResults = pd.concat([self.CompiledResults,
_printRow(analysis, key)], ignore_index=True)
Expand Down Expand Up @@ -5443,7 +5428,8 @@ def calc_performance(self, meteo_data, cumulativesky, module,
if cumulativesky is False:

# If CECMod details aren't passed, use a default Prism Solar value.
if type(module) is not ModuleObj:
#if type(module) is not ModuleObj: # not working for some reason..
if str(type(module)) != "<class 'bifacial_radiance.module.ModuleObj'>":
raise TypeError('ModuleObj input required for AnalysisObj.calc_performance. '+\
f'type passed: {type(module)}')

Expand Down
11 changes: 8 additions & 3 deletions bifacial_radiance/modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def runModelChain(simulationParamsDict, sceneParamsDict, timeControlParamsDict=N
import bifacial_radiance
import os
import numpy as np
import pandas as pd

print("\nNew bifacial_radiance simulation starting. ")
print("Version: ", bifacial_radiance.__version__)
Expand Down Expand Up @@ -147,6 +148,10 @@ def runModelChain(simulationParamsDict, sceneParamsDict, timeControlParamsDict=N
omegaParams=omegaParamsDict,
cellModule=cellModule, **kwargs)

# module CEC params
if CECModParamsDict:
module.addCEC(pd.DataFrame(CECModParamsDict, index=[0]))

customObject = None

if "customObject" in sceneParamsDict:
Expand Down Expand Up @@ -236,14 +241,14 @@ def runModelChain(simulationParamsDict, sceneParamsDict, timeControlParamsDict=N

print("\n--> Calculating Performance values")

"""
#CEC Module
import pandas as pd

if CECModParamsDict:
CECMod = pd.DataFrame(CECModParamsDict, index=[0])
else:
CECMod = None
demo.calculateResults(CECMod = CECMod)
"""
demo.calculateResults1axis()
demo.exportTrackerDict(savefile=os.path.join('results','Final_Results.csv'),reindex=False)

# Save example image files
Expand Down
2 changes: 1 addition & 1 deletion bifacial_radiance/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def __init__(self, name=None, x=None, y=None, z=None, bifi=1, modulefile=None,

self.keys = ['x', 'y', 'z', 'modulematerial', 'scenex','sceney',
'scenez','numpanels','bifi','text','modulefile', 'glass',
'offsetfromaxis','xgap','ygap','zgap' ]
'offsetfromaxis','xgap','ygap','zgap', 'CECMod' ]

#replace whitespace with underlines. what about \n and other weird characters?
# TODO: Address above comment?
Expand Down

0 comments on commit 28e2d60

Please sign in to comment.