Skip to content

Commit f66cb91

Browse files
authored
use horner's method in disc (#1183)
* use horner's method in disc * Update v0.9.5.rst update whatsnew * fix stickler, indentation in disc * fix underindentation stickler issue in disc * use is_clear instead of bools in disc * fix stickler indentation complaint for disc * fix stickler indent complaint in disc again * change is_clear to is_cloudy, fix hyperlink for whatsnew rst * Update v0.9.5.rst Fix link to Horner’s method
1 parent db1111e commit f66cb91

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ Enhancements
2626
differentiable and bounded between zero and one. (:pull:`1179`)
2727
* Add ``model='gueymard2003'``, the airmass model used for REST and REST2,
2828
to :py:func:`~pvlib.atmosphere.get_relative_airmass`. (:pull:`1655`)
29-
30-
3129
* Added an optional ``model`` parameter to
3230
:py:func:`pvlib.bifacial.infinite_sheds.get_irradiance` and
3331
:py:func:`pvlib.bifacial.infinite_sheds.get_irradiance_poa`
3432
to enable use of the hay-davies sky diffuse irradiance model
3533
instead of the default isotropic model. (:pull:`1668`)
34+
* Use `Horner's Method <https://en.wikipedia.org/wiki/Horner%27s_method>`_
35+
to evaluate polynomials in :py:func:`~pvlib.irradiance.disc`, may
36+
decrease runtime by 20%. (:issue:`1180`, :pull:`1183`)
3637

3738
Bug fixes
3839
~~~~~~~~~

pvlib/irradiance.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,24 +1481,24 @@ def _disc_kn(clearness_index, airmass, max_airmass=12):
14811481

14821482
am = np.minimum(am, max_airmass) # GH 450
14831483

1484-
# powers of kt will be used repeatedly, so compute only once
1485-
kt2 = kt * kt # about the same as kt ** 2
1486-
kt3 = kt2 * kt # 5-10x faster than kt ** 3
1487-
1488-
bools = (kt <= 0.6)
1489-
a = np.where(bools,
1490-
0.512 - 1.56*kt + 2.286*kt2 - 2.222*kt3,
1491-
-5.743 + 21.77*kt - 27.49*kt2 + 11.56*kt3)
1492-
b = np.where(bools,
1493-
0.37 + 0.962*kt,
1494-
41.4 - 118.5*kt + 66.05*kt2 + 31.9*kt3)
1495-
c = np.where(bools,
1496-
-0.28 + 0.932*kt - 2.048*kt2,
1497-
-47.01 + 184.2*kt - 222.0*kt2 + 73.81*kt3)
1484+
is_cloudy = (kt <= 0.6)
1485+
# Use Horner's method to compute polynomials efficiently
1486+
a = np.where(
1487+
is_cloudy,
1488+
0.512 + kt*(-1.56 + kt*(2.286 - 2.222*kt)),
1489+
-5.743 + kt*(21.77 + kt*(-27.49 + 11.56*kt)))
1490+
b = np.where(
1491+
is_cloudy,
1492+
0.37 + 0.962*kt,
1493+
41.4 + kt*(-118.5 + kt*(66.05 + 31.9*kt)))
1494+
c = np.where(
1495+
is_cloudy,
1496+
-0.28 + kt*(0.932 - 2.048*kt),
1497+
-47.01 + kt*(184.2 + kt*(-222.0 + 73.81*kt)))
14981498

14991499
delta_kn = a + b * np.exp(c*am)
15001500

1501-
Knc = 0.866 - 0.122*am + 0.0121*am**2 - 0.000653*am**3 + 1.4e-05*am**4
1501+
Knc = 0.866 + am*(-0.122 + am*(0.0121 + am*(-0.000653 + 1.4e-05*am)))
15021502
Kn = Knc - delta_kn
15031503
return Kn, am
15041504

0 commit comments

Comments
 (0)