Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/NREL/main' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
cdeline committed Aug 21, 2024
2 parents 901e07b + d327014 commit f03cca8
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 32 deletions.
16 changes: 8 additions & 8 deletions bifacial_radiance/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3642,11 +3642,11 @@ def _makeSceneNxR(self, modulename=None, sceneDict=None, radname=None):
f'{nMods}modsx{nRows}rows_origin{originx},{originy}.rad' )

if self.hpc:
text += f'{os.path.join(os.getcwd(), self.modulefile)}'
radfile = os.path.join(os.getcwd(), 'objects', filename)
text += f'"{os.path.join(os.getcwd(), self.modulefile)}"'
radfile = os.path.join(os.getcwd(), 'objects', filename)
else:
text += os.path.join(self.modulefile)
radfile = os.path.join('objects',filename )
text += f'"{os.path.join(self.modulefile)}"'
radfile = os.path.join('objects',filename)

# py2 and 3 compatible: binary write, encode text first
with open(radfile, 'wb') as f:
Expand Down Expand Up @@ -3998,10 +3998,10 @@ def __init__(self, tmydata, metadata, label = 'right'):
sunup['minutedelta']= int(interval.seconds/2/60) # default sun angle 30 minutes before timestamp
# vector update of minutedelta at sunrise
sunrisemask = sunup.index.hour-1==sunup['sunrise'].dt.hour
sunup['minutedelta'].mask(sunrisemask,np.floor((60-(sunup['sunrise'].dt.minute))/2),inplace=True)
sunup['minutedelta'] = sunup['minutedelta'].mask(sunrisemask,np.floor((60-(sunup['sunrise'].dt.minute))/2))
# vector update of minutedelta at sunset
sunsetmask = sunup.index.hour-1==sunup['sunset'].dt.hour
sunup['minutedelta'].mask(sunsetmask,np.floor((60-(sunup['sunset'].dt.minute))/2),inplace=True)
sunup['minutedelta'] = sunup['minutedelta'].mask(sunsetmask,np.floor((60-(sunup['sunset'].dt.minute))/2))
# save corrected timestamp
sunup['corrected_timestamp'] = sunup.index-pd.to_timedelta(sunup['minutedelta'], unit='m')

Expand All @@ -4012,10 +4012,10 @@ def __init__(self, tmydata, metadata, label = 'right'):
sunup['minutedelta']= int(interval.seconds/2/60) # default sun angle 30 minutes after timestamp
# vector update of minutedelta at sunrise
sunrisemask = sunup.index.hour==sunup['sunrise'].dt.hour
sunup['minutedelta'].mask(sunrisemask,np.ceil((60+sunup['sunrise'].dt.minute)/2),inplace=True)
sunup['minutedelta'] = sunup['minutedelta'].mask(sunrisemask,np.ceil((60+sunup['sunrise'].dt.minute)/2))
# vector update of minutedelta at sunset
sunsetmask = sunup.index.hour==sunup['sunset'].dt.hour
sunup['minutedelta'].mask(sunsetmask,np.ceil((60+sunup['sunset'].dt.minute)/2),inplace=True)
sunup['minutedelta'] = sunup['minutedelta'].mask(sunsetmask,np.ceil((60+sunup['sunset'].dt.minute)/2))
# save corrected timestamp
sunup['corrected_timestamp'] = sunup.index+pd.to_timedelta(sunup['minutedelta'], unit='m')
else: raise ValueError('Error: invalid weather label passed. Valid inputs: right, left or center')
Expand Down
5 changes: 4 additions & 1 deletion bifacial_radiance/mismatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,10 @@ def mismatch_fit2(data):
fit2 = 0.142*mad + 0.032*mad2

if fit2.__len__() == 1:
fit2 = float(fit2)
if isinstance(fit2, pd.Series):
fit2 = float(fit2.iloc[0])
else:
fit2 = float(fit2)

return fit2

