Skip to content

Commit 128d984

Browse files
committed
add voltage as kwarg
1 parent 9635a40 commit 128d984

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

pvlib/pvsystem.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,8 +1932,8 @@ def sapm_effective_irradiance(poa_direct, poa_diffuse, airmass_absolute, aoi,
19321932

19331933

19341934
def singlediode(photocurrent, saturation_current, resistance_series,
1935-
resistance_shunt, nNsVth, ivcurve_pnts=None,
1936-
method='lambertw'):
1935+
resistance_shunt, nNsVth, voltage=np.array([]),
1936+
ivcurve_pnts=None, method='lambertw'):
19371937
"""
19381938
Solve the single-diode model to obtain a photovoltaic IV curve.
19391939
@@ -1985,9 +1985,13 @@ def singlediode(photocurrent, saturation_current, resistance_series,
19851985
q is the charge of an electron (coulombs).
19861986
0 < nNsVth
19871987
1988+
voltage : numeric, default empty
1989+
Voltage values where points are calculated on the IV curve. Must be
1990+
sorted in increasing order.
1991+
19881992
ivcurve_pnts : None or int, default None
1989-
Number of points in the desired IV curve. If None or 0, no
1990-
IV curves will be produced.
1993+
Number of points to calculate along the IV curve. If `voltages` is
1994+
provides, `ivcurve_pnts` is ignored.
19911995
19921996
method : str, default 'lambertw'
19931997
Determines the method used to calculate points on the IV curve. The
@@ -2021,9 +2025,9 @@ def singlediode(photocurrent, saturation_current, resistance_series,
20212025
20222026
Notes
20232027
-----
2024-
If the method is ``'lambertw'`` then the solution employed to solve the
2025-
implicit diode equation utilizes the Lambert W function to obtain an
2026-
explicit function of :math:`V=f(I)` and :math:`I=f(V)` as shown in [2].
2028+
If the method is ``'lambertw'`` then the solution to the implicit diode
2029+
equation utilizes the Lambert W function to obtain an explicit function of
2030+
:math:`V=f(I)` and :math:`I=f(V)` as shown in [2].
20272031
20282032
If the method is ``'newton'`` then the root-finding Newton-Raphson method
20292033
is used. It should be safe for well behaved IV-curves, but the ``'brentq'``
@@ -2094,13 +2098,21 @@ def singlediode(photocurrent, saturation_current, resistance_series,
20942098
(v_oc + v_mp) / 2.0, *args, method=method.lower()
20952099
)
20962100

2097-
# calculate the IV curve if requested using bishop88
2098-
if ivcurve_pnts:
2101+
if voltage.size:
2102+
# calculate the IV curve if requested using bishop88
2103+
ivcurve_i, ivcurve_v, _ = _singlediode.bishop88_i_from_v(
2104+
voltage, *args, method=method.lower())
2105+
calc = True
2106+
elif ivcurve_pnts:
2107+
# calculate the IV curve if requested using bishop88
20992108
vd = v_oc * (
21002109
(11.0 - np.logspace(np.log10(11.0), 0.0,
21012110
ivcurve_pnts)) / 10.0
21022111
)
21032112
ivcurve_i, ivcurve_v, _ = _singlediode.bishop88(vd, *args)
2113+
calc = True
2114+
else:
2115+
calc = False
21042116

21052117
out = OrderedDict()
21062118
out['i_sc'] = i_sc
@@ -2111,7 +2123,7 @@ def singlediode(photocurrent, saturation_current, resistance_series,
21112123
out['i_x'] = i_x
21122124
out['i_xx'] = i_xx
21132125

2114-
if ivcurve_pnts:
2126+
if calc:
21152127

21162128
out['v'] = ivcurve_v
21172129
out['i'] = ivcurve_i

pvlib/singlediode.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,8 @@ def _lambertw_i_from_v(resistance_shunt, resistance_series, nNsVth, voltage,
574574

575575

576576
def _lambertw(photocurrent, saturation_current, resistance_series,
577-
resistance_shunt, nNsVth, ivcurve_pnts=None):
577+
resistance_shunt, nNsVth, voltage=np.array([]),
578+
ivcurve_pnts=None):
578579
# Compute short circuit current
579580
i_sc = _lambertw_i_from_v(resistance_shunt, resistance_series, nNsVth, 0.,
580581
saturation_current, photocurrent)
@@ -609,10 +610,17 @@ def _lambertw(photocurrent, saturation_current, resistance_series,
609610
out = (i_sc, v_oc, i_mp, v_mp, p_mp, i_x, i_xx)
610611

611612
# create ivcurve
612-
if ivcurve_pnts:
613+
if voltage.size:
614+
ivcurve_v = voltage
615+
calc = True
616+
elif ivcurve_pnts:
613617
ivcurve_v = (np.asarray(v_oc)[..., np.newaxis] *
614618
np.linspace(0, 1, ivcurve_pnts))
619+
calc = True
620+
else:
621+
calc = False
615622

623+
if calc:
616624
ivcurve_i = _lambertw_i_from_v(resistance_shunt, resistance_series,
617625
nNsVth, ivcurve_v.T, saturation_current,
618626
photocurrent).T

0 commit comments

Comments
 (0)