Skip to content

Commit f8f60f4

Browse files
RDaxiniAdamRJensenkandersolarechedey-ls
authored
Adopt dni_clear variable name for clearsky DNI (#2274)
* irradiance.py: dirint_bins(), dirindex() * irradiance.py: dni(), _get_dirint_coeffs(), complete_irradiance() * modify tests * apply decorator: dirindex, dni, complete irradiance * dni() deprecation test * Update test_irradiance.py * Update test_irradiance.py * correct version number * Update pvlib/tests/test_irradiance.py Co-authored-by: Adam R. Jensen <[email protected]> * remove warning from `complete_irradiance` Co-Authored-By: Kevin Anderson <[email protected]> * test: remove return value checks * add dirindex test * fix test * linting * Update v0.11.2.rst * 0.12->0.13 irradiance.py, test_irradiance.py * Apply suggestions from code review Co-authored-by: Echedey Luis <[email protected]> * irradiance.py: +units, +version_changed directive --------- Co-authored-by: Adam R. Jensen <[email protected]> Co-authored-by: Kevin Anderson <[email protected]> Co-authored-by: Echedey Luis <[email protected]>
1 parent 6af80da commit f8f60f4

File tree

3 files changed

+68
-24
lines changed

3 files changed

+68
-24
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ v0.11.2 (Anticipated December, 2024)
66

77
Deprecations
88
~~~~~~~~~~~~
9+
* Deprecated terms ``dni_clearsky`` and ``clearsky_dni``, replaced with ``dni_clear``.
10+
Affected functions are :py:func:`~pvlib.irradiance.dirindex` and :py:func:`~pvlib.irradiance.dni`.
11+
(:issue:`2272`, :pull:`2274`)
912

1013

1114
Enhancements

pvlib/irradiance.py

+30-14
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
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
19+
from pvlib._deprecation import pvlibDeprecationWarning, renamed_kwarg_warning
2020
import warnings
2121

2222

@@ -2151,7 +2151,12 @@ def _dirint_bins(times, kt_prime, zenith, w, delta_kt_prime):
21512151
return kt_prime_bin, zenith_bin, w_bin, delta_kt_prime_bin
21522152

21532153

2154-
def dirindex(ghi, ghi_clearsky, dni_clearsky, zenith, times, pressure=101325.,
2154+
@renamed_kwarg_warning(
2155+
since='0.11.2',
2156+
old_param_name='dni_clearsky',
2157+
new_param_name='dni_clear',
2158+
removal="0.13.0")
2159+
def dirindex(ghi, ghi_clearsky, dni_clear, zenith, times, pressure=101325.,
21552160
use_delta_kt_prime=True, temp_dew=None, min_cos_zenith=0.065,
21562161
max_zenith=87):
21572162
"""
@@ -2173,9 +2178,12 @@ def dirindex(ghi, ghi_clearsky, dni_clearsky, zenith, times, pressure=101325.,
21732178
ghi_clearsky : array-like
21742179
Global horizontal irradiance from clear sky model. [Wm⁻²]
21752180
2176-
dni_clearsky : array-like
2181+
dni_clear : array-like
21772182
Direct normal irradiance from clear sky model. [Wm⁻²]
21782183
2184+
.. versionchanged:: 0.11.2
2185+
Renamed from ``dni_clearsky`` to ``dni_clear``.
2186+
21792187
zenith : array-like
21802188
True (not refraction-corrected) zenith angles in decimal
21812189
degrees. If Z is a vector it must be of the same size as all
@@ -2239,7 +2247,7 @@ def dirindex(ghi, ghi_clearsky, dni_clearsky, zenith, times, pressure=101325.,
22392247
min_cos_zenith=min_cos_zenith,
22402248
max_zenith=max_zenith)
22412249

2242-
dni_dirindex = dni_clearsky * dni_dirint / dni_dirint_clearsky
2250+
dni_dirindex = dni_clear * dni_dirint / dni_dirint_clearsky
22432251

22442252
dni_dirindex[dni_dirindex < 0] = 0.
22452253

@@ -3611,7 +3619,12 @@ def _get_dirint_coeffs():
36113619
return coeffs[1:, 1:, :, :]
36123620

36133621

3614-
def dni(ghi, dhi, zenith, clearsky_dni=None, clearsky_tolerance=1.1,
3622+
@renamed_kwarg_warning(
3623+
since='0.11.2',
3624+
old_param_name='clearsky_dni',
3625+
new_param_name='dni_clear',
3626+
removal="0.13.0")
3627+
def dni(ghi, dhi, zenith, dni_clear=None, clearsky_tolerance=1.1,
36153628
zenith_threshold_for_zero_dni=88.0,
36163629
zenith_threshold_for_clearsky_limit=80.0):
36173630
"""
@@ -3635,11 +3648,14 @@ def dni(ghi, dhi, zenith, clearsky_dni=None, clearsky_tolerance=1.1,
36353648
True (not refraction-corrected) zenith angles in decimal
36363649
degrees. Angles must be >=0 and <=180.
36373650
3638-
clearsky_dni : Series, optional
3639-
Clearsky direct normal irradiance.
3651+
dni_clear : Series, optional
3652+
Clearsky direct normal irradiance. [Wm⁻²]
3653+
3654+
.. versionchanged:: 0.11.2
3655+
Renamed from ``clearsky_dni`` to ``dni_clear``.
36403656
36413657
clearsky_tolerance : float, default 1.1
3642-
If 'clearsky_dni' is given this parameter can be used to allow a
3658+
If ``dni_clear`` is given this parameter can be used to allow a
36433659
tolerance by how much the calculated DNI value can be greater than
36443660
the clearsky value before it is identified as an unreasonable value.
36453661
@@ -3652,7 +3668,7 @@ def dni(ghi, dhi, zenith, clearsky_dni=None, clearsky_tolerance=1.1,
36523668
'zenith_threshold_for_clearsky_limit' and smaller the
36533669
'zenith_threshold_for_zero_dni' that are greater than the clearsky DNI
36543670
(times allowed tolerance) will be corrected. Only applies if
3655-
'clearsky_dni' is not None.
3671+
``dni_clear`` is not None.
36563672
36573673
Returns
36583674
-------
@@ -3674,8 +3690,8 @@ def dni(ghi, dhi, zenith, clearsky_dni=None, clearsky_tolerance=1.1,
36743690
# zenith_threshold_for_clearsky_limit and smaller than the
36753691
# upper_cutoff_zenith that are greater than the clearsky DNI (times
36763692
# clearsky_tolerance)
3677-
if clearsky_dni is not None:
3678-
max_dni = clearsky_dni * clearsky_tolerance
3693+
if dni_clear is not None:
3694+
max_dni = dni_clear * clearsky_tolerance
36793695
dni[(zenith >= zenith_threshold_for_clearsky_limit) &
36803696
(zenith < zenith_threshold_for_zero_dni) &
36813697
(dni > max_dni)] = max_dni
@@ -3716,8 +3732,8 @@ def complete_irradiance(solar_zenith,
37163732
Pandas series of dni data, with datetime index. Must have the same
37173733
datetime index as ghi, dhi, and zenith series, when available.
37183734
dni_clear : Series, optional
3719-
Pandas series of clearsky dni data. Must have the same datetime index
3720-
as ghi, dhi, dni, and zenith series, when available. See
3735+
Pandas series of clearsky dni data [Wm⁻²]. Must have the same datetime
3736+
index as ghi, dhi, dni, and zenith series, when available. See
37213737
:py:func:`dni` for details.
37223738
37233739
Returns
@@ -3727,7 +3743,7 @@ def complete_irradiance(solar_zenith,
37273743
"""
37283744
if ghi is not None and dhi is not None and dni is None:
37293745
dni = pvlib.irradiance.dni(ghi, dhi, solar_zenith,
3730-
clearsky_dni=dni_clear,
3746+
dni_clear=dni_clear,
37313747
clearsky_tolerance=1.1)
37323748
elif dni is not None and dhi is not None and ghi is None:
37333749
ghi = (dhi + dni * tools.cosd(solar_zenith))

pvlib/tests/test_irradiance.py

+35-10
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
assert_frame_equal,
1616
assert_series_equal,
1717
requires_ephem,
18-
requires_numba
18+
requires_numba,
19+
fail_on_pvlib_version,
1920
)
2021

2122
from pvlib._deprecation import pvlibDeprecationWarning
@@ -1063,7 +1064,7 @@ def test_dirindex(times):
10631064
np.array([0., 79.73860422, 1042.48031487, 257.20751138]),
10641065
index=times
10651066
)
1066-
dni_clearsky = pd.Series(
1067+
dni_clear = pd.Series(
10671068
np.array([0., 316.1949056, 939.95469881, 646.22886049]),
10681069
index=times
10691070
)
@@ -1073,7 +1074,7 @@ def test_dirindex(times):
10731074
)
10741075
pressure = 93193.
10751076
tdew = 10.
1076-
out = irradiance.dirindex(ghi, ghi_clearsky, dni_clearsky,
1077+
out = irradiance.dirindex(ghi, ghi_clearsky, dni_clear,
10771078
zenith, times, pressure=pressure,
10781079
temp_dew=tdew)
10791080
dirint_close_values = irradiance.dirint(ghi, zenith, times,
@@ -1101,38 +1102,51 @@ def test_dirindex_min_cos_zenith_max_zenith():
11011102
times = pd.DatetimeIndex(['2014-06-24T12-0700', '2014-06-24T18-0700'])
11021103
ghi = pd.Series([0, 1], index=times)
11031104
ghi_clearsky = pd.Series([0, 1], index=times)
1104-
dni_clearsky = pd.Series([0, 5], index=times)
1105+
dni_clear = pd.Series([0, 5], index=times)
11051106
solar_zenith = pd.Series([90, 89.99], index=times)
11061107

1107-
out = irradiance.dirindex(ghi, ghi_clearsky, dni_clearsky, solar_zenith,
1108+
out = irradiance.dirindex(ghi, ghi_clearsky, dni_clear, solar_zenith,
11081109
times)
11091110
expected = pd.Series([nan, nan], index=times)
11101111
assert_series_equal(out, expected)
11111112

1112-
out = irradiance.dirindex(ghi, ghi_clearsky, dni_clearsky, solar_zenith,
1113+
out = irradiance.dirindex(ghi, ghi_clearsky, dni_clear, solar_zenith,
11131114
times, min_cos_zenith=0)
11141115
expected = pd.Series([nan, nan], index=times)
11151116
assert_series_equal(out, expected)
11161117

1117-
out = irradiance.dirindex(ghi, ghi_clearsky, dni_clearsky, solar_zenith,
1118+
out = irradiance.dirindex(ghi, ghi_clearsky, dni_clear, solar_zenith,
11181119
times, max_zenith=90)
11191120
expected = pd.Series([nan, nan], index=times)
11201121
assert_series_equal(out, expected)
11211122

1122-
out = irradiance.dirindex(ghi, ghi_clearsky, dni_clearsky, solar_zenith,
1123+
out = irradiance.dirindex(ghi, ghi_clearsky, dni_clear, solar_zenith,
11231124
times, min_cos_zenith=0, max_zenith=100)
11241125
expected = pd.Series([nan, 5.], index=times)
11251126
assert_series_equal(out, expected)
11261127

11271128

1129+
@fail_on_pvlib_version("0.13")
1130+
def test_dirindex_dni_clearsky_deprecation():
1131+
times = pd.DatetimeIndex(['2014-06-24T12-0700', '2014-06-24T18-0700'])
1132+
ghi = pd.Series([0, 1], index=times)
1133+
ghi_clearsky = pd.Series([0, 1], index=times)
1134+
dni_clear = pd.Series([0, 5], index=times)
1135+
solar_zenith = pd.Series([90, 89.99], index=times)
1136+
with pytest.warns(pvlibDeprecationWarning, match='dni_clear'):
1137+
irradiance.dirindex(ghi, ghi_clearsky, dni_clearsky=dni_clear,
1138+
zenith=solar_zenith, times=times,
1139+
min_cos_zenith=0)
1140+
1141+
11281142
def test_dni():
11291143
ghi = pd.Series([90, 100, 100, 100, 100])
11301144
dhi = pd.Series([100, 90, 50, 50, 50])
11311145
zenith = pd.Series([80, 100, 85, 70, 85])
1132-
clearsky_dni = pd.Series([50, 50, 200, 50, 300])
1146+
dni_clear = pd.Series([50, 50, 200, 50, 300])
11331147

11341148
dni = irradiance.dni(ghi, dhi, zenith,
1135-
clearsky_dni=clearsky_dni, clearsky_tolerance=2)
1149+
dni_clear=dni_clear, clearsky_tolerance=2)
11361150
assert_series_equal(dni,
11371151
pd.Series([float('nan'), float('nan'), 400,
11381152
146.190220008, 573.685662283]))
@@ -1143,6 +1157,17 @@ def test_dni():
11431157
146.190220008, 573.685662283]))
11441158

11451159

1160+
@fail_on_pvlib_version("0.13")
1161+
def test_dni_dni_clearsky_deprecation():
1162+
ghi = pd.Series([90, 100, 100, 100, 100])
1163+
dhi = pd.Series([100, 90, 50, 50, 50])
1164+
zenith = pd.Series([80, 100, 85, 70, 85])
1165+
dni_clear = pd.Series([50, 50, 200, 50, 300])
1166+
with pytest.warns(pvlibDeprecationWarning, match='dni_clear'):
1167+
irradiance.dni(ghi, dhi, zenith,
1168+
clearsky_dni=dni_clear, clearsky_tolerance=2)
1169+
1170+
11461171
@pytest.mark.parametrize(
11471172
'surface_tilt,surface_azimuth,solar_zenith,' +
11481173
'solar_azimuth,aoi_expected,aoi_proj_expected',

0 commit comments

Comments
 (0)