diff --git a/docs/sphinx/source/whatsnew/v0.6.2.rst b/docs/sphinx/source/whatsnew/v0.6.2.rst index c06c3640c0..024b162e82 100644 --- a/docs/sphinx/source/whatsnew/v0.6.2.rst +++ b/docs/sphinx/source/whatsnew/v0.6.2.rst @@ -47,6 +47,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`) * Silenced divide by 0 irradiance warnings in :py:func:`~pvlib.irradiance.klucher` and :py:func:`~pvlib.pvsystem.calcparams_desoto`. (:issue:`698`) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index f45c658660..000cf3216c 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 = \ @@ -88,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 = solarposition._calculate_simple_day_angle(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): 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():