8000 progress on passing tests · reepoi/pvlib-python@52bf37e · GitHub
[go: up one dir, main page]

Skip to content {"props":{"docsUrl":"https://docs.github.com/get-started/accessibility/keyboard-shortcuts"}}

Commit 52bf37e

Browse files
committed
progress on passing tests
1 parent 93f2394 commit 52bf37e

File tree

4 files changed

+40
-14
lines changed

4 files changed

+40
-14
lines changed

pvlib/pvsystem.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2995,9 +2995,9 @@ def v_from_i(resistance_shunt, resistance_series, nNsVth, current,
29952995
except ValueError:
29962996
raise ValueError('Expected all single diode model parameters to be broadcastable to 1d arrays.')
29972997

2998-
if all(map(np.isscalar, kwargs.values())) and not np.isscalar(current) and current.ndim == 1:
2999-
raise ValueError('Given parameters for one single diode model, but current has shape {current.shape}.'
3000-
'Please pass current with shape {current.T.shape} to use multiple currents for one model.')
2998+
if all(map(np.isscalar, kwargs.values())) and not np.isscalar(current) and current.ndim == 1 and current.size > 1:
2999+
raise ValueError(f'Given parameters for one single diode model, but current has shape {current.shape}.'
3000+
+ f'Please pass current with shape {current.T.shape} to use multiple currents for one model.')
30013001

30023002
if method.lower() == 'lambertw':
30033003
return _singlediode._lambertw_v_from_i(current=current, **kwargs)
@@ -3084,11 +3084,22 @@ def i_from_v(resistance_shunt, resistance_series, nNsVth, voltage,
30843084
parameters of real solar cells using Lambert W-function", Solar
30853085
Energy Materials and Solar Cells, 81 (2004) 269-277.
30863086
'''
3087+
kwargs = {'resistance_shunt': resistance_shunt,
3088+
'resistance_series': resistance_series,
3089+
'nNsVth': nNsVth, 'saturation_current': saturation_current,
3090+
'photocurrent': photocurrent}
3091+
3092+
try:
3093+
np.broadcast_arrays(*kwargs.values())
3094+
except ValueError:
3095+
raise ValueError('Expected all single diode model parameters to be broadcastable to 1d arrays.')
3096+
3097+
if all(map(np.isscalar, kwargs.values())) and not np.isscalar(voltage) and voltage.ndim == 1 and voltage.size > 1:
3098+
raise ValueError(f'Given parameters for one single diode model, but voltage has shape {voltage.shape}.'
3099+
+ f'Please pass voltage with shape {voltage.T.shape} to use multiple voltages for one model.')
3100+
30873101
if method.lower() == 'lambertw':
3088-
current = _singlediode._lambertw_i_from_v(
3089-
resistance_shunt, resistance_series, nNsVth, voltage,
3090-
saturation_current, photocurrent
3091-
)
3102+
current = _singlediode._lambertw_i_from_v(voltage=voltage, **kwargs)
30923103
return current
30933104
if np.isscalar(current):
30943105
return current

pvlib/singlediode.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ def bishop88(diode_voltage, photocurrent, saturation_current,
153153
2010
154154
:doi:`10.4229/25thEUPVSEC2010-4BV.1.114`
155155
"""
156+
# args = (diode_voltage, photocurrent, saturation_current, resistance_series,
157+
# resistance_shunt, nNsVth, d2mutau, NsVbi, breakdown_factor,
158+
# breakdown_voltage, breakdown_exp)
159+
# (diode_voltage, photocurrent, saturation_current, resistance_series,
160+
# resistance_shunt, nNsVth, d2mutau, NsVbi, breakdown_factor,
161+
# breakdown_voltage, breakdown_exp) = np.atleast_2d(*args)
156162
# calculate recombination loss current where d2mutau > 0
157163
is_recomb = d2mutau > 0 # True where there is thin-film recombination loss
158164
v_recomb = np.where(is_recomb, NsVbi - diode_voltage, np.inf)
@@ -287,7 +293,12 @@ def vd_from_brent(voc, v, iph, isat, rs, rsh, gamma, d2mutau, NsVbi,
287293
args=args)
288294
else:
289295
raise NotImplementedError("Method '%s' isn't implemented" % method)
290-
return bishop88(vd, *args)[0]
296+
shape = _get_size_and_shape((voltage, *args))[1]
297+
vd, *args = np.atleast_2d(vd, *args)
298+
i = bishop88(vd, *args)[0]
299+
if shape is None:
300+
return i.item()
301+
return i.reshape(shape)
291302

292303

293304
def bishop88_v_from_i(current, photocurrent, saturation_current,
@@ -374,7 +385,12 @@ def vd_from_brent(voc, i, iph, isat, rs, rsh, gamma, d2mutau, NsVbi,
374385
args=args)
375386
else:
376387
raise NotImplementedError("Method '%s' isn't implemented" % method)
377-
return bishop88(vd, *args)[1]
388+
shape = _get_size_and_shape((current, *args))[1]
389+
vd, *args = np.atleast_2d(vd, *args)
390+
v = bishop88(vd, *args)[1]
391+
if shape is None:
392+
return v.item()
393+
return v.reshape(shape)
378394

379395

380396
def bishop88_mpp(photocurrent, saturation_current, resistance_series,

pvlib/tests/test_pvsystem.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,12 +1164,12 @@ def test_i_from_v_from_i(fixture_v_from_i):
11641164
'Rsh': np.inf,
11651165
'Rs': 0.,
11661166
'nNsVth': 0.5,
1167-
'V': np.array([0., 0.5*(np.log(7. + 6.e-7) - np.log(6.e-7))/2.,
1168-
0.5*(np.log(7. + 6.e-7) - np.log(6.e-7))]),
1167+
'V': np.array([[0., 0.5*(np.log(7. + 6.e-7) - np.log(6.e-7))/2.,
1168+
0.5*(np.log(7. + 6.e-7) - np.log(6.e-7))]]),
11691169
'I0': 6.e-7,
11701170
'IL': 7.,
1171-
'I_expected': np.array([7., 7. - 6.e-7*np.expm1((np.log(7. + 6.e-7) -
1172-
np.log(6.e-7))/2.), 0.])
1171+
'I_expected': np.array([[7., 7. - 6.e-7*np.expm1((np.log(7. + 6.e-7) -
1172+
np.log(6.e-7))/2.), 0.]])
11731173
},
11741174
{ # Can handle only ideal shunt resistance, no closed form solution
11751175
'Rsh': np.inf,

pvlib/tests/test_singlediode.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ def test_method_spr_e20_327(method, cec_module_spr_e20_327):
3232
assert np.isclose(pvs['i_sc'], isc)
3333
assert np.isclose(pvs['v_oc'], voc)
3434
# the singlediode method doesn't actually get the MPP correct
35-
breakpoint()
3635
pvs_imp = pvsystem.i_from_v(rsh, rs, nnsvt, vmp, io, il, method='lambertw')
3736
pvs_vmp = pvsystem.v_from_i(rsh, rs, nnsvt, imp, io, il, method='lambertw')
3837
assert np.isclose(pvs_imp, imp)

0 commit comments

Comments
 (0)
0