Skip to content

Correct day angle in ASCE extraterrestrial irradiance model #712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/sphinx/source/whatsnew/v0.6.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
7 changes: 6 additions & 1 deletion pvlib/irradiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = \
Expand All @@ -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))
Expand Down
6 changes: 4 additions & 2 deletions pvlib/solarposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions pvlib/test/test_irradiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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():
Expand Down