Skip to content

Commit ff8cc0b

Browse files
committed
change name from mppt -> mpp
* add mpp tests for float, array and series *
1 parent 09c6a75 commit ff8cc0b

File tree

3 files changed

+64
-14
lines changed

3 files changed

+64
-14
lines changed

pvlib/pvsystem.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,11 +1821,11 @@ def singlediode(photocurrent, saturation_current, resistance_series,
18211821
return out
18221822

18231823

1824-
def mppt(photocurrent, saturation_current, resistance_series, resistance_shunt,
1825-
nNsVth, method='gold'):
1824+
def mpp(photocurrent, saturation_current, resistance_series, resistance_shunt,
1825+
nNsVth, method='gold'):
18261826
"""
1827-
Max power point tracker. Given the calculated DeSoto parameters calculates
1828-
the maximum power point (MPP).
1827+
Given the calculated DeSoto parameters, calculates the maximum power point
1828+
(MPP).
18291829
18301830
:param numeric photocurrent: photo-generated current [A]
18311831
:param numeric saturation_current: diode one reverse saturation current [A]
@@ -1837,13 +1837,13 @@ def mppt(photocurrent, saturation_current, resistance_series, resistance_shunt,
18371837
and ``p_mp``
18381838
"""
18391839
if method.lower() == 'fast':
1840-
mppt_func = singlediode_methods.fast_mppt
1840+
mpp_fun = singlediode_methods.fast_mpp
18411841
else:
1842-
mppt_func = singlediode_methods.slow_mppt
1842+
mpp_fun = singlediode_methods.slow_mpp
18431843
try:
18441844
len(photocurrent)
18451845
except TypeError:
1846-
i_mp, v_mp, p_mp = mppt_func(
1846+
i_mp, v_mp, p_mp = mpp_fun(
18471847
photocurrent, saturation_current, resistance_series,
18481848
resistance_shunt, nNsVth
18491849
)
@@ -1852,7 +1852,7 @@ def mppt(photocurrent, saturation_current, resistance_series, resistance_shunt,
18521852
out['v_mp'] = v_mp
18531853
out['p_mp'] = p_mp
18541854
else:
1855-
vecfun = np.vectorize(mppt_func)
1855+
vecfun = np.vectorize(mpp_fun)
18561856
ivp = vecfun(photocurrent, saturation_current, resistance_series,
18571857
resistance_shunt, nNsVth)
18581858
if isinstance(photocurrent, pd.Series):

pvlib/singlediode_methods.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ def fast_v_from_i(i, photocurrent, saturation_current, resistance_series,
171171
return bishop88(vd, *args)[1]
172172

173173

174-
def slow_mppt(photocurrent, saturation_current, resistance_series,
175-
resistance_shunt, nNsVth):
174+
def slow_mpp(photocurrent, saturation_current, resistance_series,
175+
resistance_shunt, nNsVth):
176176
"""
177177
This is a slow but reliable way to find mpp.
178178
"""
@@ -188,8 +188,8 @@ def slow_mppt(photocurrent, saturation_current, resistance_series,
188188
return bishop88(vd, *args)
189189

190190

191-
def fast_mppt(photocurrent, saturation_current, resistance_series,
192-
resistance_shunt, nNsVth):
191+
def fast_mpp(photocurrent, saturation_current, resistance_series,
192+
resistance_shunt, nNsVth):
193193
"""
194194
This is a possibly faster way to find mpp.
195195
"""
@@ -216,7 +216,7 @@ def slower_way(photocurrent, saturation_current, resistance_series,
216216
args = (photocurrent, saturation_current, resistance_series,
217217
resistance_shunt, nNsVth)
218218
v_oc = slow_v_from_i(0.0, *args)
219-
i_mp, v_mp, p_mp = slow_mppt(*args)
219+
i_mp, v_mp, p_mp = slow_mpp(*args)
220220
out = OrderedDict()
221221
out['i_sc'] = slow_i_from_v(0.0, *args)
222222
out['v_oc'] = v_oc
@@ -243,7 +243,7 @@ def faster_way(photocurrent, saturation_current, resistance_series,
243243
args = (photocurrent, saturation_current, resistance_series,
244244
resistance_shunt, nNsVth) # collect args
245245
v_oc = fast_v_from_i(0.0, *args)
246-
i_mp, v_mp, p_mp = fast_mppt(*args)
246+
i_mp, v_mp, p_mp = fast_mpp(*args)
247247
out = OrderedDict()
248248
out['i_sc'] = fast_i_from_v(0.0, *args)
249249
out['v_oc'] = v_oc

pvlib/test/test_pvsystem.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,56 @@ def test_PVSystem_i_from_v():
625625
assert_allclose(output, 3.0, atol=1e-5)
626626

627627

628+
@requires_scipy
629+
def test_mpp_floats():
630+
"""test mpp"""
631+
IL, I0, Rs, Rsh, nNsVth = (7, 6e-7, .1, 20, .5)
632+
out = pvsystem.mpp(IL, I0, Rs, Rsh, nNsVth)
633+
expected = {'i_mp': 6.1362673597376753, # 6.1390251797935704, lambertw
634+
'v_mp': 6.2243393757884284, # 6.221535886625464, lambertw
635+
'p_mp': 38.194210547580511} # 38.194165464983037} lambertw
636+
assert isinstance(out, dict)
637+
for k, v in out.items():
638+
assert np.isclose(v, expected[k])
639+
out = pvsystem.mpp(IL, I0, Rs, Rsh, nNsVth, method='fast')
640+
for k, v in out.items():
641+
assert np.isclose(v, expected[k])
642+
643+
644+
@requires_scipy
645+
def test_mpp_array():
646+
"""test mpp"""
647+
IL, I0, Rs, Rsh, nNsVth = ([7, 7], 6e-7, .1, 20, .5)
648+
out = pvsystem.mpp(IL, I0, Rs, Rsh, nNsVth)
649+
expected = {'i_mp': [6.1362673597376753] * 2,
650+
'v_mp': [6.2243393757884284] * 2,
651+
'p_mp': [38.194210547580511] * 2}
652+
assert isinstance(out, dict)
653+
for k, v in out.items():
654+
assert np.allclose(v, expected[k])
655+
out = pvsystem.mpp(IL, I0, Rs, Rsh, nNsVth, method='fast')
656+
for k, v in out.items():
657+
assert np.allclose(v, expected[k])
658+
659+
660+
@requires_scipy
661+
def test_mpp_series():
662+
"""test mpp"""
663+
idx = ['2008-02-17T11:30:00-0800', '2008-02-17T12:30:00-0800']
664+
IL, I0, Rs, Rsh, nNsVth = ([7, 7], 6e-7, .1, 20, .5)
665+
IL = pd.Series(IL, index=idx)
666+
out = pvsystem.mpp(IL, I0, Rs, Rsh, nNsVth)
667+
expected = pd.DataFrame({'i_mp': [6.1362673597376753] * 2,
668+
'v_mp': [6.2243393757884284] * 2,
669+
'p_mp': [38.194210547580511] * 2},
670+
index=idx)
671+
assert isinstance(out, pd.DataFrame)
672+
for k, v in out.items():
673+
assert np.allclose(v, expected[k])
674+
for k, v in out.items():
675+
assert np.allclose(v, expected[k])
676+
677+
628678
@requires_scipy
629679
def test_singlediode_series(cec_module_params):
630680
times = pd.DatetimeIndex(start='2015-01-01', periods=2, freq='12H')

0 commit comments

Comments
 (0)