From 137114ddc560b03b99a2465870233ecc74422149 Mon Sep 17 00:00:00 2001 From: Cliff Hansen Date: Tue, 7 May 2019 08:38:25 -0600 Subject: [PATCH 1/5] change day angle equation for asce model --- pvlib/irradiance.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index f34ba4b523..304e2c4b23 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -88,7 +88,7 @@ def get_extra_radiation(datetime_or_doy, solar_constant=1366.1, # consider putting asce and spencer methods in their own functions method = method.lower() if method == 'asce': - B = solarposition._calculate_simple_day_angle(to_doy(datetime_or_doy)) + B = (2. * np.pi / 365.) * (to_doy(datetime_or_doy)) RoverR0sqrd = 1 + 0.033 * np.cos(B) elif method == 'spencer': B = solarposition._calculate_simple_day_angle(to_doy(datetime_or_doy)) From b21713538230bfe96277733f0bb6836168bfb680 Mon Sep 17 00:00:00 2001 From: Cliff Hansen Date: Tue, 7 May 2019 08:59:47 -0600 Subject: [PATCH 2/5] update whatsnew --- docs/sphinx/source/whatsnew/v0.6.2.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/sphinx/source/whatsnew/v0.6.2.rst b/docs/sphinx/source/whatsnew/v0.6.2.rst index de00f40816..9521c777d9 100644 --- a/docs/sphinx/source/whatsnew/v0.6.2.rst +++ b/docs/sphinx/source/whatsnew/v0.6.2.rst @@ -46,6 +46,8 @@ Bug fixes near horizon. (:issue:`656`) * Fixed numpy warnings in :py:func:`~pvlib.tracking.singleaxis` when comparing NaN values to limits. (:issue:`622`) +* Fixed a bug in the day angle equation for the ASCE + extraterrestrial irradiance model. (:issue:`211`) Testing From 91d1d35181142a6f837345ff6a9734e73b045e73 Mon Sep 17 00:00:00 2001 From: Cliff Hansen Date: Tue, 7 May 2019 09:48:07 -0600 Subject: [PATCH 3/5] add reference --- pvlib/irradiance.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index e727dc46e2..ba55c00daa 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -80,6 +80,10 @@ def get_extra_radiation(datetime_or_doy, solar_constant=1366.1, [4] Duffie, J. A. and Beckman, W. A. 1991. Solar Engineering of Thermal Processes, 2nd edn. J. Wiley and Sons, New York. + + [5] ASCE (2005), The ASCE Standardized Reference Evapotranspiration + Equation, Environmental and Water Resources Institute of the American + Civil Engineers, Ed. R. G. Allen et al. """ to_doy, to_datetimeindex, to_output = \ From 12d0678c43657d045242d1b19f76fe68f0b19ca8 Mon Sep 17 00:00:00 2001 From: Cliff Hansen Date: Tue, 7 May 2019 10:01:58 -0600 Subject: [PATCH 4/5] add offset kwarg to _calculate_simple_day_angle --- pvlib/irradiance.py | 5 +++-- pvlib/solarposition.py | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index ba55c00daa..000cf3216c 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -81,7 +81,7 @@ def get_extra_radiation(datetime_or_doy, solar_constant=1366.1, [4] Duffie, J. A. and Beckman, W. A. 1991. Solar Engineering of Thermal Processes, 2nd edn. J. Wiley and Sons, New York. - [5] ASCE (2005), The ASCE Standardized Reference Evapotranspiration + [5] ASCE, 2005. The ASCE Standardized Reference Evapotranspiration Equation, Environmental and Water Resources Institute of the American Civil Engineers, Ed. R. G. Allen et al. """ @@ -92,7 +92,8 @@ def get_extra_radiation(datetime_or_doy, solar_constant=1366.1, # consider putting asce and spencer methods in their own functions method = method.lower() if method == 'asce': - B = (2. * np.pi / 365.) * (to_doy(datetime_or_doy)) + B = solarposition._calculate_simple_day_angle(to_doy(datetime_or_doy), + offset=0) RoverR0sqrd = 1 + 0.033 * np.cos(B) elif method == 'spencer': B = solarposition._calculate_simple_day_angle(to_doy(datetime_or_doy)) diff --git a/pvlib/solarposition.py b/pvlib/solarposition.py index 15b8b26665..d55737040b 100644 --- a/pvlib/solarposition.py +++ b/pvlib/solarposition.py @@ -988,19 +988,21 @@ def nrel_earthsun_distance(time, how='numpy', delta_t=67.0, numthreads=4): return dist -def _calculate_simple_day_angle(dayofyear): +def _calculate_simple_day_angle(dayofyear, offset=1): """ Calculates the day angle for the Earth's orbit around the Sun. Parameters ---------- dayofyear : numeric + offset : int, default 1 + For the Spencer method, offset=1; for the ASCE method, offset=0 Returns ------- day_angle : numeric """ - return (2. * np.pi / 365.) * (dayofyear - 1) + return (2. * np.pi / 365.) * (dayofyear - offset) def equation_of_time_spencer71(dayofyear): From fe1cff1704ea2a5fbd820765aba77f7947fa324a Mon Sep 17 00:00:00 2001 From: Cliff Hansen Date: Tue, 7 May 2019 12:37:43 -0600 Subject: [PATCH 5/5] add method kwarg to test --- pvlib/test/test_irradiance.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pvlib/test/test_irradiance.py b/pvlib/test/test_irradiance.py index 19f1e9244f..27598e785d 100644 --- a/pvlib/test/test_irradiance.py +++ b/pvlib/test/test_irradiance.py @@ -90,7 +90,7 @@ def test_deprecated_07(): value = 1383.636203 -@pytest.mark.parametrize('input, expected', [ +@pytest.mark.parametrize('testval, expected', [ (doy, value), (np.float64(doy), value), (dt_date, value), @@ -103,9 +103,9 @@ def test_deprecated_07(): ]) @pytest.mark.parametrize('method', [ 'asce', 'spencer', 'nrel', pytest.param('pyephem', marks=requires_ephem)]) -def test_get_extra_radiation(input, expected, method): - out = irradiance.get_extra_radiation(input) - assert_allclose(out, expected, atol=1) +def test_get_extra_radiation(testval, expected, method): + out = irradiance.get_extra_radiation(testval, method=method) + assert_allclose(out, expected, atol=10) def test_get_extra_radiation_epoch_year():