Skip to content

Commit e97b83f

Browse files
Make sure NaN irradiances pass through as expected
1 parent 483c9b8 commit e97b83f

2 files changed

Lines changed: 19 additions & 10 deletions

File tree

pvlib/irradiance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ def perez(surface_tilt, surface_azimuth, dhi, dni, dni_extra,
11471147
kappa = 1.041 # for solar_zenith in radians
11481148
z = np.radians(solar_zenith) # convert to radians
11491149

1150-
# delta is the sky's "brightness", assumes dni_extra > 0
1150+
# delta is the sky's "brightness", NaN airmass ok, assumes dni_extra > 0
11511151
delta = dhi * airmass / dni_extra
11521152

11531153
# epsilon is the sky's "clearness". Preserves NaNs for dni or dhi.

tests/test_irradiance.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -418,23 +418,32 @@ def test_perez_zero_dhi_and_dni_scalar():
418418
)
419419

420420

421-
def test_perez_zero_dhi_and_dni_array():
421+
def test_perez_array_dhi_and_dni_combos():
422422
# Divides zero by zero.
423423
args = (
424-
20, 180, np.array([0.0, 10.0, float("nan")]), 0.0, 1366.1, 89.96,
425-
256.28, 37.32
424+
20, 180, np.array([0.0, 10.0, np.nan, 0.0, np.nan]),
425+
np.array([0.0, 0.0, 0.0, np.nan, np.nan]), 1366.1, 89.96, 256.28,
426+
37.32
426427
)
427428

428429
out = irradiance.perez(*args)
429-
expected = np.array([0.0, 9.424924186619206, float("nan")])
430+
expected = np.array([0.0, 9.424924186619206, np.nan, np.nan, np.nan])
430431
assert_allclose(out, expected)
431432

432433
out = irradiance.perez(*args, return_components=True)
433434
expected = {
434-
"poa_sky_diffuse": np.array([0.0, 9.424924186619206, float("nan")]),
435-
"poa_isotropic": np.array([ 0.0, 9.162258932459126, float("nan")]),
436-
"poa_circumsolar": np.array([ 0.0, 0.5187450944545264, float("nan")]),
437-
"poa_horizon": np.array([0.0, -0.2560798402944465, float("nan")]),
435+
"poa_sky_diffuse": np.array(
436+
[0.0, 9.424924186619206, np.nan, np.nan, np.nan]
437+
),
438+
"poa_isotropic": np.array(
439+
[ 0.0, 9.162258932459126, np.nan, np.nan, np.nan]
440+
),
441+
"poa_circumsolar": np.array(
442+
[ 0.0, 0.5187450944545264, np.nan, np.nan, np.nan]
443+
),
444+
"poa_horizon": np.array(
445+
[0.0, -0.2560798402944465, np.nan, np.nan, np.nan]
446+
),
438447
}
439448
assert len(out) == len(expected)
440449
for key in expected.keys():
@@ -460,7 +469,7 @@ def test_perez_zero_dhi_nonzero_dni_scalar():
460469
def test_perez_zero_dhi_nonzero_dni_array():
461470
# Divides nonzero by zero.
462471
args = (
463-
20, 180, np.array([0.0, 10.0, float("nan")]), 100.0, 1366.1, 89.96,
472+
20, 180, np.array([0.0, 10.0, np.nan]), 100.0, 1366.1, 89.96,
464473
256.28, 37.32
465474
)
466475

0 commit comments

Comments
 (0)