Skip to content

Commit 106712b

Browse files
committed
more edits from review
1 parent a720411 commit 106712b

4 files changed

Lines changed: 76 additions & 46 deletions

File tree

docs/sphinx/source/whatsnew/v0.13.1.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ Bug fixes
1818

1919
Enhancements
2020
~~~~~~~~~~~~
21-
* Added ``method='chandrupatla'`` to :py:func:`pvlib.pvsystem.singlediode`,
21+
* Added ``method='chandrupatla'`` (faster than ``brentq`` and slower than ``newton``,
22+
but convergence is guaranteed) to
23+
:py:func:`pvlib.pvsystem.singlediode`,
2224
:py:func:`~pvlib.pvsystem.i_from_v`,
2325
:py:func:`~pvlib.pvsystem.v_from_i`,
2426
:py:func:`~pvlib.pvsystem.max_power_point`,

pvlib/pvsystem.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2634,8 +2634,11 @@ def max_power_point(photocurrent, saturation_current, resistance_series,
26342634
cells ``Ns`` and the builtin voltage ``Vbi`` of the intrinsic layer.
26352635
[V].
26362636
method : str
2637-
either ``'newton'``, ``'brentq'``, or ``'chandrupatla'`` (requires
2638-
scipy 1.15 or greater)
2637+
either ``'newton'``, ``'brentq'``, or ``'chandrupatla'``.
2638+
2639+
.. note::
2640+
``'chandrupatla'`` requires scipy 1.15 or greater.
2641+
26392642
26402643
Returns
26412644
-------
@@ -2719,8 +2722,12 @@ def v_from_i(current, photocurrent, saturation_current, resistance_series,
27192722
27202723
method : str
27212724
Method to use: ``'lambertw'``, ``'newton'``, ``'brentq'``, or
2722-
``'chandrupatla'`` (requires scipy 1.15 or greater). *Note*:
2723-
``'brentq'`` is limited to 1st quadrant only.
2725+
``'chandrupatla'``. *Note*: ``'brentq'`` is limited to 1st quadrant
2726+
only.
2727+
2728+
.. note::
2729+
``'chandrupatla'`` requires scipy 1.15 or greater.
2730+
27242731
27252732
Returns
27262733
-------
@@ -2802,8 +2809,12 @@ def i_from_v(voltage, photocurrent, saturation_current, resistance_series,
28022809
28032810
method : str
28042811
Method to use: ``'lambertw'``, ``'newton'``, ``'brentq'``, or
2805-
``'chandrupatla'`` (requires scipy 1.15 or greater). *Note*:
2806-
``'brentq'`` is limited to 1st quadrant only.
2812+
``'chandrupatla'``. *Note*: ``'brentq'`` is limited to 1st quadrant
2813+
only.
2814+
2815+
.. note::
2816+
``'chandrupatla'`` requires scipy 1.15 or greater.
2817+
28072818
28082819
Returns
28092820
-------

pvlib/singlediode.py

Lines changed: 52 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,19 @@ def bishop88_i_from_v(voltage, photocurrent, saturation_current,
242242
breakdown_exp : float, default 3.28
243243
avalanche breakdown exponent :math:`m` [unitless]
244244
method : str, default 'newton'
245-
Either ``'newton'``, ``'brentq'``, or ``'chandrupatla'`` (requires
246-
scipy 1.15 or greater). ''method'' must be ``'newton'``
247-
if ``breakdown_factor`` is not 0.
245+
Either ``'newton'``, ``'brentq'``, or ``'chandrupatla'``.
246+
''method'' must be ``'newton'`` if ``breakdown_factor`` is not 0.
247+
248+
.. note::
249+
``'chandrupatla'`` requires scipy 1.15 or greater.
250+
248251
method_kwargs : dict, optional
249-
Keyword arguments passed to root finder method. See
250-
:py:func:`scipy:scipy.optimize.brentq`,
251-
:py:func:`scipy:scipy.optimize.newton`, and
252-
:py:func:`scipy:scipy.optimize.elementwise.find_root` (when ``method='chandrupatla'``) for parameters.
252+
Keyword arguments passed to the root finder. For options, see:
253+
254+
* ``method='brentq'``: :py:func:`scipy:scipy.optimize.brentq`
255+
* ``method='newton'``: :py:func:`scipy:scipy.optimize.newton`
256+
* ``method='chandrupatla'``: :py:func:`scipy:scipy.optimize.elementwise.find_root`
257+
253258
``'full_output': True`` is allowed, and ``optimizer_output`` would be
254259
returned. See examples section.
255260
@@ -288,7 +293,7 @@ def bishop88_i_from_v(voltage, photocurrent, saturation_current,
288293
.. [1] "Computer simulation of the effects of electrical mismatches in
289294
photovoltaic cell interconnection circuits" JW Bishop, Solar Cell (1988)
290295
:doi:`10.1016/0379-6787(88)90059-2`
291-
"""
296+
""" # noqa: E501
292297
# collect args
293298
args = (photocurrent, saturation_current,
294299
resistance_series, resistance_shunt, nNsVth, d2mutau, NsVbi,
@@ -336,11 +341,11 @@ def vd_from_brent(voc, v, iph, isat, rs, rsh, gamma, d2mutau, NsVbi,
336341
except ModuleNotFoundError as e:
337342
# TODO remove this when our minimum scipy version is >=1.15
338343
msg = (
339-
"method='chandrupatla' requires scipy v1.15 or greater. "
340-
"Select another method, or update your version of scipy. "
341-
f"({str(e)})"
344+
"method='chandrupatla' requires scipy v1.15 or greater "
345+
"(available for Python 3.10+). "
346+
"Select another method, or update your version of scipy."
342347
)
343-
raise ImportError(msg)
348+
raise ImportError(msg) from e
344349

345350
voc_est = estimate_voc(photocurrent, saturation_current, nNsVth)
346351
shape = _shape_of_max_size(voltage, voc_est)
@@ -409,13 +414,19 @@ def bishop88_v_from_i(current, photocurrent, saturation_current,
409414
breakdown_exp : float, default 3.28
410415
avalanche breakdown exponent :math:`m` [unitless]
411416
method : str, default 'newton'
412-
Either ``'newton'``, ``'brentq'``, or ``'chandrupatla'`` (requires
413-
scipy 1.15 or greater). ''method'' must be ``'newton'``
414-
if ``breakdown_factor`` is not 0.
417+
Either ``'newton'``, ``'brentq'``, or ``'chandrupatla'``.
418+
''method'' must be ``'newton'`` if ``breakdown_factor`` is not 0.
419+
420+
.. note::
421+
``'chandrupatla'`` requires scipy 1.15 or greater.
422+
415423
method_kwargs : dict, optional
416-
Keyword arguments passed to root finder method. See
417-
:py:func:`scipy:scipy.optimize.brentq` and
418-
:py:func:`scipy:scipy.optimize.newton` parameters.
424+
Keyword arguments passed to the root finder. For options, see:
425+
426+
* ``method='brentq'``: :py:func:`scipy:scipy.optimize.brentq`
427+
* ``method='newton'``: :py:func:`scipy:scipy.optimize.newton`
428+
* ``method='chandrupatla'``: :py:func:`scipy:scipy.optimize.elementwise.find_root`
429+
419430
``'full_output': True`` is allowed, and ``optimizer_output`` would be
420431
returned. See examples section.
421432
@@ -454,7 +465,7 @@ def bishop88_v_from_i(current, photocurrent, saturation_current,
454465
.. [1] "Computer simulation of the effects of electrical mismatches in
455466
photovoltaic cell interconnection circuits" JW Bishop, Solar Cell (1988)
456467
:doi:`10.1016/0379-6787(88)90059-2`
457-
"""
468+
""" # noqa: E501
458469
# collect args
459470
args = (photocurrent, saturation_current,
460471
resistance_series, resistance_shunt, nNsVth, d2mutau, NsVbi,
@@ -502,11 +513,11 @@ def vd_from_brent(voc, i, iph, isat, rs, rsh, gamma, d2mutau, NsVbi,
502513
except ModuleNotFoundError as e:
503514
# TODO remove this when our minimum scipy version is >=1.15
504515
msg = (
505-
"method='chandrupatla' requires scipy v1.15 or greater (available for Python3.10+). "
506-
"Select another method, or update your version of scipy. "
507-
f"({str(e)})"
516+
"method='chandrupatla' requires scipy v1.15 or greater "
517+
"(available for Python 3.10+). "
518+
"Select another method, or update your version of scipy."
508519
)
509-
raise ImportError(msg)
520+
raise ImportError(msg) from e
510521

511522
shape = _shape_of_max_size(current, voc_est)
512523
vlo = np.zeros(shape)
@@ -571,13 +582,19 @@ def bishop88_mpp(photocurrent, saturation_current, resistance_series,
571582
breakdown_exp : numeric, default 3.28
572583
avalanche breakdown exponent :math:`m` [unitless]
573584
method : str, default 'newton'
574-
Either ``'newton'``, ``'brentq'``, or ``'chandrupatla'`` (requires
575-
scipy 1.15 or greater). ''method'' must be ``'newton'``
576-
if ``breakdown_factor`` is not 0.
585+
Either ``'newton'``, ``'brentq'``, or ``'chandrupatla'``.
586+
''method'' must be ``'newton'`` if ``breakdown_factor`` is not 0.
587+
588+
.. note::
589+
``'chandrupatla'`` requires scipy 1.15 or greater.
590+
577591
method_kwargs : dict, optional
578-
Keyword arguments passed to root finder method. See
579-
:py:func:`scipy:scipy.optimize.brentq` and
580-
:py:func:`scipy:scipy.optimize.newton` parameters.
592+
Keyword arguments passed to the root finder. For options, see:
593+
594+
* ``method='brentq'``: :py:func:`scipy:scipy.optimize.brentq`
595+
* ``method='newton'``: :py:func:`scipy:scipy.optimize.newton`
596+
* ``method='chandrupatla'``: :py:func:`scipy:scipy.optimize.elementwise.find_root`
597+
581598
``'full_output': True`` is allowed, and ``optimizer_output`` would be
582599
returned. See examples section.
583600
@@ -617,7 +634,7 @@ def bishop88_mpp(photocurrent, saturation_current, resistance_series,
617634
.. [1] "Computer simulation of the effects of electrical mismatches in
618635
photovoltaic cell interconnection circuits" JW Bishop, Solar Cell (1988)
619636
:doi:`10.1016/0379-6787(88)90059-2`
620-
"""
637+
""" # noqa: E501
621638
# collect args
622639
args = (photocurrent, saturation_current,
623640
resistance_series, resistance_shunt, nNsVth, d2mutau, NsVbi,
@@ -663,17 +680,17 @@ def fmpp(x, *a):
663680
except ModuleNotFoundError as e:
664681
# TODO remove this when our minimum scipy version is >=1.15
665682
msg = (
666-
"method='chandrupatla' requires scipy v1.15 or greater. "
667-
"Select another method, or update your version of scipy. "
668-
f"({str(e)})"
683+
"method='chandrupatla' requires scipy v1.15 or greater "
684+
"(available for Python 3.10+). "
685+
"Select another method, or update your version of scipy."
669686
)
670-
raise ImportError(msg)
687+
raise ImportError(msg) from e
671688

672689
vlo = np.zeros_like(photocurrent)
673690
vhi = np.full_like(photocurrent, voc_est)
674691
kwargs_trimmed = method_kwargs.copy()
675692
kwargs_trimmed.pop("full_output", None) # not valid for find_root
676-
693+
677694
result = find_root(fmpp,
678695
(vlo, vhi),
679696
args=args,

tests/test_singlediode.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,10 +463,10 @@ def bishop88_arguments():
463463
}),
464464
# can't include chandrupatla since the function is not available to patch
465465
# TODO: add this once chandrupatla becomes non-optional functionality
466-
#('chandrupatla', {
467-
# 'tolerances ': {'xtol': 1e-8, 'rtol': 1e-8},
468-
# 'maxiter': 30,
469-
#}),
466+
# ('chandrupatla', {
467+
# 'tolerances ': {'xtol': 1e-8, 'rtol': 1e-8},
468+
# 'maxiter': 30,
469+
# }),
470470
])
471471
def test_bishop88_kwargs_transfer(method, method_kwargs, mocker,
472472
bishop88_arguments):

0 commit comments

Comments
 (0)