Skip to content

Commit d8988c6

Browse files
committed
tests
1 parent c674f1b commit d8988c6

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

pvlib/pvarray.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,11 @@ def batzelis(effective_irradiance, temp_cell,
474474
delT = temp_cell - (t0 - 273.15)
475475
lamT = (temp_cell + 273.15) / t0
476476
g = effective_irradiance / 1000
477-
lnG = np.log(g)
477+
# for zero/negative irradiance, use lnG=large negative number so that
478+
# computed voltages are negative and then clipped to zero
479+
with np.errstate(divide='ignore'): # needed for pandas for some reason
480+
lnG = np.log(g, out=np.full_like(g, -9e9), where=g>0)
481+
lnG = np.where(np.isfinite(g), lnG, np.nan) # also preserve nans
478482

479483
# Eq 9-10
480484
del0 = (1 - beta_voc * t0) / (50.1 - alpha_sc * t0)
@@ -497,6 +501,10 @@ def batzelis(effective_irradiance, temp_cell,
497501
imp = g * imp0 * (1 + alpha_imp * delT)
498502
vmp = vmp0 * (1 + eps0 * lamT * lnG + eps1 * (1 - g) + beta_vmp * delT)
499503

504+
# handle negative voltages from zero and extremely small irradiance
505+
vmp = np.clip(vmp, a_min=0, a_max=None)
506+
voc = np.clip(voc, a_min=0, a_max=None)
507+
500508
return {
501509
'p_mp': vmp * imp,
502510
'i_mp': imp,

tests/test_pvarray.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import numpy as np
2+
from numpy import nan
23
import pandas as pd
34
from numpy.testing import assert_allclose
45
from .conftest import assert_series_equal
@@ -114,3 +115,40 @@ def test_huld_errors():
114115
pvarray.huld(
115116
eff_irr, temp_mod, pdc0, cell_type='csi', k_version='2021'
116117
)
118+
119+
120+
def test_batzelis():
121+
params = {'isc0': 15.98, 'voc0': 50.26, 'imp0': 15.27, 'vmp0': 42.57,
122+
'alpha_sc': 0.00046, 'beta_voc': -0.0024}
123+
g = np.array([1000, 500, 1200, 500, 1200, 0, nan, 1000])
124+
t = np.array([25, 20, 20, 50, 50, 25, 0, nan])
125+
expected = { # these values were computed using the function itself
126+
'p_mp': [650.044, 328.599, 789.136, 300.079, 723.401, 0, nan, nan],
127+
'i_mp': [ 15.270, 7.626, 18.302, 7.680, 18.433, 0, nan, nan],
128+
'v_mp': [ 42.570, 43.090, 43.117, 39.071, 39.246, 0, nan, nan],
129+
'i_sc': [ 15.980, 7.972, 19.132, 8.082, 19.397, 0, nan, nan],
130+
'v_oc': [ 50.260, 49.687, 51.172, 45.948, 47.585, 0, nan, nan],
131+
}
132+
133+
# numpy array
134+
actual = pvarray.batzelis(g, t, **params)
135+
for key, exp in expected.items():
136+
np.testing.assert_allclose(actual[key], exp, atol=1e-3)
137+
138+
# pandas series
139+
actual = pvarray.batzelis(pd.Series(g), pd.Series(t), **params)
140+
for key, exp in expected.items():
141+
pd.testing.assert_series_equal(actual[key], pd.Series(exp), atol=1e-3)
142+
143+
# scalar
144+
actual = pvarray.batzelis(g[1], t[1], **params)
145+
for key, exp in expected.items():
146+
assert pytest.approx(exp[1], abs=1e-3) == actual[key]
147+
148+
149+
def test_batzelis_negative_voltage():
150+
params = {'isc0': 15.98, 'voc0': 50.26, 'imp0': 15.27, 'vmp0': 42.57,
151+
'alpha_sc': 0.00046, 'beta_voc': -0.0024}
152+
actual = pvarray.batzelis(1e-10, 25, **params)
153+
assert actual['v_mp'] == 0
154+
assert actual['v_oc'] == 0

0 commit comments

Comments
 (0)