From d6bcef97ad59098d0103339b25764eab1734a671 Mon Sep 17 00:00:00 2001 From: Mark Mikofski Date: Wed, 25 Jul 2018 13:58:08 -0700 Subject: [PATCH 1/3] BUG: fix klucher nan output for numpy * fixes #508 * use `F = np.where(np.isnan(F), 0, F) to only replace `nan` with zero * previously if numpy array with nan, then entire array was zeroed so output differed from pandas series input --- pvlib/irradiance.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index fd03c3ffac..30060714f7 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -629,7 +629,7 @@ def klucher(surface_tilt, surface_azimuth, dhi, ghi, solar_zenith, # fails with single point input F.fillna(0, inplace=True) except AttributeError: - F = 0 + F = np.where(np.isnan(F), 0, F) term1 = 0.5 * (1 + tools.cosd(surface_tilt)) term2 = 1 + F * (tools.sind(0.5 * surface_tilt) ** 3) From 9979fe74832f47f8de6971a477c2135cb3f37c83 Mon Sep 17 00:00:00 2001 From: Mark Mikofski Date: Wed, 25 Jul 2018 14:32:38 -0700 Subject: [PATCH 2/3] update klucker tests * the original test had the bug in it, because floats don't have `fillna` attribute, **but** that doesn't mean that the value was `NaN`! * instead of hard-coding the expected value, what we really expect is that it should produce the same value as the pandas series result * also compare the pandas series result to a numpy array of the same --- pvlib/test/test_irradiance.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/pvlib/test/test_irradiance.py b/pvlib/test/test_irradiance.py index ef9599e7b2..31ebbcb532 100644 --- a/pvlib/test/test_irradiance.py +++ b/pvlib/test/test_irradiance.py @@ -114,8 +114,20 @@ def test_isotropic_series(): def test_klucher_series_float(): - result = irradiance.klucher(40, 180, 100, 900, 20, 180) - assert_allclose(result, 88.3022221559) + # klucher inputs + surface_tilt, surface_azimuth = 40.0, 180.0 + dhi, ghi = 100.0, 900.0 + solar_zenith, solar_azimuth = 20.0, 180.0 + # expect same result for floats and pd.Series + expected = irradiance.klucher( + surface_tilt, surface_azimuth, + pd.Series(dhi), pd.Series(ghi), + pd.Series(solar_zenith), pd.Series(solar_azimuth) + ) # 94.99429931664851 + result = irradiance.klucher( + surface_tilt, surface_azimuth, dhi, ghi, solar_zenith, solar_azimuth + ) + assert_allclose(result, expected[0]) def test_klucher_series(): @@ -123,6 +135,12 @@ def test_klucher_series(): ephem_data['apparent_zenith'], ephem_data['azimuth']) assert_allclose(result, [0, 37.446276, 109.209347, 56.965916], atol=1e-4) + # expect same result for np.array and pd.Series + expected = irradiance.klucher( + 40, 180, irrad_data['dhi'].values, irrad_data['ghi'].values, + ephem_data['apparent_zenith'].values, ephem_data['azimuth'].values + ) + assert_allclose(result, expected, atol=1e-4) def test_haydavies(): From 79bb144c0a3525d09f2ff5b2e02d7bc5f86a23fa Mon Sep 17 00:00:00 2001 From: Mark Mikofski Date: Wed, 25 Jul 2018 16:35:18 -0700 Subject: [PATCH 3/3] DOC: MAINT: update what's new --- docs/sphinx/source/whatsnew/v0.6.0.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/sphinx/source/whatsnew/v0.6.0.rst b/docs/sphinx/source/whatsnew/v0.6.0.rst index 009f015e62..1aa535c477 100644 --- a/docs/sphinx/source/whatsnew/v0.6.0.rst +++ b/docs/sphinx/source/whatsnew/v0.6.0.rst @@ -59,7 +59,8 @@ Bug fixes Location.get_clearsky. Fixed. (:issue:`481`) * Add User-Agent specification to TMY3 remote requests to avoid rejection. (:issue:`493`) - +* Fix ``pvlib.irradiance.klucher`` output is different for Pandas Series vs. + floats and NumPy arrays. (:issue:`508`) Documentation ~~~~~~~~~~~~~