From c07ae1d046faed7f5dec311867fd7486e3793777 Mon Sep 17 00:00:00 2001 From: Ioannis Sifnaios Date: Mon, 17 Jun 2024 18:43:35 +0200 Subject: [PATCH 1/9] Move albedo dictionary --- pvlib/albedo.py | 21 ++++++++++++++++++++- pvlib/irradiance.py | 19 +++++++++++++++++-- pvlib/pvsystem.py | 13 +++++++------ pvlib/tests/test_irradiance.py | 6 ++++++ 4 files changed, 50 insertions(+), 9 deletions(-) diff --git a/pvlib/albedo.py b/pvlib/albedo.py index 98b920dddb..6e3bf8e419 100644 --- a/pvlib/albedo.py +++ b/pvlib/albedo.py @@ -7,6 +7,25 @@ import pandas as pd +# Sources of for the albedo values are provided in +# pvlib.irradiance.get_ground_diffuse. +SURFACE_ALBEDOS = { + 'urban': 0.18, + 'grass': 0.20, + 'fresh grass': 0.26, + 'soil': 0.17, + 'sand': 0.40, + 'snow': 0.65, + 'fresh snow': 0.75, + 'asphalt': 0.12, + 'concrete': 0.30, + 'aluminum': 0.85, + 'copper': 0.74, + 'fresh steel': 0.35, + 'dirty steel': 0.08, + 'sea': 0.06, +} + WATER_COLOR_COEFFS = { 'clear_water_no_waves': 0.13, 'clear_water_ripples_up_to_2.5cm': 0.16, @@ -33,7 +52,7 @@ def inland_water_dvoracek(solar_elevation, surface_condition=None, The available surface conditions are for inland water bodies, e.g., lakes and ponds. For ocean/open sea, see - :const:`pvlib.irradiance.SURFACE_ALBEDOS`. + :const:`pvlib.albedo.SURFACE_ALBEDOS`. Parameters ---------- diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index d2f494021d..e73507d8de 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -16,6 +16,21 @@ from pvlib import atmosphere, solarposition, tools import pvlib # used to avoid dni name collision in complete_irradiance +import sys, warnings + +def WrapMod(mod, deprecated): + """Return a wrapped object that warns about deprecated accesses""" + class Wrapper(object): + def __getattr__(self, attr): + if attr in deprecated: + warnings.warn("%s is deprecated as of v0.11.0" % attr) + return getattr(mod, attr) + return Wrapper() + + +sys.modules[__name__] = WrapMod(sys.modules[__name__], + deprecated=['SURFACE_ALBEDOS']) + # see References section of get_ground_diffuse function SURFACE_ALBEDOS = {'urban': 0.18, @@ -550,7 +565,7 @@ def get_ground_diffuse(surface_tilt, ghi, albedo=.25, surface_type=None): Notes ----- Table of albedo values by ``surface_type`` are from [2]_, [3]_, [4]_; - see :py:data:`~pvlib.irradiance.SURFACE_ALBEDOS`. + see :py:data:`~pvlib.albedo.SURFACE_ALBEDOS`. References ---------- @@ -565,7 +580,7 @@ def get_ground_diffuse(surface_tilt, ghi, albedo=.25, surface_type=None): ''' if surface_type is not None: - albedo = SURFACE_ALBEDOS[surface_type] + albedo = pvlib.albedo.SURFACE_ALBEDOS[surface_type] diffuse_irrad = ghi * albedo * (1 - np.cos(np.radians(surface_tilt))) * 0.5 diff --git a/pvlib/pvsystem.py b/pvlib/pvsystem.py index 0f0a41c87a..68e5af36ed 100644 --- a/pvlib/pvsystem.py +++ b/pvlib/pvsystem.py @@ -19,6 +19,7 @@ from pvlib._deprecation import deprecated, warn_deprecated +import pvlib # used to avoid albedo name collision in the Array class from pvlib import (atmosphere, iam, inverter, irradiance, singlediode as _singlediode, spectrum, temperature) from pvlib.tools import _build_kwargs, _build_args @@ -131,12 +132,12 @@ class PVSystem: albedo : float, optional Ground surface albedo. If not supplied, then ``surface_type`` is used - to look up a value in ``irradiance.SURFACE_ALBEDOS``. + to look up a value in :const:`pvlib.albedo.SURFACE_ALBEDOS`. If ``surface_type`` is also not supplied then a ground surface albedo of 0.25 is used. surface_type : string, optional - The ground surface type. See ``irradiance.SURFACE_ALBEDOS`` for + The ground surface type. See :const:`pvlib.albedo.SURFACE_ALBEDOS` for valid values. module : string, optional @@ -907,13 +908,13 @@ class Array: albedo : float, optional Ground surface albedo. If not supplied, then ``surface_type`` is used - to look up a value in ``irradiance.SURFACE_ALBEDOS``. + to look up a value in :const:`pvlib.albedo.SURFACE_ALBEDOS`. If ``surface_type`` is also not supplied then a ground surface albedo of 0.25 is used. surface_type : string, optional - The ground surface type. See ``irradiance.SURFACE_ALBEDOS`` for valid - values. + The ground surface type. See :const:`pvlib.albedo.SURFACE_ALBEDOS` for + valid values. module : string, optional The model name of the modules. @@ -956,7 +957,7 @@ def __init__(self, mount, self.surface_type = surface_type if albedo is None: - self.albedo = irradiance.SURFACE_ALBEDOS.get(surface_type, 0.25) + self.albedo = pvlib.albedo.SURFACE_ALBEDOS.get(surface_type, 0.25) else: self.albedo = albedo diff --git a/pvlib/tests/test_irradiance.py b/pvlib/tests/test_irradiance.py index c855c88d73..74cd08e67f 100644 --- a/pvlib/tests/test_irradiance.py +++ b/pvlib/tests/test_irradiance.py @@ -1406,3 +1406,9 @@ def test_louche(): out = irradiance.louche(ghi, zenith, index) assert_frame_equal(out, expected) + + +def test_SURFACE_ALBEDOS_deprecation(): + with pytest.warns(UserWarning, match='SURFACE_ALBEDOS is deprecated as of' + ' v0.11.0'): + irradiance.SURFACE_ALBEDOS From 0e8b27d591e90ad1d56068f03803138eb8957982 Mon Sep 17 00:00:00 2001 From: Ioannis Sifnaios Date: Mon, 17 Jun 2024 18:49:38 +0200 Subject: [PATCH 2/9] fixed linter --- pvlib/irradiance.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index e73507d8de..75b37e992b 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -2821,8 +2821,8 @@ def orgill_hollands(ghi, zenith, datetime_or_doy, dni_extra=None, References ---------- .. [1] Orgill, J.F., Hollands, K.G.T., Correlation equation for hourly - diffuse radiation on a horizontal surface, Solar Energy 19(4), pp 357–359, - 1977. Eqs. 3(a), 3(b) and 3(c) + diffuse radiation on a horizontal surface, Solar Energy 19(4), + pp 357–359, 1977. Eqs. 3(a), 3(b) and 3(c) :doi:`10.1016/0038-092X(77)90006-8` See Also From 796d370520d79e48d2af9e2e610f24c7b7e21cad Mon Sep 17 00:00:00 2001 From: Ioannis Sifnaios Date: Mon, 17 Jun 2024 18:52:23 +0200 Subject: [PATCH 3/9] fixed linter vol.2 --- pvlib/irradiance.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index 75b37e992b..3568b4927e 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -16,7 +16,9 @@ from pvlib import atmosphere, solarposition, tools import pvlib # used to avoid dni name collision in complete_irradiance -import sys, warnings +import sys +import warnings + def WrapMod(mod, deprecated): """Return a wrapped object that warns about deprecated accesses""" @@ -2457,7 +2459,6 @@ def _gti_dirint_lt_90(poa_global, aoi, aoi_lt_90, solar_zenith, solar_azimuth, else: # we are here because we ran out of coeffs to loop over and # therefore we have exceeded max_iterations - import warnings failed_points = best_diff[aoi_lt_90][~best_diff_lte_1_lt_90] warnings.warn( ('%s points failed to converge after %s iterations. best_diff:\n%s' From 33333d53251b7132d7e75b2468e2f5af0fd35734 Mon Sep 17 00:00:00 2001 From: Ioannis Sifnaios Date: Mon, 17 Jun 2024 19:08:51 +0200 Subject: [PATCH 4/9] Update v0.11.0.rst --- docs/sphinx/source/whatsnew/v0.11.0.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/sphinx/source/whatsnew/v0.11.0.rst b/docs/sphinx/source/whatsnew/v0.11.0.rst index 3fa2aa41df..faa82dc5b7 100644 --- a/docs/sphinx/source/whatsnew/v0.11.0.rst +++ b/docs/sphinx/source/whatsnew/v0.11.0.rst @@ -20,6 +20,8 @@ Breaking changes Deprecations ~~~~~~~~~~~~ +* The ``pvlib.irradiance.SURFACE_ALBEDOS`` dictionary has been moved to the + ``albedo.py`` module. (:pull:`2095`) Enhancements From 701886b6f2144970140bdd39adf7da78337d5dd8 Mon Sep 17 00:00:00 2001 From: Ioannis Sifnaios Date: Tue, 18 Jun 2024 12:40:39 +0200 Subject: [PATCH 5/9] Move surface_albedos dict to albedo.py --- docs/sphinx/source/whatsnew.rst | 1 + docs/sphinx/source/whatsnew/v0.11.0.rst | 8 ++-- pvlib/irradiance.py | 51 ++++++++++++------------- pvlib/tests/test_irradiance.py | 8 ++-- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/docs/sphinx/source/whatsnew.rst b/docs/sphinx/source/whatsnew.rst index 66c7196333..6baff55247 100644 --- a/docs/sphinx/source/whatsnew.rst +++ b/docs/sphinx/source/whatsnew.rst @@ -6,6 +6,7 @@ What's New These are new features and improvements of note in each release. +.. include:: whatsnew/v0.11.0.rst .. include:: whatsnew/v0.10.5.rst .. include:: whatsnew/v0.10.4.rst .. include:: whatsnew/v0.10.3.rst diff --git a/docs/sphinx/source/whatsnew/v0.11.0.rst b/docs/sphinx/source/whatsnew/v0.11.0.rst index faa82dc5b7..ff1084e57c 100644 --- a/docs/sphinx/source/whatsnew/v0.11.0.rst +++ b/docs/sphinx/source/whatsnew/v0.11.0.rst @@ -8,20 +8,20 @@ v0.11.0 (Anticipated June, 2024) Breaking changes ~~~~~~~~~~~~~~~~ * The deprecated ``pvlib.modelchain.basic_chain`` has now been removed. (:pull:`1862`) -* Remove the `poa_horizontal_ratio` function and all of its references. (:issue:`1697`, :pull:`2021`) +* Remove the ``poa_horizontal_ratio`` function and all of its references. (:issue:`1697`, :pull:`2021`) * Updated `~pvlib.iotools.MIDC_VARIABLE_MAP`~ to reflect changes in instrumentation. (:pull:`2006`) * ``pvlib.iotools.read_srml_month_from_solardat`` was deprecated in v0.10.0 and has now been completely removed. The function is replaced by :py:func:`~pvlib.iotools.get_srml()`. (:pull:`1779`, :pull:`1989`) -* The `leap_day` parameter in :py:func:`~pvlib.iotools.get_psm3` +* The ``leap_day`` parameter in :py:func:`~pvlib.iotools.get_psm3` now defaults to True instead of False. (:issue:`1481`, :pull:`1991`) Deprecations ~~~~~~~~~~~~ -* The ``pvlib.irradiance.SURFACE_ALBEDOS`` dictionary has been moved to the - ``albedo.py`` module. (:pull:`2095`) +* The ``pvlib.irradiance.SURFACE_ALBEDOS`` dictionary has been moved to + :py:const:`pvlib.albedo.SURFACE_ALBEDOS`. (:pull:`2095`) Enhancements diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index 3568b4927e..6fc342967d 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -16,39 +16,36 @@ from pvlib import atmosphere, solarposition, tools import pvlib # used to avoid dni name collision in complete_irradiance -import sys +from pvlib._deprecation import pvlibDeprecationWarning import warnings -def WrapMod(mod, deprecated): - """Return a wrapped object that warns about deprecated accesses""" - class Wrapper(object): - def __getattr__(self, attr): - if attr in deprecated: - warnings.warn("%s is deprecated as of v0.11.0" % attr) - return getattr(mod, attr) - return Wrapper() - - -sys.modules[__name__] = WrapMod(sys.modules[__name__], - deprecated=['SURFACE_ALBEDOS']) +# Deprecation warning based on https://peps.python.org/pep-0562/ +def __getattr__(attr): + if attr in ['SURFACE_ALBEDOS']: + warnings.warn(f"{attr} has been moved to the albedo module as of " + "v0.11.0. Please use pvlib.albedo.SURFACE_ALBEDOS.", + pvlibDeprecationWarning) + return globals()[f"_DEPRECATED_{attr}"] + raise AttributeError(f"module {__name__!r} has no attribute {attr!r}") # see References section of get_ground_diffuse function -SURFACE_ALBEDOS = {'urban': 0.18, - 'grass': 0.20, - 'fresh grass': 0.26, - 'soil': 0.17, - 'sand': 0.40, - 'snow': 0.65, - 'fresh snow': 0.75, - 'asphalt': 0.12, - 'concrete': 0.30, - 'aluminum': 0.85, - 'copper': 0.74, - 'fresh steel': 0.35, - 'dirty steel': 0.08, - 'sea': 0.06} +_DEPRECATED_SURFACE_ALBEDOS = { + 'urban': 0.18, + 'grass': 0.20, + 'fresh grass': 0.26, + 'soil': 0.17, + 'sand': 0.40, + 'snow': 0.65, + 'fresh snow': 0.75, + 'asphalt': 0.12, + 'concrete': 0.30, + 'aluminum': 0.85, + 'copper': 0.74, + 'fresh steel': 0.35, + 'dirty steel': 0.08, + 'sea': 0.06} def get_extra_radiation(datetime_or_doy, solar_constant=1366.1, diff --git a/pvlib/tests/test_irradiance.py b/pvlib/tests/test_irradiance.py index 74cd08e67f..45d99f2065 100644 --- a/pvlib/tests/test_irradiance.py +++ b/pvlib/tests/test_irradiance.py @@ -18,6 +18,7 @@ requires_numba ) +from pvlib._deprecation import pvlibDeprecationWarning # fixtures create realistic test input data # test input data generated at Location(32.2, -111, 'US/Arizona', 700) @@ -1408,7 +1409,8 @@ def test_louche(): assert_frame_equal(out, expected) -def test_SURFACE_ALBEDOS_deprecation(): - with pytest.warns(UserWarning, match='SURFACE_ALBEDOS is deprecated as of' - ' v0.11.0'): +def test_SURFACE_ALBEDOS_deprecated(): + with pytest.warns(pvlibDeprecationWarning, match='SURFACE_ALBEDOS has been' + ' moved to the albedo module as of v0.11.0. Please use' + ' pvlib.albedo.SURFACE_ALBEDOS.'): irradiance.SURFACE_ALBEDOS From bb1ddaf41dbeeb4b9519ea92d392e85db3b25076 Mon Sep 17 00:00:00 2001 From: Ioannis Sifnaios Date: Tue, 18 Jun 2024 13:04:39 +0200 Subject: [PATCH 6/9] changed parameter type in documentation --- pvlib/irradiance.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index 6fc342967d..f616845812 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -564,7 +564,7 @@ def get_ground_diffuse(surface_tilt, ghi, albedo=.25, surface_type=None): Notes ----- Table of albedo values by ``surface_type`` are from [2]_, [3]_, [4]_; - see :py:data:`~pvlib.albedo.SURFACE_ALBEDOS`. + see :py:const:`~pvlib.albedo.SURFACE_ALBEDOS`. References ---------- From 05c14c0d4ec4700c31f7fcd63d148a5ca885ac0a Mon Sep 17 00:00:00 2001 From: Ioannis Sifnaios Date: Tue, 18 Jun 2024 13:38:26 +0200 Subject: [PATCH 7/9] fixed parameter type --- pvlib/pvsystem.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pvlib/pvsystem.py b/pvlib/pvsystem.py index 68e5af36ed..385760c967 100644 --- a/pvlib/pvsystem.py +++ b/pvlib/pvsystem.py @@ -132,13 +132,13 @@ class PVSystem: albedo : float, optional Ground surface albedo. If not supplied, then ``surface_type`` is used - to look up a value in :const:`pvlib.albedo.SURFACE_ALBEDOS`. + to look up a value in :py:const:`pvlib.albedo.SURFACE_ALBEDOS`. If ``surface_type`` is also not supplied then a ground surface albedo of 0.25 is used. surface_type : string, optional - The ground surface type. See :const:`pvlib.albedo.SURFACE_ALBEDOS` for - valid values. + The ground surface type. See :py:const:`pvlib.albedo.SURFACE_ALBEDOS` + for valid values. module : string, optional The model name of the modules. @@ -908,13 +908,13 @@ class Array: albedo : float, optional Ground surface albedo. If not supplied, then ``surface_type`` is used - to look up a value in :const:`pvlib.albedo.SURFACE_ALBEDOS`. + to look up a value in :py:const:`pvlib.albedo.SURFACE_ALBEDOS`. If ``surface_type`` is also not supplied then a ground surface albedo of 0.25 is used. surface_type : string, optional - The ground surface type. See :const:`pvlib.albedo.SURFACE_ALBEDOS` for - valid values. + The ground surface type. See :py:const:`pvlib.albedo.SURFACE_ALBEDOS` + for valid values. module : string, optional The model name of the modules. From d0749f75677f0e6e094b94b929ac4f0158969b77 Mon Sep 17 00:00:00 2001 From: Ioannis Sifnaios Date: Tue, 18 Jun 2024 13:40:43 +0200 Subject: [PATCH 8/9] fixed parameter type --- pvlib/albedo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pvlib/albedo.py b/pvlib/albedo.py index 6e3bf8e419..2dca47ef3d 100644 --- a/pvlib/albedo.py +++ b/pvlib/albedo.py @@ -52,7 +52,7 @@ def inland_water_dvoracek(solar_elevation, surface_condition=None, The available surface conditions are for inland water bodies, e.g., lakes and ponds. For ocean/open sea, see - :const:`pvlib.albedo.SURFACE_ALBEDOS`. + :py:const:`pvlib.albedo.SURFACE_ALBEDOS`. Parameters ---------- From 42942da615c0aabac493d746ce78671607b17cca Mon Sep 17 00:00:00 2001 From: Ioannis Sifnaios Date: Tue, 18 Jun 2024 19:28:23 +0200 Subject: [PATCH 9/9] Implemented feedback form Kevin --- pvlib/irradiance.py | 22 ++-------------------- pvlib/tests/test_irradiance.py | 7 ++++++- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index 60d01b8fa0..73448b6d6d 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -22,32 +22,14 @@ # Deprecation warning based on https://peps.python.org/pep-0562/ def __getattr__(attr): - if attr in ['SURFACE_ALBEDOS']: + if attr == 'SURFACE_ALBEDOS': warnings.warn(f"{attr} has been moved to the albedo module as of " "v0.11.0. Please use pvlib.albedo.SURFACE_ALBEDOS.", pvlibDeprecationWarning) - return globals()[f"_DEPRECATED_{attr}"] + return pvlib.albedo.SURFACE_ALBEDOS raise AttributeError(f"module {__name__!r} has no attribute {attr!r}") -# see References section of get_ground_diffuse function -_DEPRECATED_SURFACE_ALBEDOS = { - 'urban': 0.18, - 'grass': 0.20, - 'fresh grass': 0.26, - 'soil': 0.17, - 'sand': 0.40, - 'snow': 0.65, - 'fresh snow': 0.75, - 'asphalt': 0.12, - 'concrete': 0.30, - 'aluminum': 0.85, - 'copper': 0.74, - 'fresh steel': 0.35, - 'dirty steel': 0.08, - 'sea': 0.06} - - def get_extra_radiation(datetime_or_doy, solar_constant=1366.1, method='spencer', epoch_year=2014, **kwargs): """ diff --git a/pvlib/tests/test_irradiance.py b/pvlib/tests/test_irradiance.py index 45d99f2065..19ce0790ee 100644 --- a/pvlib/tests/test_irradiance.py +++ b/pvlib/tests/test_irradiance.py @@ -9,7 +9,7 @@ import pytest from numpy.testing import (assert_almost_equal, assert_allclose) -from pvlib import irradiance +from pvlib import irradiance, albedo from .conftest import ( assert_frame_equal, @@ -1414,3 +1414,8 @@ def test_SURFACE_ALBEDOS_deprecated(): ' moved to the albedo module as of v0.11.0. Please use' ' pvlib.albedo.SURFACE_ALBEDOS.'): irradiance.SURFACE_ALBEDOS + + +@pytest.mark.filterwarnings("ignore:SURFACE_ALBEDOS") +def test_SURFACE_ALBEDO_equals(): + assert irradiance.SURFACE_ALBEDOS == albedo.SURFACE_ALBEDOS