Expand Down
33 changes: 15 additions & 18 deletions bifacial_radiance/performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def calculatePerformance(effective_irradiance, CECMod, temp_air=None,
effective_irradiance : numeric
Dataframe or single value. Must be same length as temp_cell
CECMod : Dict
Dictionary with CEC Module PArameters for the module selected. Must
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
temp_air : numeric
Expand Down Expand Up @@ -51,23 +51,20 @@ def calculatePerformance(effective_irradiance, CECMod, temp_air=None,
if temp_cell is None:
if temp_air is None:
temp_air = 25 # STC

temp_cell = pvlib.temperature.sapm_cell(effective_irradiance, temp_air,
wind_speed,
temp_model_params['a'],
temp_model_params['b'],
temp_model_params['deltaT'])

if isinstance(CECMod, pd.DataFrame):
CECMod.to_pickle("CECMod.pkl")
if len(CECMod) == 1:
CECMod1 = CECMod.iloc[0]
else:
print("More than one Module passed. Error, using 1st one")
CECMod1 = CECMod.iloc[0]
else:
CECMod1 = CECMod

temp_cell = pvlib.temperature.sapm_cell(effective_irradiance, temp_air, wind_speed,
temp_model_params['a'], temp_model_params['b'], temp_model_params['deltaT'])

if isinstance(CECMod, pd.DataFrame):
#CECMod.to_pickle("CECMod.pkl")
if len(CECMod) == 1:
CECMod1 = CECMod.iloc[0]
else:
print("More than one Module passed. Error, using 1st one")
CECMod1 = CECMod.iloc[0]
else:
CECMod1 = CECMod

IL, I0, Rs, Rsh, nNsVth = pvlib.pvsystem.calcparams_cec(
effective_irradiance=effective_irradiance,
temp_cell=temp_cell,
Expand All @@ -79,7 +76,7 @@ def calculatePerformance(effective_irradiance, CECMod, temp_air=None,
R_s=float(CECMod1.R_s),
Adjust=float(CECMod1.Adjust)
)

IVcurve_info = pvlib.pvsystem.singlediode(
photocurrent=IL,
saturation_current=I0,
Expand Down
10 changes: 5 additions & 5 deletions tests/test_bifacial_radiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def test_Radiance_1axis_gendaylit_modelchains():
#V 0.2.5 fixed the gcr passed to set1axis. (since gcr was not being passd to set1axis, gcr was default 0.33 default).
assert(demo2.CompiledResults.Gfront_mean[0] == pytest.approx(205.0, 0.01) ) # was 214 in v0.2.3 # was 205 in early v0.2.4
assert(demo2.CompiledResults.Grear_mean[0] == pytest.approx(43.0, 0.1) )
assert demo2.trackerdict['2001-01-01_1100']['scenes'][0].text.__len__() == 132
assert demo2.trackerdict['2001-01-01_1100']['scenes'][0].text.__len__() == 134
assert demo2.trackerdict['2001-01-01_1100']['scenes'][0].text[23:28] == " 2.0 "
demo2.exportTrackerDict(savefile = 'results\exportedTrackerDict.csv', reindex=True)
# Run groundscan
Expand Down Expand Up @@ -244,7 +244,7 @@ def test_1axis_gencumSky():
assert trackerdict[-5.0]['scenes'].__len__() == 4
fname = trackerdict[-5.0]['scenes'][3].radfiles
with open(fname, 'r') as f:
assert f.readline().__len__() == 131
assert f.readline().__len__() == 133
assert f.readline()[-14:] == 'whiteblock.rad'

assert trackerdict[-5.0]['scenes'][3].radfiles[0:7] == 'objects'
Expand Down Expand Up @@ -298,7 +298,7 @@ def test_SceneObj_makeSceneNxR_lowtilt():
'sx_xinc': 0.0, 'sx_yinc':0.0, 'sx_zinc':0.0})
# zstart was 0.01 and zinc was 0 in v0.2.2
#assert scene.text == '!xform -rz -90 -t -0.795 0.475 0 -rx 10 -t 0 0 0.2 -a 20 -t 1.6 0 0 -a 7 -t 0 1.5 0 -i 1 -t -15.9 -4.5 0 -rz 0 objects\\simple_panel.rad'
assert scene.text[0:116] == '!xform -rx 10 -t 0 0 0.2824828843917919 -a 20 -t 1.6 0 0 -a 7 -t 0 1.5 0 -i 1 -t -14.4 -4.5 0 -rz 0 -t 0 0 0 objects' #linux has different directory structure and will error here.
assert scene.text[0:117] == '!xform -rx 10 -t 0 0 0.2824828843917919 -a 20 -t 1.6 0 0 -a 7 -t 0 1.5 0 -i 1 -t -14.4 -4.5 0 -rz 0 -t 0 0 0 "objects' #linux has different directory structure and will error here.

def test_SceneObj_makeSceneNxR_hightilt():
# test _makeSceneNxR(tilt, height, pitch, orientation = None, azimuth = 180, nMods = 20, nRows = 7, radname = None)
Expand Down Expand Up @@ -342,7 +342,7 @@ def test_SceneObj_makeSceneNxR_hightilt():
'zinc': 0.08609923976848174, 'zstart': 0.28567662150674106,
'sx_xinc': 0.0, 'sx_yinc':0.0, 'sx_zinc':0.0})
#assert scene.text == '!xform -rz -90 -t -0.795 0.475 0 -rx 65 -t 0 0 0.2 -a 20 -t 1.6 0 0 -a 7 -t 0 1.5 0 -i 1 -t -15.9 -4.5 0 -rz 91 objects\\simple_panel.rad'
assert scene.text[0:117] == '!xform -rx 65 -t 0 0 0.6304961988424087 -a 20 -t 1.6 0 0 -a 7 -t 0 1.5 0 -i 1 -t -14.4 -4.5 0 -rz 91 -t 0 0 0 objects'
assert scene.text[0:118] == '!xform -rx 65 -t 0 0 0.6304961988424087 -a 20 -t 1.6 0 0 -a 7 -t 0 1.5 0 -i 1 -t -14.4 -4.5 0 -rz 91 -t 0 0 0 "objects'



Expand Down Expand Up @@ -659,7 +659,7 @@ def test_customObj():
scene.appendtoScene(customObject=customObject, text='-t 1 1 0')

with open(scene.radfiles[0], 'r') as f:
assert f.readline().__len__() == 110
assert f.readline().__len__() == 112
assert f.readline()[0:26] == '!xform -rx 0 -rz 0 objects'
assert f.readline()[0:29] == '!xform -rx 0 -t 1 1 0 objects'

Expand Down
7 changes: 7 additions & 0 deletions tests/test_performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ def test_calculatePerformance():
p_mp_tamb = bifacial_radiance.performance.calculatePerformance(s1, CECMod=CECMod,
temp_air=s3, wind_speed=1, glassglass=True)
assert p_mp_tamb[0] == pytest.approx(190.4431, abs=.0001)
# test passing CECMod as a DF

p_mp_celltemp2 = bifacial_radiance.performance.calculatePerformance(s1, pd.DataFrame([CECMod]),
temp_cell=s2)
p_mp_celltemp3 = bifacial_radiance.performance.calculatePerformance(s1, pd.DataFrame([CECMod, CECMod]),
temp_cell=s2)
assert p_mp_celltemp3.all()==p_mp_celltemp2.all()==p_mp_celltemp.all()

def test_MBD():
from bifacial_radiance import performance
Expand Down

0 comments on commit f03cca8

Please sign in to comment.