Skip to content

Commit 68c65c3

Browse files
committed
fixes pvlib#410
* test_modelchain now passes * in pvsystem.singlediode if using default "slow" then use ducktyping to see if photocurrent is a sequence, sorry other params are not checked, if not, then get out as usual, if it is, then use np.vectorize, and get a sequence of outputs, check if photocurrent is a pd.Series, and if so, then convert out to a pd.DataFrame, otherwise, transpose the sequence of outputs into a an OrderedDict of sequences (actually np.arrays) * move series check from original lambertw back up to there, because it doesn't work for the vectorized slow or fast methods, you need to call .tolist() first * also copy & paste WET code for 'fast'
1 parent c5248bb commit 68c65c3

File tree

1 file changed

+48
-19
lines changed

1 file changed

+48
-19
lines changed

pvlib/pvsystem.py

+48-19
Original file line numberDiff line numberDiff line change
@@ -1733,29 +1733,58 @@ def singlediode(photocurrent, saturation_current, resistance_series,
17331733
out['v'] = ivcurve_v
17341734
out['i'] = ivcurve_i
17351735

1736+
if isinstance(photocurrent, pd.Series) and not ivcurve_pnts:
1737+
out = pd.DataFrame(out, index=photocurrent.index)
1738+
1739+
elif method.lower() == 'fast':
1740+
try:
1741+
len(photocurrent)
1742+
except TypeError:
1743+
out = way_faster.faster_way(
1744+
photocurrent, saturation_current, resistance_series,
1745+
resistance_shunt, nNsVth, ivcurve_pnts
1746+
)
1747+
else:
1748+
vecfun = np.vectorize(way_faster.faster_way)
1749+
out = vecfun(photocurrent, saturation_current, resistance_series,
1750+
resistance_shunt, nNsVth, ivcurve_pnts)
1751+
if isinstance(photocurrent, pd.Series) and not ivcurve_pnts:
1752+
out = pd.DataFrame(out.tolist(), index=photocurrent.index)
1753+
else:
1754+
out_array = pd.DataFrame(out.tolist())
1755+
out = OrderedDict()
1756+
out['i_sc'] = out_array.i_sc
1757+
out['v_oc'] = out_array.v_oc
1758+
out['i_mp'] = out_array.i_mp
1759+
out['v_mp'] = out_array.v_mp
1760+
out['p_mp'] = out_array.p_mp
1761+
out['i_x'] = out_array.i_x
1762+
out['i_xx'] = out_array.i_xx
1763+
17361764
else:
1737-
size = 0
17381765
try:
1739-
size = len(photocurrent)
1766+
len(photocurrent)
17401767
except TypeError:
1741-
my_func = way_faster.faster_way
1768+
out = way_faster.slower_way(
1769+
photocurrent, saturation_current, resistance_series,
1770+
resistance_shunt, nNsVth, ivcurve_pnts
1771+
)
17421772
else:
1743-
my_func = np.vectorize(way_faster.slower_way)
1744-
out = my_func(photocurrent, saturation_current, resistance_series,
1745-
resistance_shunt, nNsVth, ivcurve_pnts)
1746-
if size:
1747-
out_array = pd.DataFrame(out.tolist())
1748-
out = OrderedDict()
1749-
out['i_sc'] = out_array.i_sc
1750-
out['v_oc'] = out_array.v_oc
1751-
out['i_mp'] = out_array.i_mp
1752-
out['v_mp'] = out_array.v_mp
1753-
out['p_mp'] = out_array.p_mp
1754-
out['i_x'] = out_array.i_x
1755-
out['i_xx'] = out_array.i_xx
1756-
1757-
if isinstance(photocurrent, pd.Series) and not ivcurve_pnts:
1758-
out = pd.DataFrame(out, index=photocurrent.index)
1773+
vecfun = np.vectorize(way_faster.slower_way)
1774+
out = vecfun(photocurrent, saturation_current, resistance_series,
1775+
resistance_shunt, nNsVth, ivcurve_pnts)
1776+
if isinstance(photocurrent, pd.Series) and not ivcurve_pnts:
1777+
out = pd.DataFrame(out.tolist(), index=photocurrent.index)
1778+
else:
1779+
out_array = pd.DataFrame(out.tolist())
1780+
out = OrderedDict()
1781+
out['i_sc'] = out_array.i_sc
1782+
out['v_oc'] = out_array.v_oc
1783+
out['i_mp'] = out_array.i_mp
1784+
out['v_mp'] = out_array.v_mp
1785+
out['p_mp'] = out_array.p_mp
1786+
out['i_x'] = out_array.i_x
1787+
out['i_xx'] = out_array.i_xx
17591788

17601789
return out
17611790

0 commit comments

Comments
 (0)