Skip to content

Commit 5fd9ae8

Browse files
cwhanseadriesse
authored and
Echedey Luis Álvarez
committed
Raise helpful exceptions for irradiance.gti_dirint (#2347)
* add a function to test inputs for gti_dirint * linter * linter * linter * whatsnew * review * Update pvlib/irradiance.py Co-authored-by: Anton Driesse <[email protected]> * update test --------- Co-authored-by: Anton Driesse <[email protected]>
1 parent 4a2664c commit 5fd9ae8

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

docs/sphinx/source/whatsnew/v0.11.3.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Deprecations
1010

1111
Enhancements
1212
~~~~~~~~~~~~
13+
* :py:func:`~pvlib.irradiance.gti_dirint` now raises an informative message
14+
when input data don't include values with AOI<90 (:issue:`1342`, :pull:`2347`)
1315
* Fix a bug in :py:func:`pvlib.bifacial.get_irradiance_poa` which may have yielded non-zero
1416
ground irradiance when the sun was below the horizon. (:issue:`2245`, :pull:`2359`)
1517
* Fix a bug where :py:func:`pvlib.transformer.simple_efficiency` could only be imported
@@ -41,6 +43,7 @@ Contributors
4143
~~~~~~~~~~~~
4244
* Rajiv Daxini (:ghuser:`RDaxini`)
4345
* Mark Campanelli (:ghuser:`markcampanelli`)
46+
* Cliff Hansen (:ghuser:`cwhanse`)
4447
* Jason Lun Leung (:ghuser:`jason-rpkt`)
4548
* Manoj K S (:ghuser:`manojks1999`)
4649
* Kurt Rhee (:ghuser:`kurt-rhee`)

pvlib/irradiance.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2368,6 +2368,9 @@ def gti_dirint(poa_global, aoi, solar_zenith, solar_azimuth, times,
23682368
irradiance, Solar Energy 122, 1037-1046.
23692369
:doi:`10.1016/j.solener.2015.10.024`
23702370
"""
2371+
# check input data and raise Exceptions where data will cause the
2372+
# algorithm to fail
2373+
_gti_dirint_check_input(aoi)
23712374

23722375
aoi_lt_90 = aoi < 90
23732376

@@ -2399,6 +2402,17 @@ def gti_dirint(poa_global, aoi, solar_zenith, solar_azimuth, times,
23992402
return output
24002403

24012404

2405+
def _gti_dirint_check_input(aoi):
2406+
r"""
2407+
Helper for gti_dirint
2408+
2409+
Raises Exceptions from input data that cause the algorithm to fail.
2410+
"""
2411+
if not (aoi < 90).any():
2412+
raise ValueError("There are no times with AOI < 90. "
2413+
"gti_dirint requires some data with AOI < 90.")
2414+
2415+
24022416
def _gti_dirint_lt_90(poa_global, aoi, aoi_lt_90, solar_zenith, solar_azimuth,
24032417
times, surface_tilt, surface_azimuth, pressure=101325.,
24042418
use_delta_kt_prime=True, temp_dew=None, albedo=.25,

tests/test_irradiance.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,23 @@ def test_gti_dirint():
928928
assert_frame_equal(output, expected)
929929

930930

931+
def test_gti_dirint_data_error():
932+
times = pd.DatetimeIndex(
933+
['2014-06-24T06-0700', '2014-06-24T09-0700', '2014-06-24T12-0700'])
934+
poa_global = np.array([20, 300, 1000])
935+
zenith = np.array([80, 45, 20])
936+
azimuth = np.array([90, 135, 180])
937+
surface_tilt = 30
938+
surface_azimuth = 180
939+
940+
aoi = np.array([100, 170, 110])
941+
with pytest.raises(
942+
ValueError, match="There are no times with AOI < 90"):
943+
irradiance.gti_dirint(
944+
poa_global, aoi, zenith, azimuth, times, surface_tilt,
945+
surface_azimuth)
946+
947+
931948
def test_erbs():
932949
index = pd.DatetimeIndex(['20190101']*3 + ['20190620'])
933950
ghi = pd.Series([0, 50, 1000, 1000], index=index)

0 commit comments

Comments
 (0)