Skip to content

Commit f6c8070

Browse files
Do not overwrite approapriate NaNs with zero when airmass is NaN
1 parent 4f1b664 commit f6c8070

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

pvlib/irradiance.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,8 +1049,8 @@ def perez(surface_tilt, surface_azimuth, dhi, dni, dni_extra,
10491049
DHI is zero, then DNI is also zero, otherwise a FloatingPointError is
10501050
raised due to a division of a nonzero (and not NaN) value by zero. It is
10511051
also expected that extraterrestrial irradiance is positive. If airmass
1052-
is NaN, then the total and all components are zero if they should not
1053-
otherwise be NaN.
1052+
is NaN, then the total and all components are zero if they should not
1053+
otherwise be NaN because DHI or DNI was NaN.
10541054
10551055
Warning
10561056
-------
@@ -1218,10 +1218,15 @@ def perez(surface_tilt, surface_azimuth, dhi, dni, dni_extra,
12181218
sky_diffuse = np.maximum(dhi * (term1 + term2 + term3), 0)
12191219

12201220
# we've preserved the input type until now, so don't ruin it!
1221+
airmass_nan_idx = np.logical_and(
1222+
np.isnan(airmass), np.logical_not(
1223+
np.logical_or(np.isnan(dhi), np.isnan(dni))
1224+
)
1225+
)
12211226
if isinstance(sky_diffuse, pd.Series):
1222-
sky_diffuse[np.isnan(airmass)] = 0
1227+
sky_diffuse[airmass_nan_idx] = 0
12231228
else:
1224-
sky_diffuse = np.where(np.isnan(airmass), 0, sky_diffuse)
1229+
sky_diffuse = np.where(airmass_nan_idx, 0, sky_diffuse)
12251230

12261231
if return_components:
12271232
diffuse_components = OrderedDict()

tests/test_irradiance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ def test_perez_array_dhi_and_dni_combos_nan_airmass():
463463
20, 180,
464464
np.array([0.0, 10.0, np.nan, np.nan, 0.0, 100.0, np.nan]),
465465
np.array([0.0, 0.0, 0.0, 100.0, np.nan, np.nan, np.nan]),
466-
1366.1, 89.96, 256.28, np.nan
466+
1366.1, 91, 256.28, np.nan
467467
)
468468

469469
out = irradiance.perez(*args)

0 commit comments

Comments
 (0)