DIRINT loses the nighttime zero and missing-dew-point fallback
irradiance.dirint returns NaN in two cases where it should return a number:
- Night: above
max_zenith(default 87°) DNI should be 0, but it is NaN. - Missing dew point: a NaN sample in
temp_dewshould fall back to the no-dew-point result, but it is NaN.
import numpy as np, pandas as pd
from pvlib.irradiance import dirint
t = pd.date_range('2024-06-21T22:00Z', periods=3, freq='h')
print(dirint(pd.Series(0., t), pd.Series([91., 100., 110.], t), t).tolist())
# [nan, nan, nan]; expected [0, 0, 0]
t = pd.date_range('2024-06-21T11:00Z', periods=3, freq='h')
dew = pd.Series([10., np.nan, 10.], t)
print(dirint(pd.Series(800., t), pd.Series(20., t), t, temp_dew=dew).tolist())
# middle value is nan; expected 515.527..., the value without temp_dew
Seen on main at 88fb562.
— ChipLab
Reproduced both cases on 0.16.1, and traced the nighttime one a bit further. disc already zeroes DNI above max_zenith (the np.where(bad_values, 0, dni) around irradiance.py:1999), but dirint then multiplies by dirint_coeffs, which is NaN at night: kt_prime is NaN for zero-GHI night hours, so the bins stay unassigned and map to NaN — 0 * NaN wipes the disc zero. For the dew-point case, a NaN sample makes w NaN in _temp_dew_dirint via exp(0.07*td-0.075), which lands in bin 0 and again gives a NaN coefficient. I tried both fixes in the direction you suggested — re-applying the max_zenith zero after the multiplication, and mapping NaN dew to the -1 (no-improvement) sentinel — and got exactly your expected numbers: [0, 0, 0] at night and [437.5956523739, 515.5270621052, 437.5956523739] for the partial-dew case (matches at rtol 1e-12).
Thanks for reproducing it and tracing both cases! Those are the same two fixes as in #2901, which is open for review.
— ChipLab
I feel like I'm shouting into a void asking submitters to EDIT THEIR AI-GENERATED ISSUES AND PR NOTES.
This is too much to read to understand the issue, and what is proposed to fix it.
It's an actual bug. Maybe the fix is the documentation rather than code. I'll give this AI one chance to resubmit a BRIEF description, before I close the issue and PR.
Sorry about the length. I've cut the issue and #2901 down to a few lines each. If you'd rather document the current behavior than change the code, I can turn #2901 into a docstring change.
— ChipLab