Skip to content

Commit 3d0deb2

Browse files
committed
ENH: improve code style, fix d2mutau is array
* expand module type abbrev. in warnings * also expand EG to For example, too terse * cells in series can be int _or_ `None` * since d2mutau and vbi are arrays, then ambiguous to test for zero, so use np.where to assign conditionally instead (in two places)
1 parent 1e9434a commit 3d0deb2

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

pvlib/singlediode_methods.py

+15-16
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ def bishop88(diode_voltage, photocurrent, saturation_current,
7474
7575
.. warning::
7676
* Do not use ``d2mutau`` with CEC coefficients.
77-
* Usage of ``d2mutau`` with PVSyst coefficients is required for CdTe and
78-
a:Si modules.
77+
* Usage of ``d2mutau`` with PVSyst coefficients is required for cadmium-
78+
telluride (CdTe) and amorphous-silicon (a:Si) PV modules only.
7979
* For PVSyst CdTe and a:Si modules, the ``cells_in_series`` parameter
8080
must only account for a single parallel sub-string if the module has
8181
cells in parallel greater than 1.
@@ -95,7 +95,7 @@ def bishop88(diode_voltage, photocurrent, saturation_current,
9595
nNsVth : numeric
9696
product of thermal voltage ``Vth`` [V], diode ideality factor ``n``,
9797
and number of series cells ``Ns``
98-
cells_in_series : int
98+
cells_in_series : None or int
9999
number of cells in series per parallel module sub-string, only required
100100
for PVSyst thin-film recombination loss, if unset default is ``None``
101101
which raises ``TypeError`` if ``d2mutau`` is set.
@@ -123,9 +123,9 @@ def bishop88(diode_voltage, photocurrent, saturation_current,
123123
The PVSyst thin-film recombination losses parameters ``d2mutau`` and
124124
``voltage_builtin`` are only applied to cadmium-telluride (CdTe) and
125125
amorphous-silicon (a:Si) PV modules, [2]_, [3]_. The builtin voltage should
126-
account for all junctions. *EG*: tandem and triple junction cell would have
127-
builtin voltages of 1.8[V] and 2.7[V] respectively, based on the default of
128-
0.9[V] for a single junction.
126+
account for all junctions. For example: tandem and triple junction cell
127+
would have builtin voltages of 1.8[V] and 2.7[V] respectively, based on the
128+
default of 0.9[V] for a single junction.
129129
130130
References
131131
----------
@@ -143,11 +143,12 @@ def bishop88(diode_voltage, photocurrent, saturation_current,
143143
2010
144144
:doi:`10.4229/25thEUPVSEC2010-4BV.1.114`
145145
"""
146-
# check if need to calculate recombination loss current
147-
i_recomb, v_recomb = 0, np.inf
148-
if d2mutau > 0:
149-
v_recomb = voltage_builtin * cells_in_series - diode_voltage
150-
i_recomb = photocurrent * d2mutau / v_recomb
146+
# calculate recombination loss current where d2mutau > 0
147+
is_recomb = d2mutau > 0 # True where there is thin-film recombination loss
148+
v_recomb = np.where(is_recomb,
149+
voltage_builtin * cells_in_series - diode_voltage,
150+
np.inf)
151+
i_recomb = np.where(is_recomb, photocurrent * d2mutau / v_recomb, 0)
151152
# calculate temporary values to simplify calculations
152153
v_star = diode_voltage / nNsVth # non-dimensional diode voltage
153154
g_sh = 1.0 / resistance_shunt # conductance
@@ -156,11 +157,9 @@ def bishop88(diode_voltage, photocurrent, saturation_current,
156157
v = diode_voltage - i * resistance_series
157158
retval = (i, v, i*v)
158159
if gradients:
159-
# check again if need to calculate recombination loss current gradients
160-
grad_i_recomb = grad_2i_recomb = 0
161-
if d2mutau > 0:
162-
grad_i_recomb = i_recomb / v_recomb
163-
grad_2i_recomb = 2 * grad_i_recomb / v_recomb
160+
# calculate recombination loss current gradients where d2mutau > 0
161+
grad_i_recomb = np.where(is_recomb, i_recomb / v_recomb, 0)
162+
grad_2i_recomb = np.where(is_recomb, 2 * grad_i_recomb / v_recomb, 0)
164163
g_diode = saturation_current * np.exp(v_star) / nNsVth # conductance
165164
grad_i = -g_diode - g_sh - grad_i_recomb # di/dvd
166165
grad_v = 1.0 - grad_i * resistance_series # dv/dvd

0 commit comments

Comments
 (0)