Skip to content

Commit 483c9b8

Browse files
Add and improve tests
1 parent 60bf26d commit 483c9b8

1 file changed

Lines changed: 60 additions & 14 deletions

File tree

tests/test_irradiance.py

Lines changed: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,6 @@ def test_perez_driesse_airmass(irrad_data, ephem_data, dni_et):
288288
out = irradiance.perez_driesse(40, 180, irrad_data['dhi'], dni,
289289
dni_et, ephem_data['apparent_zenith'],
290290
ephem_data['azimuth'], airmass=None)
291-
print(out)
292291
expected = pd.Series(np.array(
293292
[0., 29.991, np.nan, 47.397]),
294293
index=irrad_data.index)
@@ -394,15 +393,15 @@ def test_perez_negative_horizon():
394393
assert_series_equal(sum_components, expected_for_sum, check_less_precise=2)
395394

396395

397-
def test_perez_zero_dhi_and_dni(dni_et):
398-
out = irradiance.perez(20, 180, 0.0, 0.0, dni_et, 89.96, 256.28, 37.32)
396+
def test_perez_zero_dhi_and_dni_scalar():
397+
# Divides zero by zero.
398+
args = (20, 180, 0.0, 0.0, 1366.1, 89.96, 256.28, 37.32)
399+
400+
out = irradiance.perez(*args)
399401
expected = 0.0
400402
assert_equal(out, expected)
401403

402-
out = irradiance.perez(
403-
20, 180, 0.0, 0.0, dni_et, 89.96, 256.28, 37.32,
404-
return_components=True
405-
)
404+
out = irradiance.perez(*args, return_components=True)
406405
expected = {
407406
"poa_sky_diffuse": 0.0,
408407
"poa_isotropic": 0.0,
@@ -411,18 +410,65 @@ def test_perez_zero_dhi_and_dni(dni_et):
411410
}
412411
assert len(out) == len(expected)
413412
for key in expected.keys():
414-
assert_equal(out[key], expected[key])
413+
assert_equal(out[key], expected[key], err_msg=key)
414+
415+
assert_equal(
416+
out["poa_sky_diffuse"],
417+
out["poa_isotropic"] + out["poa_circumsolar"] + out["poa_horizon"],
418+
)
419+
420+
421+
def test_perez_zero_dhi_and_dni_array():
422+
# Divides zero by zero.
423+
args = (
424+
20, 180, np.array([0.0, 10.0, float("nan")]), 0.0, 1366.1, 89.96,
425+
256.28, 37.32
426+
)
427+
428+
out = irradiance.perez(*args)
429+
expected = np.array([0.0, 9.424924186619206, float("nan")])
430+
assert_allclose(out, expected)
415431

432+
out = irradiance.perez(*args, return_components=True)
433+
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")]),
438+
}
439+
assert len(out) == len(expected)
440+
for key in expected.keys():
441+
assert_allclose(out[key], expected[key], err_msg=key)
442+
443+
assert_almost_equal(
444+
out["poa_sky_diffuse"],
445+
out["poa_isotropic"] + out["poa_circumsolar"] + out["poa_horizon"],
446+
)
447+
448+
449+
def test_perez_zero_dhi_nonzero_dni_scalar():
450+
# Divides nonzero by zero.
451+
args = (20, 180, 0.0, 100.0, 1366.1, 89.96, 256.28, 37.32)
452+
453+
with assert_raises(FloatingPointError):
454+
irradiance.perez(*args)
455+
456+
with assert_raises(FloatingPointError):
457+
irradiance.perez(*args, return_components=True)
458+
459+
460+
def test_perez_zero_dhi_nonzero_dni_array():
461+
# Divides nonzero by zero.
462+
args = (
463+
20, 180, np.array([0.0, 10.0, float("nan")]), 100.0, 1366.1, 89.96,
464+
256.28, 37.32
465+
)
416466

417-
def test_perez_zero_dhi_nonzero_dni(dni_et):
418467
with assert_raises(FloatingPointError):
419-
irradiance.perez(20, 180, 0.0, 100.0, dni_et, 89.96, 256.28, 37.32)
468+
irradiance.perez(*args)
420469

421470
with assert_raises(FloatingPointError):
422-
irradiance.perez(
423-
20, 180, 0.0, 100.0, dni_et, 89.96, 256.28, 37.32,
424-
return_components=True
425-
)
471+
irradiance.perez(*args, return_components=True)
426472

427473

428474
def test_perez_arrays(irrad_data, ephem_data, dni_et, relative_airmass):

0 commit comments

Comments
 (0)