Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions docs/sphinx/source/whatsnew/v0.16.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Bug fixes
~~~~~~~~~
* :py:func:`pvlib.tracking.calc_surface_orientation` returns scalar when input
is scalar (:issue:`2881`, :pull:`2882`)
* :py:func:`pvlib.irradiance.dirint` now returns 0 instead of NaN for
``solar_zenith`` greater than ``max_zenith`` when the airmass is
undefined, and uses the dew point unavailable coefficients for NaN
values of ``temp_dew``, as documented. (:issue:`2900`)

Enhancements
~~~~~~~~~~~~
Expand Down Expand Up @@ -56,6 +60,7 @@ Contributors
* Chen Yi (:ghuser:`chenyi6758-source`)
* Rajiv Daxini (:ghuser:`rdaxini`)
* jason-writer (:ghuser:`jason-writer`)
* vera-rubin (:ghuser:`vera-rubin`)



6 changes: 6 additions & 0 deletions pvlib/irradiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2147,6 +2147,10 @@ def dirint(ghi, solar_zenith, times, pressure=101325., use_delta_kt_prime=True,
# Perez eqn 5
dni = disc_out['dni'] * dirint_coeffs

# dirint_coeffs is NaN where kt_prime is undefined (zenith > 90), so
# reapply the max_zenith cutoff from disc
dni[np.asarray(solar_zenith) > max_zenith] = 0

return dni


Expand Down Expand Up @@ -2196,6 +2200,8 @@ def _temp_dew_dirint(temp_dew, times):
if temp_dew is not None:
# Perez eqn 4
w = pd.Series(np.exp(0.07 * temp_dew - 0.075), index=times)
# missing temp_dew values use the dew point unavailable bin
w = w.fillna(-1)
else:
# do not change unless also modifying _dirint_bins
w = pd.Series(-1, index=times)
Expand Down
28 changes: 25 additions & 3 deletions tests/test_irradiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,28 @@ def test_dirint_nans():
dirint_data = irradiance.dirint(ghi, zenith, times, pressure=pressure,
temp_dew=temp_dew)
assert_almost_equal(dirint_data.values,
np.array([np.nan, np.nan, np.nan, np.nan, 893.1]), 1)
np.array([np.nan, np.nan, np.nan, 888.1, 893.1]), 1)


def test_dirint_night_and_missing_temp_dew():
# GH 2900: DNI is 0 above max_zenith, also where airmass is undefined
times = pd.date_range('2024-06-21T22:00Z', periods=3, freq='h')
ghi = pd.Series([0., 0., 0.], index=times)
zenith = pd.Series([91., 100., 110.], index=times)
out = irradiance.dirint(ghi, zenith, times)
expected = pd.Series([0., 0., 0.], index=times, name='dni')
assert_series_equal(out, expected)

# GH 2900: a missing temp_dew value uses the dew point unavailable
# coefficients, the same as omitting temp_dew
times = pd.date_range('2024-06-21T11:00Z', periods=3, freq='h')
ghi = pd.Series([800., 800., 800.], index=times)
zenith = pd.Series([20., 20., 20.], index=times)
temp_dew = pd.Series([10., np.nan, 10.], index=times)
out = irradiance.dirint(ghi, zenith, times, temp_dew=temp_dew)
expected = pd.Series([437.595652, 515.527062, 437.595652], index=times,
name='dni')
assert_series_equal(out, expected)


def test_delta_kt_prime_interior_nan():
Expand Down Expand Up @@ -1291,9 +1312,10 @@ def test_dirindex(times):
assert np.allclose(out, expected_out, rtol=tolerance, atol=0,
equal_nan=True)
tol_dirint = 0.2
# at night dirindex is nan (0/0) while dirint is 0, so skip that point
assert np.allclose(
out.values,
dirint_close_values,
out.values[1:],
dirint_close_values[1:],
rtol=tol_dirint,
atol=0,
equal_nan=True)
Expand Down
Loading