Skip to content

Commit e92ee94

Browse files
echedey-lsadriesse
andauthored
Correct usage of xtol in ghi_from_poa_driesse_2023 (#1971)
* Fix typo * Add test * why is always the linter * Update test_irradiance.py * Update v0.10.4.rst * Am I faster that the linter? * Again the linter * Clear up comments * Update irradiance.py Co-Authored-By: Anton Driesse <[email protected]> * Update test_irradiance.py --------- Co-authored-by: Anton Driesse <[email protected]>
1 parent 26acf8a commit e92ee94

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Bug fixes
1414
~~~~~~~~~
1515
* :py:class:`~pvlib.modelchain.ModelChain` now raises a more useful error when
1616
``temperature_model_parameters`` are specified on the passed ``system`` instead of on its ``arrays``. (:issue:`1759`).
17+
* :py:func:`pvlib.irradiance.ghi_from_poa_driesse_2023` now correctly makes use
18+
of the ``xtol`` argument. Previously, it was ignored. (:issue:`1970`, :pull:`1971`)
1719

1820
Testing
1921
~~~~~~~

pvlib/irradiance.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,8 +1557,8 @@ def ghi_from_poa_driesse_2023(surface_tilt, surface_azimuth,
15571557
albedo : numeric, default 0.25
15581558
Ground surface albedo. [unitless]
15591559
xtol : numeric, default 0.01
1560-
Convergence criterion. The estimated GHI will be within xtol of the
1561-
true value. [W/m^2]
1560+
Convergence criterion. The estimated GHI will be within xtol of the
1561+
true value. Must be positive. [W/m^2]
15621562
full_output : boolean, default False
15631563
If full_output is False, only ghi is returned, otherwise the return
15641564
value is (ghi, converged, niter). (see Returns section for details).
@@ -1593,13 +1593,16 @@ def ghi_from_poa_driesse_2023(surface_tilt, surface_azimuth,
15931593
'''
15941594
# Contributed by Anton Driesse (@adriesse), PV Performance Labs. Nov., 2023
15951595

1596+
if xtol <= 0:
1597+
raise ValueError(f"xtol too small ({xtol:g} <= 0)")
1598+
15961599
ghi_from_poa_array = np.vectorize(_ghi_from_poa)
15971600

15981601
ghi, conv, niter = ghi_from_poa_array(surface_tilt, surface_azimuth,
15991602
solar_zenith, solar_azimuth,
16001603
poa_global,
16011604
dni_extra, airmass, albedo,
1602-
xtol=0.01)
1605+
xtol=xtol)
16031606

16041607
if isinstance(poa_global, pd.Series):
16051608
ghi = pd.Series(ghi, poa_global.index)

pvlib/tests/test_irradiance.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ def test_dirint_min_cos_zenith_max_zenith():
782782
assert_series_equal(out, expected, check_less_precise=True)
783783

784784

785-
def test_ghi_from_poa_driesse():
785+
def test_ghi_from_poa_driesse(mocker):
786786
# inputs copied from test_gti_dirint
787787
times = pd.DatetimeIndex(
788788
['2014-06-24T06-0700', '2014-06-24T09-0700', '2014-06-24T12-0700'])
@@ -825,6 +825,22 @@ def test_ghi_from_poa_driesse():
825825
expected = [0, -1, 0]
826826
assert_allclose(expected, niter)
827827

828+
# test xtol argument
829+
poa_global = pd.Series([20, 300, 1000], index=times)
830+
# test exception
831+
xtol = -3.14159 # negative value raises exception in scipy.optimize.bisect
832+
with pytest.raises(ValueError, match=rf"xtol too small \({xtol:g} <= 0\)"):
833+
output = irradiance.ghi_from_poa_driesse_2023(
834+
surface_tilt, surface_azimuth, zenith, azimuth,
835+
poa_global, dni_extra=1366.1, xtol=xtol)
836+
# test propagation
837+
xtol = 3.141592
838+
bisect_spy = mocker.spy(irradiance, "bisect")
839+
output = irradiance.ghi_from_poa_driesse_2023(
840+
surface_tilt, surface_azimuth, zenith, azimuth,
841+
poa_global, dni_extra=1366.1, xtol=xtol)
842+
assert bisect_spy.call_args[1]["xtol"] == xtol
843+
828844

829845
def test_gti_dirint():
830846
times = pd.DatetimeIndex(

0 commit comments

Comments
 (0)