Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
8 changes: 4 additions & 4 deletions pvlib/clearsky.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,13 @@ def haurwitz(apparent_zenith):
'''

cos_zenith = tools.cosd(apparent_zenith.values)
clearsky_ghi = np.zeros_like(apparent_zenith.values)
ghi_clear = np.zeros_like(apparent_zenith.values)
cos_zen_gte_0 = cos_zenith > 0
clearsky_ghi[cos_zen_gte_0] = (1098.0 * cos_zenith[cos_zen_gte_0] *
np.exp(-0.059/cos_zenith[cos_zen_gte_0]))
ghi_clear[cos_zen_gte_0] = (1098.0 * cos_zenith[cos_zen_gte_0] *
np.exp(-0.059/cos_zenith[cos_zen_gte_0]))

df_out = pd.DataFrame(index=apparent_zenith.index,
data=clearsky_ghi,
data=ghi_clear,
columns=['ghi'])

return df_out
Expand Down
28 changes: 19 additions & 9 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 @@ -1614,7 +1614,12 @@ def ghi_from_poa_driesse_2023(surface_tilt, surface_azimuth,
return ghi


def clearsky_index(ghi, clearsky_ghi, max_clearsky_index=2.0):
@renamed_kwarg_warning(
since='11.2',
old_param_name='clearsky_ghi',
new_param_name='ghi_clear',
removal="12.0")
def clearsky_index(ghi, ghi_clear, max_clearsky_index=2.0):
"""
Calculate the clearsky index.

Expand All @@ -1626,7 +1631,7 @@ def clearsky_index(ghi, clearsky_ghi, max_clearsky_index=2.0):
ghi : numeric
Global horizontal irradiance. [Wm⁻²]

clearsky_ghi : numeric
ghi_clear : numeric
Modeled clearsky GHI

max_clearsky_index : numeric, default 2.0
Expand All @@ -1638,12 +1643,12 @@ def clearsky_index(ghi, clearsky_ghi, max_clearsky_index=2.0):
clearsky_index : numeric
Clearsky index
"""
clearsky_index = ghi / clearsky_ghi
clearsky_index = ghi / ghi_clear
# set +inf, -inf, and nans to zero
clearsky_index = np.where(~np.isfinite(clearsky_index), 0,
clearsky_index)
# but preserve nans in the input arrays
input_is_nan = ~np.isfinite(ghi) | ~np.isfinite(clearsky_ghi)
input_is_nan = ~np.isfinite(ghi) | ~np.isfinite(ghi_clear)
clearsky_index = np.where(input_is_nan, np.nan, clearsky_index)

clearsky_index = np.maximum(clearsky_index, 0)
Expand Down Expand Up @@ -2151,15 +2156,20 @@ 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='11.2',
old_param_name='ghi_clearsky',
new_param_name='ghi_clear',
removal="12.0")
def dirindex(ghi, ghi_clear, dni_clearsky, zenith, times, pressure=101325.,
use_delta_kt_prime=True, temp_dew=None, min_cos_zenith=0.065,
max_zenith=87):
"""
Determine DNI from GHI using the DIRINDEX model.

The DIRINDEX model [1]_ modifies the DIRINT model implemented in
:py:func:`pvlib.irradiance.dirint` by taking into account information
from a clear sky model. It is recommended that ``ghi_clearsky`` be
from a clear sky model. It is recommended that ``ghi_clear`` be
calculated using the Ineichen clear sky model
:py:func:`pvlib.clearsky.ineichen` with ``perez_enhancement=True``.

Expand All @@ -2170,7 +2180,7 @@ def dirindex(ghi, ghi_clearsky, dni_clearsky, zenith, times, pressure=101325.,
ghi : array-like
Global horizontal irradiance. [Wm⁻²]

ghi_clearsky : array-like
ghi_clear : array-like
Global horizontal irradiance from clear sky model. [Wm⁻²]

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

dni_dirint_clearsky = dirint(ghi_clearsky, zenith, times,
dni_dirint_clearsky = dirint(ghi_clear, zenith, times,
pressure=pressure,
use_delta_kt_prime=use_delta_kt_prime,
temp_dew=temp_dew,
Expand Down
33 changes: 32 additions & 1 deletion 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 @@ -1094,6 +1095,29 @@ def test_dirindex(times):
equal_nan=True)


@fail_on_pvlib_version("0.12")
def test_dirindex_ghi_clearsky_deprecation():
with pytest.warns(pvlibDeprecationWarning, match='ghi_clear'):
times = pd.DatetimeIndex(['2014-06-24T18-1200'])
ghi = pd.Series([1038.62], index=times)
ghi_clearsky = pd.Series(
np.array([1042.48031487]),
index=times
)
dni_clearsky = pd.Series(
np.array([939.95469881]),
index=times
)
zenith = pd.Series(
np.array([10.56413562]),
index=times
)
pressure, tdew = 93193, 10
irradiance.dirindex(
ghi=ghi, ghi_clearsky=ghi_clearsky, dni_clearsky=dni_clearsky,
zenith=zenith, times=times, pressure=pressure, temp_dew=tdew)


def test_dirindex_min_cos_zenith_max_zenith():
# map out behavior under difficult conditions with various
# limiting kwargs settings
Expand Down Expand Up @@ -1235,6 +1259,13 @@ def test_clearsky_index():
assert_series_equal(out, expected)


@fail_on_pvlib_version("0.12")
def test_clearsky_index_clearsky_ghi_deprecation():
with pytest.warns(pvlibDeprecationWarning, match='ghi_clear'):
ghi, clearsky_ghi = 200, 300
irradiance.clearsky_index(ghi, clearsky_ghi=clearsky_ghi)


def test_clearness_index():
ghi = np.array([-1, 0, 1, 1000])
solar_zenith = np.array([180, 90, 89.999, 0])
Expand Down
Loading