Skip to content

Commit 3ca7556

Browse files
Catch exceptions in i_mp_ic computation and update docstring
1 parent 999df20 commit 3ca7556

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

pvlib/pvsystem.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3048,17 +3048,22 @@ def max_power_point_mismatched(
30483048
previous step may speed up computation. Algorithm falls back to automated
30493049
computation of i_mp_ic if solution fails with provided i_mp_ic. The value
30503050
of i_mp_ic used is returned along with i_mp (same value for all devices),
3051-
v_mp, and p_mp.
3051+
v_mp, p_mp, i_mp_string, v_mp_string, and p_mp_string.
30523052
"""
30533053
if i_mp_ic is None:
3054-
i_mp_ic = max_power_point(
3055-
np.mean(photocurrent),
3056-
np.mean(saturation_current),
3057-
np.mean(resistance_series),
3058-
np.mean(resistance_shunt),
3059-
np.mean(nNsVth),
3060-
)["i_mp"]
30613054
retry_ic = False
3055+
try:
3056+
i_mp_ic = max_power_point(
3057+
np.mean(photocurrent),
3058+
np.mean(saturation_current),
3059+
np.mean(resistance_series),
3060+
np.mean(resistance_shunt),
3061+
np.mean(nNsVth),
3062+
)["i_mp"]
3063+
except Exception as exc:
3064+
raise RuntimeError(
3065+
f"unsuccessful determination of i_mp_ic"
3066+
) from exc
30623067
else:
30633068
retry_ic = True
30643069

pvlib/tests/test_pvsystem.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2648,11 +2648,11 @@ def test_max_power_point_mismatched(inputs):
26482648
print(result)
26492649

26502650

2651-
def test_max_power_point_mismatched_error():
2651+
def test_max_power_point_mismatched_exception():
26522652
"""
26532653
Test errored max power point computation for mismatched devices in series.
26542654
"""
2655-
photocurrent = -6.2
2655+
photocurrent = -6.2 # This is bad.
26562656
saturation_current = 1.0e-8
26572657
resistance_series = 0.0001
26582658
resistance_shunt = 5000.0
@@ -2661,7 +2661,7 @@ def test_max_power_point_mismatched_error():
26612661
T_K = scipy.constants.convert_temperature(25.0, "Celsius", "Kelvin")
26622662
nNsVth = 1.1 * 60 * k_B_J_per_K * T_K / q_C
26632663

2664-
with pytest.raises(ValueError) as e_info:
2664+
with pytest.raises(RuntimeError) as e_info:
26652665
pvsystem.max_power_point_mismatched(
26662666
photocurrent,
26672667
saturation_current,

0 commit comments

Comments
 (0)