From 8e0c7f0b38669db705dd6833c5ea454dd97ac103 Mon Sep 17 00:00:00 2001 From: Cliff Hansen Date: Tue, 31 Dec 2024 15:01:25 -0700 Subject: [PATCH 1/8] add a function to test inputs for gti_dirint --- pvlib/irradiance.py | 14 ++++++++++++++ pvlib/tests/test_irradiance.py | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index 7fbb1ea98..0137b6f94 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -2368,6 +2368,9 @@ def gti_dirint(poa_global, aoi, solar_zenith, solar_azimuth, times, irradiance, Solar Energy 122, 1037-1046. :doi:`10.1016/j.solener.2015.10.024` """ + # check input data and raise Exceptions where data will cause the + # algorithm to fail + _gti_dirint_check_input(aoi) aoi_lt_90 = aoi < 90 @@ -2399,6 +2402,17 @@ def gti_dirint(poa_global, aoi, solar_zenith, solar_azimuth, times, return output +def _gti_dirint_check_input(aoi): + r""" + Helper for gti_dirint + + Raises Exceptions from input data that cause the algorithm to fail. + """ + if (aoi >= 90).all(): + raise ValueError("AOI >= 90 for all input data to gti_dirint. " + "gti_dirint requires some data with AOI < 90.") + + def _gti_dirint_lt_90(poa_global, aoi, aoi_lt_90, solar_zenith, solar_azimuth, times, surface_tilt, surface_azimuth, pressure=101325., use_delta_kt_prime=True, temp_dew=None, albedo=.25, diff --git a/pvlib/tests/test_irradiance.py b/pvlib/tests/test_irradiance.py index 9352e978e..336e0537b 100644 --- a/pvlib/tests/test_irradiance.py +++ b/pvlib/tests/test_irradiance.py @@ -928,6 +928,24 @@ def test_gti_dirint(): assert_frame_equal(output, expected) +def test_gti_dirint_data_error(): + times = pd.DatetimeIndex( + ['2014-06-24T06-0700', '2014-06-24T09-0700', '2014-06-24T12-0700']) + poa_global = np.array([20, 300, 1000]) + zenith = np.array([80, 45, 20]) + azimuth = np.array([90, 135, 180]) + surface_tilt = 30 + surface_azimuth = 180 + + aoi = np.array([100, 170, 110]) + with pytest.raises( + ValueError, match="AOI >= 90 for all input data to gti_dirint" + ): + irradiance.gti_dirint( + poa_global, aoi, zenith, azimuth, times, surface_tilt, + surface_azimuth) + + def test_erbs(): index = pd.DatetimeIndex(['20190101']*3 + ['20190620']) ghi = pd.Series([0, 50, 1000, 1000], index=index) From 1f5562e1004f96e6b0cd696f537ffd080bfa45e3 Mon Sep 17 00:00:00 2001 From: Cliff Hansen Date: Tue, 31 Dec 2024 15:18:08 -0700 Subject: [PATCH 2/8] linter --- pvlib/tests/test_irradiance.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pvlib/tests/test_irradiance.py b/pvlib/tests/test_irradiance.py index 336e0537b..8e0ec7cb5 100644 --- a/pvlib/tests/test_irradiance.py +++ b/pvlib/tests/test_irradiance.py @@ -939,13 +939,13 @@ def test_gti_dirint_data_error(): aoi = np.array([100, 170, 110]) with pytest.raises( - ValueError, match="AOI >= 90 for all input data to gti_dirint" - ): + ValueError, match="AOI >= 90 for all input data to gti_dirint" + ): irradiance.gti_dirint( poa_global, aoi, zenith, azimuth, times, surface_tilt, surface_azimuth) - - + + def test_erbs(): index = pd.DatetimeIndex(['20190101']*3 + ['20190620']) ghi = pd.Series([0, 50, 1000, 1000], index=index) From ab7c41155725a4df263b5350c0ed550ed0d9b093 Mon Sep 17 00:00:00 2001 From: Cliff Hansen Date: Tue, 31 Dec 2024 15:20:30 -0700 Subject: [PATCH 3/8] linter --- pvlib/tests/test_irradiance.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pvlib/tests/test_irradiance.py b/pvlib/tests/test_irradiance.py index 8e0ec7cb5..36f70574b 100644 --- a/pvlib/tests/test_irradiance.py +++ b/pvlib/tests/test_irradiance.py @@ -939,11 +939,10 @@ def test_gti_dirint_data_error(): aoi = np.array([100, 170, 110]) with pytest.raises( - ValueError, match="AOI >= 90 for all input data to gti_dirint" - ): - irradiance.gti_dirint( - poa_global, aoi, zenith, azimuth, times, surface_tilt, - surface_azimuth) + ValueError, match="AOI >= 90 for all input data to gti_dirint"): + irradiance.gti_dirint( + poa_global, aoi, zenith, azimuth, times, surface_tilt, + surface_azimuth) def test_erbs(): From 10dcb6dd950391eb39c722b212b19df2759cbad5 Mon Sep 17 00:00:00 2001 From: Cliff Hansen Date: Tue, 31 Dec 2024 15:24:30 -0700 Subject: [PATCH 4/8] linter --- pvlib/tests/test_irradiance.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pvlib/tests/test_irradiance.py b/pvlib/tests/test_irradiance.py index 36f70574b..239c8b7f8 100644 --- a/pvlib/tests/test_irradiance.py +++ b/pvlib/tests/test_irradiance.py @@ -939,10 +939,10 @@ def test_gti_dirint_data_error(): aoi = np.array([100, 170, 110]) with pytest.raises( - ValueError, match="AOI >= 90 for all input data to gti_dirint"): - irradiance.gti_dirint( - poa_global, aoi, zenith, azimuth, times, surface_tilt, - surface_azimuth) + ValueError, match="AOI >= 90 for all input data to gti_dirint"): + irradiance.gti_dirint( + poa_global, aoi, zenith, azimuth, times, surface_tilt, + surface_azimuth) def test_erbs(): From 504122b919ef8d17f81d6cd7e8fb40d8d2572464 Mon Sep 17 00:00:00 2001 From: Cliff Hansen Date: Tue, 28 Jan 2025 14:44:52 -0700 Subject: [PATCH 5/8] whatsnew --- docs/sphinx/source/whatsnew/v0.11.3.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/sphinx/source/whatsnew/v0.11.3.rst b/docs/sphinx/source/whatsnew/v0.11.3.rst index e330221dd..300e6c8ad 100644 --- a/docs/sphinx/source/whatsnew/v0.11.3.rst +++ b/docs/sphinx/source/whatsnew/v0.11.3.rst @@ -10,7 +10,8 @@ Deprecations Enhancements ~~~~~~~~~~~~ - +* :pyPfunc:`~pvlib.irradiance.gti_dirint` now raises an informative message + when input data don't include values with AOI<90 (:issue:`1342`, :pull:`2347`) Documentation ~~~~~~~~~~~~~ @@ -37,3 +38,4 @@ Contributors ~~~~~~~~~~~~ * Rajiv Daxini (:ghuser:`RDaxini`) * Mark Campanelli (:ghuser:`markcampanelli`) +* Cliff Hansen (:ghuser:`cwhanse`) From 675a422acecd77a35bdd97864e569b30437e973e Mon Sep 17 00:00:00 2001 From: Cliff Hansen Date: Wed, 29 Jan 2025 10:24:11 -0700 Subject: [PATCH 6/8] review --- docs/sphinx/source/whatsnew/v0.11.3.rst | 2 +- pvlib/irradiance.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/sphinx/source/whatsnew/v0.11.3.rst b/docs/sphinx/source/whatsnew/v0.11.3.rst index 300e6c8ad..e68dfac86 100644 --- a/docs/sphinx/source/whatsnew/v0.11.3.rst +++ b/docs/sphinx/source/whatsnew/v0.11.3.rst @@ -10,7 +10,7 @@ Deprecations Enhancements ~~~~~~~~~~~~ -* :pyPfunc:`~pvlib.irradiance.gti_dirint` now raises an informative message +* :py:func:`~pvlib.irradiance.gti_dirint` now raises an informative message when input data don't include values with AOI<90 (:issue:`1342`, :pull:`2347`) Documentation diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index 0137b6f94..c2a9c9e7b 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -2408,7 +2408,7 @@ def _gti_dirint_check_input(aoi): Raises Exceptions from input data that cause the algorithm to fail. """ - if (aoi >= 90).all(): + if not (aoi < 90).any(): raise ValueError("AOI >= 90 for all input data to gti_dirint. " "gti_dirint requires some data with AOI < 90.") From 5ac3b35d1f71a62784d74393fdcd32677634903a Mon Sep 17 00:00:00 2001 From: Cliff Hansen Date: Fri, 31 Jan 2025 10:51:29 -0700 Subject: [PATCH 7/8] Update pvlib/irradiance.py Co-authored-by: Anton Driesse --- pvlib/irradiance.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index c2a9c9e7b..846560df8 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -2409,7 +2409,7 @@ def _gti_dirint_check_input(aoi): Raises Exceptions from input data that cause the algorithm to fail. """ if not (aoi < 90).any(): - raise ValueError("AOI >= 90 for all input data to gti_dirint. " + raise ValueError("There are no times with AOI < 90. " "gti_dirint requires some data with AOI < 90.") From 93781e2e65e0a649b45f958b4fcfd1cea2c9364c Mon Sep 17 00:00:00 2001 From: Cliff Hansen Date: Fri, 31 Jan 2025 10:56:31 -0700 Subject: [PATCH 8/8] update test --- pvlib/tests/test_irradiance.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pvlib/tests/test_irradiance.py b/pvlib/tests/test_irradiance.py index 239c8b7f8..b56c36677 100644 --- a/pvlib/tests/test_irradiance.py +++ b/pvlib/tests/test_irradiance.py @@ -939,7 +939,7 @@ def test_gti_dirint_data_error(): aoi = np.array([100, 170, 110]) with pytest.raises( - ValueError, match="AOI >= 90 for all input data to gti_dirint"): + ValueError, match="There are no times with AOI < 90"): irradiance.gti_dirint( poa_global, aoi, zenith, azimuth, times, surface_tilt, surface_azimuth)