Skip to content

Commit 1eecaa3

Browse files
Move albedo dictionary from pvlib.irradiance to pvlib.albedo (#2095)
* Move albedo dictionary * fixed linter * fixed linter vol.2 * Update v0.11.0.rst * Move surface_albedos dict to albedo.py * changed parameter type in documentation * fixed parameter type * fixed parameter type * Implemented feedback form Kevin
1 parent cc027e4 commit 1eecaa3

File tree

6 files changed

+62
-31
lines changed

6 files changed

+62
-31
lines changed

docs/sphinx/source/whatsnew.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ What's New
66

77
These are new features and improvements of note in each release.
88

9+
.. include:: whatsnew/v0.11.0.rst
910
.. include:: whatsnew/v0.10.5.rst
1011
.. include:: whatsnew/v0.10.4.rst
1112
.. include:: whatsnew/v0.10.3.rst

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ v0.11.0 (Anticipated June, 2024)
88
Breaking changes
99
~~~~~~~~~~~~~~~~
1010
* The deprecated ``pvlib.modelchain.basic_chain`` has now been removed. (:pull:`1862`)
11-
* Remove the `poa_horizontal_ratio` function and all of its references. (:issue:`1697`, :pull:`2021`)
11+
* Remove the ``poa_horizontal_ratio`` function and all of its references. (:issue:`1697`, :pull:`2021`)
1212
* Updated `~pvlib.iotools.MIDC_VARIABLE_MAP`~ to reflect
1313
changes in instrumentation. (:pull:`2006`)
1414
* ``pvlib.iotools.read_srml_month_from_solardat`` was deprecated in v0.10.0 and has
1515
now been completely removed. The function is replaced by :py:func:`~pvlib.iotools.get_srml()`.
1616
(:pull:`1779`, :pull:`1989`)
17-
* The `leap_day` parameter in :py:func:`~pvlib.iotools.get_psm3`
17+
* The ``leap_day`` parameter in :py:func:`~pvlib.iotools.get_psm3`
1818
now defaults to True instead of False. (:issue:`1481`, :pull:`1991`)
1919
* :py:func:`~pvlib.iotools.get_psm3`, :py:func:`~pvlib.iotools.read_psm3`, and
2020
:py:func:`~pvlib.iotools.parse_psm3` all now have ``map_variables=True`` by
@@ -23,6 +23,8 @@ Breaking changes
2323

2424
Deprecations
2525
~~~~~~~~~~~~
26+
* The ``pvlib.irradiance.SURFACE_ALBEDOS`` dictionary has been moved to
27+
:py:const:`pvlib.albedo.SURFACE_ALBEDOS`. (:pull:`2095`)
2628
* Function :py:func:`pvlib.spectrum.get_am15g` has been deprecated in favor
2729
of the new function :py:func:`pvlib.spectrum.get_reference_spectra`. Use
2830
``pvlib.spectrum.get_reference_spectra(standard="ASTM G173-03")["global"]``

pvlib/albedo.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@
77
import pandas as pd
88

99

10+
# Sources of for the albedo values are provided in
11+
# pvlib.irradiance.get_ground_diffuse.
12+
SURFACE_ALBEDOS = {
13+
'urban': 0.18,
14+
'grass': 0.20,
15+
'fresh grass': 0.26,
16+
'soil': 0.17,
17+
'sand': 0.40,
18+
'snow': 0.65,
19+
'fresh snow': 0.75,
20+
'asphalt': 0.12,
21+
'concrete': 0.30,
22+
'aluminum': 0.85,
23+
'copper': 0.74,
24+
'fresh steel': 0.35,
25+
'dirty steel': 0.08,
26+
'sea': 0.06,
27+
}
28+
1029
WATER_COLOR_COEFFS = {
1130
'clear_water_no_waves': 0.13,
1231
'clear_water_ripples_up_to_2.5cm': 0.16,
@@ -33,7 +52,7 @@ def inland_water_dvoracek(solar_elevation, surface_condition=None,
3352
3453
The available surface conditions are for inland water bodies, e.g., lakes
3554
and ponds. For ocean/open sea, see
36-
:const:`pvlib.irradiance.SURFACE_ALBEDOS`.
55+
:py:const:`pvlib.albedo.SURFACE_ALBEDOS`.
3756
3857
Parameters
3958
----------

pvlib/irradiance.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,18 @@
1616
from pvlib import atmosphere, solarposition, tools
1717
import pvlib # used to avoid dni name collision in complete_irradiance
1818

19+
from pvlib._deprecation import pvlibDeprecationWarning
20+
import warnings
1921

20-
# see References section of get_ground_diffuse function
21-
SURFACE_ALBEDOS = {'urban': 0.18,
22-
'grass': 0.20,
23-
'fresh grass': 0.26,
24-
'soil': 0.17,
25-
'sand': 0.40,
26-
'snow': 0.65,
27-
'fresh snow': 0.75,
28-
'asphalt': 0.12,
29-
'concrete': 0.30,
30-
'aluminum': 0.85,
31-
'copper': 0.74,
32-
'fresh steel': 0.35,
33-
'dirty steel': 0.08,
34-
'sea': 0.06}
22+
23+
# Deprecation warning based on https://peps.python.org/pep-0562/
24+
def __getattr__(attr):
25+
if attr == 'SURFACE_ALBEDOS':
26+
warnings.warn(f"{attr} has been moved to the albedo module as of "
27+
"v0.11.0. Please use pvlib.albedo.SURFACE_ALBEDOS.",
28+
pvlibDeprecationWarning)
29+
return pvlib.albedo.SURFACE_ALBEDOS
30+
raise AttributeError(f"module {__name__!r} has no attribute {attr!r}")
3531

3632

3733
def get_extra_radiation(datetime_or_doy, solar_constant=1366.1,
@@ -550,7 +546,7 @@ def get_ground_diffuse(surface_tilt, ghi, albedo=.25, surface_type=None):
550546
Notes
551547
-----
552548
Table of albedo values by ``surface_type`` are from [2]_, [3]_, [4]_;
553-
see :py:data:`~pvlib.irradiance.SURFACE_ALBEDOS`.
549+
see :py:const:`~pvlib.albedo.SURFACE_ALBEDOS`.
554550
555551
References
556552
----------
@@ -565,7 +561,7 @@ def get_ground_diffuse(surface_tilt, ghi, albedo=.25, surface_type=None):
565561
'''
566562

567563
if surface_type is not None:
568-
albedo = SURFACE_ALBEDOS[surface_type]
564+
albedo = pvlib.albedo.SURFACE_ALBEDOS[surface_type]
569565

570566
diffuse_irrad = ghi * albedo * (1 - np.cos(np.radians(surface_tilt))) * 0.5
571567

@@ -2442,7 +2438,6 @@ def _gti_dirint_lt_90(poa_global, aoi, aoi_lt_90, solar_zenith, solar_azimuth,
24422438
else:
24432439
# we are here because we ran out of coeffs to loop over and
24442440
# therefore we have exceeded max_iterations
2445-
import warnings
24462441
failed_points = best_diff[aoi_lt_90][~best_diff_lte_1_lt_90]
24472442
warnings.warn(
24482443
('%s points failed to converge after %s iterations. best_diff:\n%s'
@@ -2806,8 +2801,8 @@ def orgill_hollands(ghi, zenith, datetime_or_doy, dni_extra=None,
28062801
References
28072802
----------
28082803
.. [1] Orgill, J.F., Hollands, K.G.T., Correlation equation for hourly
2809-
diffuse radiation on a horizontal surface, Solar Energy 19(4), pp 357–359,
2810-
1977. Eqs. 3(a), 3(b) and 3(c)
2804+
diffuse radiation on a horizontal surface, Solar Energy 19(4),
2805+
pp 357–359, 1977. Eqs. 3(a), 3(b) and 3(c)
28112806
:doi:`10.1016/0038-092X(77)90006-8`
28122807
28132808
See Also

pvlib/pvsystem.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from pvlib._deprecation import deprecated, warn_deprecated
2121

22+
import pvlib # used to avoid albedo name collision in the Array class
2223
from pvlib import (atmosphere, iam, inverter, irradiance,
2324
singlediode as _singlediode, spectrum, temperature)
2425
from pvlib.tools import _build_kwargs, _build_args
@@ -131,13 +132,13 @@ class PVSystem:
131132
132133
albedo : float, optional
133134
Ground surface albedo. If not supplied, then ``surface_type`` is used
134-
to look up a value in ``irradiance.SURFACE_ALBEDOS``.
135+
to look up a value in :py:const:`pvlib.albedo.SURFACE_ALBEDOS`.
135136
If ``surface_type`` is also not supplied then a ground surface albedo
136137
of 0.25 is used.
137138
138139
surface_type : string, optional
139-
The ground surface type. See ``irradiance.SURFACE_ALBEDOS`` for
140-
valid values.
140+
The ground surface type. See :py:const:`pvlib.albedo.SURFACE_ALBEDOS`
141+
for valid values.
141142
142143
module : string, optional
143144
The model name of the modules.
@@ -907,13 +908,13 @@ class Array:
907908
908909
albedo : float, optional
909910
Ground surface albedo. If not supplied, then ``surface_type`` is used
910-
to look up a value in ``irradiance.SURFACE_ALBEDOS``.
911+
to look up a value in :py:const:`pvlib.albedo.SURFACE_ALBEDOS`.
911912
If ``surface_type`` is also not supplied then a ground surface albedo
912913
of 0.25 is used.
913914
914915
surface_type : string, optional
915-
The ground surface type. See ``irradiance.SURFACE_ALBEDOS`` for valid
916-
values.
916+
The ground surface type. See :py:const:`pvlib.albedo.SURFACE_ALBEDOS`
917+
for valid values.
917918
918919
module : string, optional
919920
The model name of the modules.
@@ -956,7 +957,7 @@ def __init__(self, mount,
956957

957958
self.surface_type = surface_type
958959
if albedo is None:
959-
self.albedo = irradiance.SURFACE_ALBEDOS.get(surface_type, 0.25)
960+
self.albedo = pvlib.albedo.SURFACE_ALBEDOS.get(surface_type, 0.25)
960961
else:
961962
self.albedo = albedo
962963

pvlib/tests/test_irradiance.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import pytest
1010
from numpy.testing import (assert_almost_equal,
1111
assert_allclose)
12-
from pvlib import irradiance
12+
from pvlib import irradiance, albedo
1313

1414
from .conftest import (
1515
assert_frame_equal,
@@ -18,6 +18,7 @@
1818
requires_numba
1919
)
2020

21+
from pvlib._deprecation import pvlibDeprecationWarning
2122

2223
# fixtures create realistic test input data
2324
# test input data generated at Location(32.2, -111, 'US/Arizona', 700)
@@ -1406,3 +1407,15 @@ def test_louche():
14061407
out = irradiance.louche(ghi, zenith, index)
14071408

14081409
assert_frame_equal(out, expected)
1410+
1411+
1412+
def test_SURFACE_ALBEDOS_deprecated():
1413+
with pytest.warns(pvlibDeprecationWarning, match='SURFACE_ALBEDOS has been'
1414+
' moved to the albedo module as of v0.11.0. Please use'
1415+
' pvlib.albedo.SURFACE_ALBEDOS.'):
1416+
irradiance.SURFACE_ALBEDOS
1417+
1418+
1419+
@pytest.mark.filterwarnings("ignore:SURFACE_ALBEDOS")
1420+
def test_SURFACE_ALBEDO_equals():
1421+
assert irradiance.SURFACE_ALBEDOS == albedo.SURFACE_ALBEDOS

0 commit comments

Comments
 (0)