Skip to content

Commit 3c6ef52

Browse files
committed
Merge remote-tracking branch 'upstream/main' into glossary
2 parents 7d6a0ac + 1c65dca commit 3c6ef52

File tree

8 files changed

+173
-34
lines changed

8 files changed

+173
-34
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Contributing
8181
============
8282

8383
We need your help to make pvlib-python a great tool!
84-
Please see the [Contributing page](http://pvlib-python.readthedocs.io/en/stable/contributing.html) for more on how you can contribute.
84+
Please see the [Contributing page](https://pvlib-python.readthedocs.io/en/stable/contributing/index.html) for more on how you can contribute.
8585
The long-term success of pvlib-python requires substantial community support.
8686

8787

docs/sphinx/source/contributing/testing.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.. _testing:
22

3-
Testing
4-
=======
3+
Testing and benchmarking
4+
========================
55

66
.. _overview:
77

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ Enhancements
1515
Documentation
1616
~~~~~~~~~~~~~
1717
* Edited docstrings for :py:func:`~pvlib.pvsystem.dc_ohms_from_percent` and
18-
:py:func:`~pvlib.pvsystem.dc_ohmic_loss` for clarity. (:issue:`1601`, :pull:`2229`)
19-
18+
:py:func:`~pvlib.pvsystem.dc_ohmic_losses` for clarity. (:issue:`1601`, :pull:`2229`)
19+
* Updated :py:func:`~pvlib.irradiance.reindl` to include definitions of terms
20+
and a new "notes" section (:issue:`2183`, :pull:`2193`)
2021

2122
Testing
2223
~~~~~~~
@@ -29,4 +30,5 @@ Requirements
2930
Contributors
3031
~~~~~~~~~~~~
3132
* Cliff Hansen (:ghuser:`cwhanse`)
33+
* Rajiv Daxini (:ghuser:`RDaxini`)
3234

pvlib/_deprecation.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,76 @@ def wrapper(*args, **kwargs):
316316
return finalize(wrapper, new_doc)
317317

318318
return deprecate
319+
320+
321+
def renamed_kwarg_warning(since, old_param_name, new_param_name, removal=""):
322+
"""
323+
Decorator to mark a possible keyword argument as deprecated and replaced
324+
with other name.
325+
326+
Raises a warning when the deprecated argument is used, and replaces the
327+
call with the new argument name. Does not modify the function signature.
328+
329+
.. warning::
330+
Ensure ``removal`` date with a ``fail_on_pvlib_version`` decorator in
331+
the test suite.
332+
333+
.. note::
334+
Not compatible with positional-only arguments.
335+
336+
.. note::
337+
Documentation for the function may updated to reflect the new parameter
338+
name; it is suggested to add a |.. versionchanged::| directive.
339+
340+
Parameters
341+
----------
342+
since : str
343+
The release at which this API became deprecated.
344+
old_param_name : str
345+
The name of the deprecated parameter.
346+
new_param_name : str
347+
The name of the new parameter.
348+
removal : str, optional
349+
The expected removal version, in order to compose the Warning message.
350+
351+
Examples
352+
--------
353+
>>> @renamed_kwarg_warning("1.4.0", "old_name", "new_name", "1.6.0")
354+
>>> def some_function(new_name=None):
355+
>>> pass
356+
>>> some_function(old_name=1)
357+
Parameter 'old_name' has been renamed since 1.4.0. and
358+
will be removed in 1.6.0. Please use 'new_name' instead.
359+
360+
>>> @renamed_kwarg_warning("1.4.0", "old_name", "new_name")
361+
>>> def some_function(new_name=None):
362+
>>> pass
363+
>>> some_function(old_name=1)
364+
Parameter 'old_name' has been renamed since 1.4.0. and
365+
will be removed soon. Please use 'new_name' instead.
366+
"""
367+
368+
def deprecate(func, old=old_param_name, new=new_param_name, since=since):
369+
def wrapper(*args, **kwargs):
370+
if old in kwargs:
371+
if new in kwargs:
372+
raise ValueError(
373+
f"{func.__name__} received both '{old}' and '{new}', "
374+
"which are mutually exclusive since they refer to the "
375+
f"same parameter. Please remove deprecated '{old}'."
376+
)
377+
warnings.warn(
378+
f"Parameter '{old}' has been renamed since {since}. "
379+
f"and will be removed "
380+
+ (f"in {removal}" if removal else "soon")
381+
+ f". Please use '{new}' instead.",
382+
_projectWarning,
383+
stacklevel=2,
384+
)
385+
kwargs[new] = kwargs.pop(old)
386+
return func(*args, **kwargs)
387+
388+
wrapper = functools.wraps(func)(wrapper)
389+
return wrapper
390+
391+
return deprecate

pvlib/iam.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ def martin_ruiz(aoi, a_r=0.16):
269269
270270
which is presented as :math:`AL(\alpha) = 1 - IAM` in equation 4 of [1]_,
271271
with :math:`\alpha` representing the angle of incidence AOI. Thus IAM = 1
272-
at AOI = 0, and IAM = 0 at AOI = 90. This equation is only valid for
273-
-90 <= aoi <= 90, therefore `iam` is constrained to 0.0 outside this
272+
at AOI = 0°, and IAM = 0 at AOI = 90°. This equation is only valid for
273+
<= aoi <= 90°, therefore `iam` is constrained to 0.0 outside this
274274
interval.
275275
276276
References
@@ -891,8 +891,8 @@ def schlick_diffuse(surface_tilt):
891891
implements only the integrated Schlick approximation.
892892
893893
Note also that the output of this function (which is an exact integration)
894-
can be compared with the output of :py:func:`marion_diffuse` which numerically
895-
integrates the Schlick approximation:
894+
can be compared with the output of :py:func:`marion_diffuse` which
895+
numerically integrates the Schlick approximation:
896896
897897
.. code::
898898

pvlib/irradiance.py

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -869,19 +869,14 @@ def haydavies(surface_tilt, surface_azimuth, dhi, dni, dni_extra,
869869
def reindl(surface_tilt, surface_azimuth, dhi, dni, ghi, dni_extra,
870870
solar_zenith, solar_azimuth):
871871
r'''
872-
Determine diffuse irradiance from the sky on a tilted surface using
873-
Reindl's 1990 model
874-
875-
.. math::
872+
Determine the diffuse irradiance from the sky on a tilted surface using
873+
the Reindl (1990) model.
876874
877-
I_{d} = DHI \left(A R_b + (1 - A) \left(\frac{1 + \cos\beta}{2}\right)
878-
\left(1 + \sqrt{\frac{I_{hb}}{I_h}} \sin^3(\beta/2)\right) \right)
879-
880-
Reindl's 1990 model determines the diffuse irradiance from the sky
881-
(ground reflected irradiance is not included in this algorithm) on a
882-
tilted surface using the surface tilt angle, surface azimuth angle,
875+
The Reindl (1990) model [1]_ [2]_ determines the diffuse irradiance from
876+
the sky on
877+
a tilted surface using the surface tilt angle, surface azimuth angle,
883878
diffuse horizontal irradiance, direct normal irradiance, global
884-
horizontal irradiance, extraterrestrial irradiance, sun zenith
879+
horizontal irradiance, extraterrestrial normal irradiance, sun zenith
885880
angle, and sun azimuth angle.
886881
887882
Parameters
@@ -903,7 +898,7 @@ def reindl(surface_tilt, surface_azimuth, dhi, dni, ghi, dni_extra,
903898
direct normal irradiance. [Wm⁻²]
904899
905900
ghi: numeric
906-
Global irradiance. [Wm⁻²]
901+
Global horizontal irradiance. [Wm⁻²]
907902
908903
dni_extra : numeric
909904
Extraterrestrial normal irradiance. [Wm⁻²]
@@ -923,23 +918,41 @@ def reindl(surface_tilt, surface_azimuth, dhi, dni, ghi, dni_extra,
923918
924919
Notes
925920
-----
926-
The poa_sky_diffuse calculation is generated from the Loutzenhiser et al.
927-
(2007) paper, equation 8. Note that I have removed the beam and ground
928-
reflectance portion of the equation and this generates ONLY the diffuse
929-
radiation from the sky and circumsolar, so the form of the equation
930-
varies slightly from equation 8.
921+
The Reindl (1990) model for the sky diffuse irradiance,
922+
:math:`I_d`, is as follows:
923+
924+
.. math::
925+
926+
I_{d} = DHI \left(A \cdot R_b + (1 - A)
927+
\left(\frac{1 + \cos\beta}{2}\right)
928+
\left(1 + \sqrt{\frac{BHI}{GHI}} \sin^3(\beta/2)\right) \right).
929+
930+
:math:`DHI`, :math:`BHI`, and :math:`GHI` are the diffuse horizontal, beam
931+
(direct) horizontal and global horizontal irradiances, respectively.
932+
:math:`A` is the anisotropy index, which is the ratio of the direct normal
933+
irradiance to the direct extraterrestrial irradiation, :math:`R_b` is the
934+
projection ratio, which is defined as the ratio of the cosine of the angle
935+
of incidence (AOI) to the cosine of the zenith angle, and :math:`\beta`
936+
is the tilt angle of the array.
937+
938+
Implementation is based on Loutzenhiser et al.
939+
(2007) [3]_, Equation 8. The beam and ground reflectance portion of the
940+
equation have been removed, therefore the model described here generates
941+
ONLY the diffuse radiation from the sky and circumsolar, so the form of the
942+
equation varies slightly from Equation 8 in [3]_.
931943
932944
References
933945
----------
934-
.. [1] Loutzenhiser P.G. et. al. "Empirical validation of models to
935-
compute solar irradiance on inclined surfaces for building energy
936-
simulation" 2007, Solar Energy vol. 81. pp. 254-267
937-
938-
.. [2] Reindl, D.T., Beckmann, W.A., Duffie, J.A., 1990a. Diffuse
946+
.. [1] Reindl, D. T., Beckmann, W. A., Duffie, J. A., 1990a. Diffuse
939947
fraction correlations. Solar Energy 45(1), 1-7.
940-
941-
.. [3] Reindl, D.T., Beckmann, W.A., Duffie, J.A., 1990b. Evaluation of
948+
:doi:`10.1016/0038-092X(90)90060-P`
949+
.. [2] Reindl, D. T., Beckmann, W. A., Duffie, J. A., 1990b. Evaluation of
942950
hourly tilted surface radiation models. Solar Energy 45(1), 9-17.
951+
:doi:`10.1016/0038-092X(90)90061-G`
952+
.. [3] Loutzenhiser P. G. et. al., 2007. Empirical validation of models to
953+
compute solar irradiance on inclined surfaces for building energy
954+
simulation. Solar Energy 81(2), 254-267
955+
:doi:`10.1016/j.solener.2006.03.009`
943956
'''
944957

945958
cos_tt = aoi_projection(surface_tilt, surface_azimuth,

pvlib/pvsystem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2952,7 +2952,7 @@ def dc_ohmic_losses(resistance, current):
29522952
29532953
.. math::
29542954
2955-
L = I \times R^2
2955+
L = I^2 \times R
29562956
29572957
where :math:`I` is the current (A) and :math:`R` is the resistance of the
29582958
conductor (ohms).

pvlib/tests/test__deprecation.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""
2+
Test the _deprecation module.
3+
"""
4+
5+
import pytest
6+
7+
from pvlib import _deprecation
8+
9+
import warnings
10+
11+
12+
@pytest.fixture
13+
def renamed_kwarg_func():
14+
"""Returns a function decorated by renamed_kwarg_warning.
15+
This function is called 'func' and has a docstring equal to 'docstring'.
16+
"""
17+
18+
@_deprecation.renamed_kwarg_warning(
19+
"0.1.0", "old_kwarg", "new_kwarg", "0.2.0"
20+
)
21+
def func(new_kwarg):
22+
"""docstring"""
23+
return new_kwarg
24+
25+
return func
26+
27+
28+
def test_renamed_kwarg_warning(renamed_kwarg_func):
29+
# assert decorated function name and docstring are unchanged
30+
assert renamed_kwarg_func.__name__ == "func"
31+
assert renamed_kwarg_func.__doc__ == "docstring"
32+
33+
# assert no warning is raised when using the new kwarg
34+
with warnings.catch_warnings():
35+
warnings.simplefilter("error")
36+
assert renamed_kwarg_func(new_kwarg=1) == 1 # as keyword argument
37+
assert renamed_kwarg_func(1) == 1 # as positional argument
38+
39+
# assert a warning is raised when using the old kwarg
40+
with pytest.warns(Warning, match="Parameter 'old_kwarg' has been renamed"):
41+
assert renamed_kwarg_func(old_kwarg=1) == 1
42+
43+
# assert an error is raised when using both the old and new kwarg
44+
with pytest.raises(ValueError, match="they refer to the same parameter."):
45+
renamed_kwarg_func(old_kwarg=1, new_kwarg=2)
46+
47+
# assert when not providing any of them
48+
with pytest.raises(
49+
TypeError, match="missing 1 required positional argument"
50+
):
51+
renamed_kwarg_func()

0 commit comments

Comments
 (0)