Skip to content

Commit 74158a2

Browse files
authored
Merge branch 'main' into test-simple-efficiency-vectorized
2 parents 7abb5e7 + 0e92d6c commit 74158a2

4 files changed

Lines changed: 30 additions & 4 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ Deprecations
1414

1515
Bug fixes
1616
~~~~~~~~~
17-
17+
* Fix a division-by-zero condition in
18+
:py:func:`pvlib.transformer.simple_efficiency` when ``load_loss = 0``.
19+
(:issue:`2645`, :pull:`2646`)
1820

1921
Enhancements
2022
~~~~~~~~~~~~
@@ -42,4 +44,5 @@ Maintenance
4244

4345
Contributors
4446
~~~~~~~~~~~~
47+
* Aman Srivastava (:ghuser:`aman-coder03`)
4548

pvlib/iotools/bsrn.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ def get_bsrn(station, start, end, username, password,
148148
<https://bsrn.awi.de/>`_
149149
.. [2] `BSRN Data Retrieval via FTP
150150
<https://bsrn.awi.de/data/data-retrieval-via-ftp/>`_
151-
.. [4] `BSRN Data Release Guidelines
151+
.. [3] `BSRN Data Release Guidelines
152152
<https://bsrn.awi.de/data/conditions-of-data-release/>`_
153-
.. [3] `Update of the Technical Plan for BSRN Data Management, 2013,
153+
.. [4] `Update of the Technical Plan for BSRN Data Management, 2013,
154154
Global Climate Observing System (GCOS) GCOS-174.
155155
<https://bsrn.awi.de/fileadmin/user_upload/bsrn.awi.de/Publications/gcos-174.pdf>`_
156156
""" # noqa: E501

pvlib/transformer.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ def simple_efficiency(
111111
b = 1
112112
c = no_load_loss - input_power_normalized
113113

114-
output_power_normalized = (-b + (b**2 - 4*a*c)**0.5) / (2 * a)
114+
# alternative form of the quadratic equation to avoid
115+
# divide-by-zero when a == 0
116+
disc = (b*b - 4*a*c)**0.5
117+
output_power_normalized = 2*c / (-b - disc)
115118

116119
output_power = output_power_normalized * transformer_rating
117120
return output_power

tests/test_transformer.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pandas as pd
2+
import pytest
23

34
from numpy.testing import assert_allclose
45

@@ -98,3 +99,22 @@ def test_simple_efficiency_vector_equals_scalar():
9899
])
99100

100101
assert_allclose(vector_result, scalar_result)
102+
@pytest.mark.parametrize(
103+
"input_power, no_load_loss, load_loss, transformer_rating, expected",
104+
[
105+
(1000.0, 0.01, 0.0, 1000.0, 990.0),
106+
],
107+
)
108+
def test_simple_efficiency_zero_load_loss(
109+
input_power, no_load_loss, load_loss, transformer_rating, expected
110+
):
111+
# for load_loss = 0, the model reduces to:
112+
# P_out = P_in - L_no_load * P_nom
113+
result = transformer.simple_efficiency(
114+
input_power=input_power,
115+
no_load_loss=no_load_loss,
116+
load_loss=load_loss,
117+
transformer_rating=transformer_rating,
118+
)
119+
120+
assert_allclose(result, expected)

0 commit comments

Comments
 (0)