Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Adopt dni_clear variable name for clearsky DNI #2274

Merged
merged 19 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions pvlib/irradiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pvlib import atmosphere, solarposition, tools
import pvlib # used to avoid dni name collision in complete_irradiance

from pvlib._deprecation import pvlibDeprecationWarning
from pvlib._deprecation import pvlibDeprecationWarning, renamed_kwarg_warning
import warnings


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


def dirindex(ghi, ghi_clearsky, dni_clearsky, zenith, times, pressure=101325.,
@renamed_kwarg_warning(
since='0.11.2',
old_param_name='dni_clearsky',
new_param_name='dni_clear',
removal="0.12.0")
def dirindex(ghi, ghi_clearsky, dni_clear, zenith, times, pressure=101325.,
use_delta_kt_prime=True, temp_dew=None, min_cos_zenith=0.065,
max_zenith=87):
"""
Expand All @@ -2173,7 +2178,7 @@ def dirindex(ghi, ghi_clearsky, dni_clearsky, zenith, times, pressure=101325.,
ghi_clearsky : array-like
Global horizontal irradiance from clear sky model. [Wm⁻²]

dni_clearsky : array-like
dni_clear : array-like
Direct normal irradiance from clear sky model. [Wm⁻²]

zenith : array-like
Expand Down Expand Up @@ -2239,7 +2244,7 @@ def dirindex(ghi, ghi_clearsky, dni_clearsky, zenith, times, pressure=101325.,
min_cos_zenith=min_cos_zenith,
max_zenith=max_zenith)

dni_dirindex = dni_clearsky * dni_dirint / dni_dirint_clearsky
dni_dirindex = dni_clear * dni_dirint / dni_dirint_clearsky

dni_dirindex[dni_dirindex < 0] = 0.

Expand Down Expand Up @@ -3611,7 +3616,12 @@ def _get_dirint_coeffs():
return coeffs[1:, 1:, :, :]


def dni(ghi, dhi, zenith, clearsky_dni=None, clearsky_tolerance=1.1,
@renamed_kwarg_warning(
since='0.11.2',
old_param_name='clearsky_dni',
new_param_name='dni_clear',
removal="0.12.0")
def dni(ghi, dhi, zenith, dni_clear=None, clearsky_tolerance=1.1,
zenith_threshold_for_zero_dni=88.0,
zenith_threshold_for_clearsky_limit=80.0):
"""
Expand All @@ -3635,11 +3645,11 @@ def dni(ghi, dhi, zenith, clearsky_dni=None, clearsky_tolerance=1.1,
True (not refraction-corrected) zenith angles in decimal
degrees. Angles must be >=0 and <=180.

clearsky_dni : Series, optional
dni_clear : Series, optional
Clearsky direct normal irradiance.

clearsky_tolerance : float, default 1.1
If 'clearsky_dni' is given this parameter can be used to allow a
If `dni_clear` is given this parameter can be used to allow a
tolerance by how much the calculated DNI value can be greater than
the clearsky value before it is identified as an unreasonable value.

Expand All @@ -3652,7 +3662,7 @@ def dni(ghi, dhi, zenith, clearsky_dni=None, clearsky_tolerance=1.1,
'zenith_threshold_for_clearsky_limit' and smaller the
'zenith_threshold_for_zero_dni' that are greater than the clearsky DNI
(times allowed tolerance) will be corrected. Only applies if
'clearsky_dni' is not None.
`dni_clear` is not None.

Returns
-------
Expand All @@ -3674,14 +3684,19 @@ def dni(ghi, dhi, zenith, clearsky_dni=None, clearsky_tolerance=1.1,
# zenith_threshold_for_clearsky_limit and smaller than the
# upper_cutoff_zenith that are greater than the clearsky DNI (times
# clearsky_tolerance)
if clearsky_dni is not None:
max_dni = clearsky_dni * clearsky_tolerance
if dni_clear is not None:
max_dni = dni_clear * clearsky_tolerance
dni[(zenith >= zenith_threshold_for_clearsky_limit) &
(zenith < zenith_threshold_for_zero_dni) &
(dni > max_dni)] = max_dni
return dni


@renamed_kwarg_warning(
since='0.11.2',
old_param_name='clearsky_dni',
new_param_name='dni_clear',
removal="0.12.0")
def complete_irradiance(solar_zenith,
ghi=None,
dhi=None,
Expand Down Expand Up @@ -3727,7 +3742,7 @@ def complete_irradiance(solar_zenith,
"""
if ghi is not None and dhi is not None and dni is None:
dni = pvlib.irradiance.dni(ghi, dhi, solar_zenith,
clearsky_dni=dni_clear,
dni_clear=dni_clear,
clearsky_tolerance=1.1)
elif dni is not None and dhi is not None and ghi is None:
ghi = (dhi + dni * tools.cosd(solar_zenith))
Expand Down
41 changes: 31 additions & 10 deletions pvlib/tests/test_irradiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
assert_frame_equal,
assert_series_equal,
requires_ephem,
requires_numba
requires_numba,
fail_on_pvlib_version
)

from pvlib._deprecation import pvlibDeprecationWarning
Expand Down Expand Up @@ -1063,7 +1064,7 @@ def test_dirindex(times):
np.array([0., 79.73860422, 1042.48031487, 257.20751138]),
index=times
)
dni_clearsky = pd.Series(
dni_clear = pd.Series(
np.array([0., 316.1949056, 939.95469881, 646.22886049]),
index=times
)
Expand All @@ -1073,7 +1074,7 @@ def test_dirindex(times):
)
pressure = 93193.
tdew = 10.
out = irradiance.dirindex(ghi, ghi_clearsky, dni_clearsky,
out = irradiance.dirindex(ghi, ghi_clearsky, dni_clear,
zenith, times, pressure=pressure,
temp_dew=tdew)
dirint_close_values = irradiance.dirint(ghi, zenith, times,
Expand Down Expand Up @@ -1101,25 +1102,25 @@ def test_dirindex_min_cos_zenith_max_zenith():
times = pd.DatetimeIndex(['2014-06-24T12-0700', '2014-06-24T18-0700'])
ghi = pd.Series([0, 1], index=times)
ghi_clearsky = pd.Series([0, 1], index=times)
dni_clearsky = pd.Series([0, 5], index=times)
dni_clear = pd.Series([0, 5], index=times)
solar_zenith = pd.Series([90, 89.99], index=times)

out = irradiance.dirindex(ghi, ghi_clearsky, dni_clearsky, solar_zenith,
out = irradiance.dirindex(ghi, ghi_clearsky, dni_clear, solar_zenith,
times)
expected = pd.Series([nan, nan], index=times)
assert_series_equal(out, expected)

out = irradiance.dirindex(ghi, ghi_clearsky, dni_clearsky, solar_zenith,
out = irradiance.dirindex(ghi, ghi_clearsky, dni_clear, solar_zenith,
times, min_cos_zenith=0)
expected = pd.Series([nan, nan], index=times)
assert_series_equal(out, expected)

out = irradiance.dirindex(ghi, ghi_clearsky, dni_clearsky, solar_zenith,
out = irradiance.dirindex(ghi, ghi_clearsky, dni_clear, solar_zenith,
times, max_zenith=90)
expected = pd.Series([nan, nan], index=times)
assert_series_equal(out, expected)

out = irradiance.dirindex(ghi, ghi_clearsky, dni_clearsky, solar_zenith,
out = irradiance.dirindex(ghi, ghi_clearsky, dni_clear, solar_zenith,
times, min_cos_zenith=0, max_zenith=100)
expected = pd.Series([nan, 5.], index=times)
assert_series_equal(out, expected)
Expand All @@ -1129,10 +1130,30 @@ def test_dni():
ghi = pd.Series([90, 100, 100, 100, 100])
dhi = pd.Series([100, 90, 50, 50, 50])
zenith = pd.Series([80, 100, 85, 70, 85])
clearsky_dni = pd.Series([50, 50, 200, 50, 300])
dni_clear = pd.Series([50, 50, 200, 50, 300])

dni = irradiance.dni(ghi, dhi, zenith,
clearsky_dni=clearsky_dni, clearsky_tolerance=2)
dni_clear=dni_clear, clearsky_tolerance=2)
assert_series_equal(dni,
pd.Series([float('nan'), float('nan'), 400,
146.190220008, 573.685662283]))

dni = irradiance.dni(ghi, dhi, zenith)
assert_series_equal(dni,
pd.Series([float('nan'), float('nan'), 573.685662283,
146.190220008, 573.685662283]))


@fail_on_pvlib_version("0.12")
def test_dni_dni_clearsky_deprecation():
ghi = pd.Series([90, 100, 100, 100, 100])
dhi = pd.Series([100, 90, 50, 50, 50])
zenith = pd.Series([80, 100, 85, 70, 85])
dni_clear = pd.Series([50, 50, 200, 50, 300])

with pytest.warns(pvlibDeprecationWarning, match='dni_clear'):
dni = irradiance.dni(ghi, dhi, zenith,
clearsky_dni=dni_clear, clearsky_tolerance=2)
assert_series_equal(dni,
pd.Series([float('nan'), float('nan'), 400,
146.190220008, 573.685662283]))
Expand Down
Loading