From 28e2d6008ecae5ab757efebc4a92d1a2ab76f345 Mon Sep 17 00:00:00 2001 From: cdeline Date: Tue, 21 May 2024 17:27:25 -0600 Subject: [PATCH] rename to demo.calculateResults1axis. Fix modelchains --- bifacial_radiance/main.py | 48 ++++++++++++--------------------- bifacial_radiance/modelchain.py | 11 +++++--- bifacial_radiance/module.py | 2 +- 3 files changed, 26 insertions(+), 35 deletions(-) diff --git a/bifacial_radiance/main.py b/bifacial_radiance/main.py index bb3afe29..e06f3ec5 100644 --- a/bifacial_radiance/main.py +++ b/bifacial_radiance/main.py @@ -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, @@ -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 @@ -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()) @@ -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: @@ -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) @@ -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)) != "": raise TypeError('ModuleObj input required for AnalysisObj.calc_performance. '+\ f'type passed: {type(module)}') diff --git a/bifacial_radiance/modelchain.py b/bifacial_radiance/modelchain.py index 36fbc12f..3e5e1300 100644 --- a/bifacial_radiance/modelchain.py +++ b/bifacial_radiance/modelchain.py @@ -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__) @@ -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: @@ -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 diff --git a/bifacial_radiance/module.py b/bifacial_radiance/module.py index 3a341083..c91568bc 100644 --- a/bifacial_radiance/module.py +++ b/bifacial_radiance/module.py @@ -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?