Skip to content

Commit 46970d2

Browse files
Push breaking test for discussion purposes
1 parent 303ae01 commit 46970d2

2 files changed

Lines changed: 52 additions & 4 deletions

File tree

pvlib/irradiance.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,10 +1042,14 @@ def perez(surface_tilt, surface_azimuth, dhi, dni, dni_extra,
10421042
Perez models determine the diffuse irradiance from the sky (ground
10431043
reflected irradiance is not included in this algorithm) on a tilted
10441044
surface using the surface tilt angle, surface azimuth angle, diffuse
1045-
horizontal irradiance, direct normal irradiance, extraterrestrial
1046-
irradiance, sun zenith angle, sun azimuth angle, and relative (not
1047-
pressure-corrected) airmass. Optionally a selector may be used to
1048-
use any of Perez's model coefficient sets.
1045+
horizontal irradiance (DHI), direct normal irradiance (DNI),
1046+
extraterrestrial irradiance, sun zenith angle, sun azimuth angle, and
1047+
relative (not pressure-corrected) airmass. Optionally a selector may be
1048+
used to use any of Perez's model coefficient sets. It is expected that if
1049+
DHI is zero, then DNI is also zero, otherwise a FloatingPointError is
1050+
raised due to a division of a nonzero (and not NaN) value by zero. It is
1051+
also expected that extraterrestrial irradiance is positive. If airmass
1052+
is NaN, then the total and all components are zero.
10491053
10501054
Warning
10511055
-------
@@ -1125,6 +1129,11 @@ def perez(surface_tilt, surface_azimuth, dhi, dni, dni_extra,
11251129
* poa_circumsolar
11261130
* poa_horizon
11271131
1132+
Raises
1133+
------
1134+
FloatingPointError
1135+
If dni is zero when dhi is not zero and not NaN.
1136+
11281137
11291138
References
11301139
----------

tests/test_irradiance.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,45 @@ def test_perez_array_dhi_and_dni_combos():
456456
)
457457

458458

459+
def test_perez_array_dhi_and_dni_combos_nan_airmass():
460+
# Divides zero and non-zero by zero and various NaN division combos, when
461+
# airmass is NaN (e.g., for sun below horizon).
462+
args = (
463+
20, 180,
464+
np.array([0.0, 10.0, np.nan, np.nan, 0.0, 100.0, np.nan]),
465+
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
467+
)
468+
469+
out = irradiance.perez(*args)
470+
poa_sky_diffuse_expected = np.array(
471+
[0.0, 0.0, np.nan, np.nan, np.nan, np.nan, np.nan]
472+
)
473+
assert_allclose(out, poa_sky_diffuse_expected)
474+
475+
out = irradiance.perez(*args, return_components=True)
476+
expected = {
477+
"poa_sky_diffuse": poa_sky_diffuse_expected,
478+
"poa_isotropic": np.array(
479+
[0.0, 9.162258932459126, np.nan, np.nan, np.nan, np.nan, np.nan]
480+
),
481+
"poa_circumsolar": np.array(
482+
[0.0, 0.5187450944545264, np.nan, np.nan, np.nan, np.nan, np.nan]
483+
),
484+
"poa_horizon": np.array(
485+
[0.0, -0.2560798402944465, np.nan, np.nan, np.nan, np.nan, np.nan]
486+
),
487+
}
488+
assert len(out) == len(expected)
489+
for key in expected.keys():
490+
assert_allclose(out[key], expected[key], err_msg=key)
491+
492+
assert_almost_equal(
493+
out["poa_sky_diffuse"],
494+
out["poa_isotropic"] + out["poa_circumsolar"] + out["poa_horizon"],
495+
)
496+
497+
459498
def test_perez_zero_dhi_nonzero_dni_scalar():
460499
# Divides nonzero by zero.
461500
args = (20, 180, 0.0, 100.0, 1366.1, 89.96, 256.28, 37.32)

0 commit comments

Comments
 (0)