Skip to content

Handle overflow condition in pvlib.clearsky.haurwitz #364

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 9 commits into from
Aug 15, 2017
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
1 change: 1 addition & 0 deletions docs/sphinx/source/whatsnew.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ What's New

These are new features and improvements of note in each release.

.. include:: whatsnew/v0.5.1.rst
.. include:: whatsnew/v0.5.0.rst
.. include:: whatsnew/v0.4.5.txt
.. include:: whatsnew/v0.4.4.txt
Expand Down
28 changes: 28 additions & 0 deletions docs/sphinx/source/whatsnew/v0.5.1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.. _whatsnew_0500:

v0.5.0 (August 11, 2017)
------------------------

API Changes
~~~~~~~~~~~
*

Bug fixes
~~~~~~~~~
* Remove condition causing Overflow warning from clearsky.haurwitz

Enhancements
~~~~~~~~~~~~
*

Documentation
~~~~~~~~~~~~~
*

Testing
~~~~~~~
* Changed test for clearsky.haurwitz to operate on zenith angles

Contributors
~~~~~~~~~~~~
* Cliff Hansen
21 changes: 11 additions & 10 deletions pvlib/clearsky.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,9 @@ def haurwitz(apparent_zenith):

Implements the Haurwitz clear sky model for global horizontal
irradiance (GHI) as presented in [1, 2]. A report on clear
sky models found the Haurwitz model to have the best performance of
models which require only zenith angle [3]. Extreme care should
be taken in the interpretation of this result!
sky models found the Haurwitz model to have the best performance
in terms of average monthly error among models which require only
zenith angle [3].

Parameters
----------
Expand All @@ -306,7 +306,7 @@ def haurwitz(apparent_zenith):

Returns
-------
pd.Series
pd.DataFrame
The modeled global horizonal irradiance in W/m^2 provided
by the Haurwitz clear-sky model.

Expand All @@ -326,13 +326,14 @@ def haurwitz(apparent_zenith):
Laboratories, SAND2012-2389, 2012.
'''

cos_zenith = tools.cosd(apparent_zenith)
cos_zenith = tools.cosd(apparent_zenith.values)
clearsky_ghi = np.zeros_like(apparent_zenith.values)
clearsky_ghi[cos_zenith>0] = 1098.0 * cos_zenith[cos_zenith>0] * \
np.exp(-0.059/cos_zenith[cos_zenith>0])

clearsky_ghi = 1098.0 * cos_zenith * np.exp(-0.059/cos_zenith)

clearsky_ghi[clearsky_ghi < 0] = 0

df_out = pd.DataFrame({'ghi': clearsky_ghi})
df_out = pd.DataFrame(index=apparent_zenith.index,
data=clearsky_ghi,
columns=['ghi'])

return df_out

Expand Down
33 changes: 16 additions & 17 deletions pvlib/test/test_clearsky.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,25 +234,24 @@ def test_lookup_linke_turbidity_nointerp_months():


def test_haurwitz():
tus = Location(32.2, -111, 'US/Arizona', 700)
times = pd.date_range(start='2014-06-24', end='2014-06-25', freq='3h')
times_localized = times.tz_localize(tus.tz)
ephem_data = solarposition.get_solarposition(times_localized, tus.latitude,
tus.longitude)
expected = pd.DataFrame(np.array([[0.],
[0.],
[82.85934048],
[699.74514735],
[1016.50198354],
[838.32103769],
[271.90853863],
[0.],
[0.]]),
columns=['ghi'], index=times_localized)
out = clearsky.haurwitz(ephem_data['zenith'])
apparent_solar_elevation = np.array([-20, -0.05, -0.001, 5, 10, 30, 50, 90])
apparent_solar_zenith = 90 - apparent_solar_elevation
data_in = pd.DataFrame(data=apparent_solar_zenith,
index=apparent_solar_zenith,
columns=['apparent_zenith'])
expected = pd.DataFrame(np.array([0.,
0.,
0.,
48.6298687941956,
135.741748091813,
487.894132885425,
778.766689344363,
1035.09203253450]),
columns=['ghi'],
index=apparent_solar_zenith)
out = clearsky.haurwitz(data_in['apparent_zenith'])
assert_frame_equal(expected, out)


def test_simplified_solis_series_elevation():
tus = Location(32.2, -111, 'US/Arizona', 700)
times = pd.date_range(start='2014-06-24', end='2014-06-25', freq='3h')
Expand Down