Skip to content

Commit 39c0862

Browse files
cwhansewholmgren
authored andcommitted
Handle overflow condition in pvlib.clearsky.haurwitz (#364)
* Improve convergence of lambertw for very large arguments * Revert "Improve convergence of lambertw for very large arguments" This reverts commit d83d77d. * Handle overflow warning; revise test case Handles overflow when apparent zenith is slight greater than 90. Revised test case to operate on zenith rather than time, removes dependence on solarposition. * Fix test case Resolve errors in test definition * more fixes Remove use of np.where in haurwitz, fix declaration of pandas objects * Fix pandas objects Changed np arrays from 2d to 1d for use as dataframe indices * more fixes Resolving type conflict inside haurwitz function for casting output as a dataframe * Final edits Fix line length, formatting and documentation in clearsky.haurwitz. Create whatsnew\v0.5.1.rst. Delete commented old code from test\test_clearsky.py
1 parent d372fd3 commit 39c0862

File tree

4 files changed

+56
-27
lines changed

4 files changed

+56
-27
lines changed

docs/sphinx/source/whatsnew.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ What's New
66

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

9+
.. include:: whatsnew/v0.5.1.rst
910
.. include:: whatsnew/v0.5.0.rst
1011
.. include:: whatsnew/v0.4.5.txt
1112
.. include:: whatsnew/v0.4.4.txt
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.. _whatsnew_0500:
2+
3+
v0.5.0 (August 11, 2017)
4+
------------------------
5+
6+
API Changes
7+
~~~~~~~~~~~
8+
*
9+
10+
Bug fixes
11+
~~~~~~~~~
12+
* Remove condition causing Overflow warning from clearsky.haurwitz
13+
14+
Enhancements
15+
~~~~~~~~~~~~
16+
*
17+
18+
Documentation
19+
~~~~~~~~~~~~~
20+
*
21+
22+
Testing
23+
~~~~~~~
24+
* Changed test for clearsky.haurwitz to operate on zenith angles
25+
26+
Contributors
27+
~~~~~~~~~~~~
28+
* Cliff Hansen

pvlib/clearsky.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,9 @@ def haurwitz(apparent_zenith):
294294
295295
Implements the Haurwitz clear sky model for global horizontal
296296
irradiance (GHI) as presented in [1, 2]. A report on clear
297-
sky models found the Haurwitz model to have the best performance of
298-
models which require only zenith angle [3]. Extreme care should
299-
be taken in the interpretation of this result!
297+
sky models found the Haurwitz model to have the best performance
298+
in terms of average monthly error among models which require only
299+
zenith angle [3].
300300
301301
Parameters
302302
----------
@@ -306,7 +306,7 @@ def haurwitz(apparent_zenith):
306306
307307
Returns
308308
-------
309-
pd.Series
309+
pd.DataFrame
310310
The modeled global horizonal irradiance in W/m^2 provided
311311
by the Haurwitz clear-sky model.
312312
@@ -326,13 +326,14 @@ def haurwitz(apparent_zenith):
326326
Laboratories, SAND2012-2389, 2012.
327327
'''
328328

329-
cos_zenith = tools.cosd(apparent_zenith)
329+
cos_zenith = tools.cosd(apparent_zenith.values)
330+
clearsky_ghi = np.zeros_like(apparent_zenith.values)
331+
clearsky_ghi[cos_zenith>0] = 1098.0 * cos_zenith[cos_zenith>0] * \
332+
np.exp(-0.059/cos_zenith[cos_zenith>0])
330333

331-
clearsky_ghi = 1098.0 * cos_zenith * np.exp(-0.059/cos_zenith)
332-
333-
clearsky_ghi[clearsky_ghi < 0] = 0
334-
335-
df_out = pd.DataFrame({'ghi': clearsky_ghi})
334+
df_out = pd.DataFrame(index=apparent_zenith.index,
335+
data=clearsky_ghi,
336+
columns=['ghi'])
336337

337338
return df_out
338339

pvlib/test/test_clearsky.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -234,25 +234,24 @@ def test_lookup_linke_turbidity_nointerp_months():
234234

235235

236236
def test_haurwitz():
237-
tus = Location(32.2, -111, 'US/Arizona', 700)
238-
times = pd.date_range(start='2014-06-24', end='2014-06-25', freq='3h')
239-
times_localized = times.tz_localize(tus.tz)
240-
ephem_data = solarposition.get_solarposition(times_localized, tus.latitude,
241-
tus.longitude)
242-
expected = pd.DataFrame(np.array([[0.],
243-
[0.],
244-
[82.85934048],
245-
[699.74514735],
246-
[1016.50198354],
247-
[838.32103769],
248-
[271.90853863],
249-
[0.],
250-
[0.]]),
251-
columns=['ghi'], index=times_localized)
252-
out = clearsky.haurwitz(ephem_data['zenith'])
237+
apparent_solar_elevation = np.array([-20, -0.05, -0.001, 5, 10, 30, 50, 90])
238+
apparent_solar_zenith = 90 - apparent_solar_elevation
239+
data_in = pd.DataFrame(data=apparent_solar_zenith,
240+
index=apparent_solar_zenith,
241+
columns=['apparent_zenith'])
242+
expected = pd.DataFrame(np.array([0.,
243+
0.,
244+
0.,
245+
48.6298687941956,
246+
135.741748091813,
247+
487.894132885425,
248+
778.766689344363,
249+
1035.09203253450]),
250+
columns=['ghi'],
251+
index=apparent_solar_zenith)
252+
out = clearsky.haurwitz(data_in['apparent_zenith'])
253253
assert_frame_equal(expected, out)
254254

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

0 commit comments

Comments
 (0)