Skip to content

Commit fabf920

Browse files
anomamwholmgren
authored andcommitted
Implement dirindex decomposition model (#283)
* Starting implementation of DIRINDEX model * making call to DIRINT model * make sure in test that data is returned * Added calculation of DIRINDEX dni values with clearsky model inputs * providing clear sky ghi and dni as arguments so that the user can use different clear sky models * only returning positive values from the calculation * an option could be to provide dni_dirint and dni_dirint_clearsky as arguments as well. Not sure if that's preferable * added docstrings * Adding parenthesis for Python 3 * Added v0.4.3.txt file and references + updated api.rst * Updated dirindex test to compare obtained to expected values * tests for consistency of the algorithm * doesn't exactly test for validity of implementation, need reference values? * adding comparison to dirint values but not sure how relevant it is * Making test more robust + decorator for min build on travis * writing explicit values for input arguments, instead of calling functions * adding ``@needs_numpy_1_10`` decorator for continuous integration
1 parent 04b7a82 commit fabf920

File tree

5 files changed

+137
-2
lines changed

5 files changed

+137
-2
lines changed

docs/sphinx/source/api.rst

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ DNI estimation models
137137

138138
irradiance.disc
139139
irradiance.dirint
140+
irradiance.dirindex
140141
irradiance.erbs
141142
irradiance.liujordan
142143

docs/sphinx/source/whatsnew.rst

+1
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.4.3.txt
910
.. include:: whatsnew/v0.4.2.txt
1011
.. include:: whatsnew/v0.4.1.txt
1112
.. include:: whatsnew/v0.4.0.txt
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.. _whatsnew_0430:
2+
3+
v0.4.3 (December 13, 2016)
4+
--------------------------
5+
6+
Enhancements
7+
~~~~~~~~~~~~
8+
9+
* Adding implementation of Perez's DIRINDEX model based on existing DIRINT
10+
model implementation. (:issue:`282`)
11+
12+
Code Contributors
13+
~~~~~~~~~~~~~~~~~
14+
15+
* Marc Anoma

pvlib/irradiance.py

+81-1
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,7 @@ def dirint(ghi, zenith, times, pressure=101325., use_delta_kt_prime=True,
12231223
Notes
12241224
-----
12251225
DIRINT model requires time series data (ie. one of the inputs must
1226-
be a vector of length > 2.
1226+
be a vector of length > 2).
12271227
12281228
References
12291229
----------
@@ -1319,6 +1319,86 @@ def dirint(ghi, zenith, times, pressure=101325., use_delta_kt_prime=True,
13191319
return dni
13201320

13211321

1322+
def dirindex(ghi, ghi_clearsky, dni_clearsky, zenith, times, pressure=101325.,
1323+
use_delta_kt_prime=True, temp_dew=None):
1324+
"""
1325+
Determine DNI from GHI using the DIRINDEX model, which is a modification of
1326+
the DIRINT model with information from a clear sky model.
1327+
1328+
DIRINDEX [1] improves upon the DIRINT model by taking into account turbidity
1329+
when used with the Ineichen clear sky model results.
1330+
1331+
Parameters
1332+
----------
1333+
ghi : array-like
1334+
Global horizontal irradiance in W/m^2.
1335+
1336+
ghi_clearsky : array-like
1337+
Global horizontal irradiance from clear sky model, in W/m^2.
1338+
1339+
dni_clearsky : array-like
1340+
Direct normal irradiance from clear sky model, in W/m^2.
1341+
1342+
zenith : array-like
1343+
True (not refraction-corrected) zenith angles in decimal
1344+
degrees. If Z is a vector it must be of the same size as all
1345+
other vector inputs. Z must be >=0 and <=180.
1346+
1347+
times : DatetimeIndex
1348+
1349+
pressure : float or array-like
1350+
The site pressure in Pascal. Pressure may be measured or an
1351+
average pressure may be calculated from site altitude.
1352+
1353+
use_delta_kt_prime : bool
1354+
Indicates if the user would like to utilize the time-series
1355+
nature of the GHI measurements. A value of ``False`` will not
1356+
use the time-series improvements, any other numeric value will
1357+
use time-series improvements. It is recommended that time-series
1358+
data only be used if the time between measured data points is
1359+
less than 1.5 hours. If none of the input arguments are vectors,
1360+
then time-series improvements are not used (because it's not a
1361+
time-series). If True, input data must be Series.
1362+
1363+
temp_dew : None, float, or array-like
1364+
Surface dew point temperatures, in degrees C. Values of temp_dew
1365+
may be numeric or NaN. Any single time period point with a
1366+
DewPtTemp=NaN does not have dew point improvements applied. If
1367+
DewPtTemp is not provided, then dew point improvements are not
1368+
applied.
1369+
1370+
Returns
1371+
-------
1372+
dni : array-like
1373+
The modeled direct normal irradiance in W/m^2.
1374+
1375+
Notes
1376+
-----
1377+
DIRINDEX model requires time series data (ie. one of the inputs must
1378+
be a vector of length > 2).
1379+
1380+
References
1381+
----------
1382+
[1] Perez, R., Ineichen, P., Moore, K., Kmiecik, M., Chain, C., George, R.,
1383+
& Vignola, F. (2002). A new operational model for satellite-derived
1384+
irradiances: description and validation. Solar Energy, 73(5), 307-317.
1385+
"""
1386+
1387+
dni_dirint = dirint(ghi, zenith, times, pressure=pressure,
1388+
use_delta_kt_prime=use_delta_kt_prime,
1389+
temp_dew=temp_dew)
1390+
1391+
dni_dirint_clearsky = dirint(ghi_clearsky, zenith, times, pressure=pressure,
1392+
use_delta_kt_prime=use_delta_kt_prime,
1393+
temp_dew=temp_dew)
1394+
1395+
dni_dirindex = dni_clearsky * dni_dirint / dni_dirint_clearsky
1396+
1397+
dni_dirindex[dni_dirindex < 0] = 0.
1398+
1399+
return dni_dirindex
1400+
1401+
13221402
def erbs(ghi, zenith, doy):
13231403
r"""
13241404
Estimate DNI and DHI from GHI using the Erbs model.

pvlib/test/test_irradiance.py

+39-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
dt_np64 = np.datetime64(dt_datetime)
4343
value = 1383.636203
4444

45+
4546
@pytest.mark.parametrize('input, expected', [
4647
(doy, value),
4748
(np.float64(doy), value),
@@ -194,7 +195,6 @@ def test_perez_arrays():
194195
assert_allclose(out, expected, atol=1e-2)
195196

196197

197-
198198
def test_liujordan():
199199
expected = pd.DataFrame(np.
200200
array([[863.859736967, 653.123094076, 220.65905025]]),
@@ -286,6 +286,7 @@ def test_dirint():
286286
dirint_data = irradiance.dirint(clearsky_data['ghi'], ephem_data['zenith'],
287287
ephem_data.index, pressure=pressure)
288288

289+
289290
def test_dirint_value():
290291
times = pd.DatetimeIndex(['2014-06-24T12-0700','2014-06-24T18-0700'])
291292
ghi = pd.Series([1038.62, 254.53], index=times)
@@ -318,6 +319,7 @@ def test_dirint_tdew():
318319
assert_almost_equal(dirint_data.values,
319320
np.array([892.9, 636.5]), 1)
320321

322+
321323
def test_dirint_no_delta_kt():
322324
times = pd.DatetimeIndex(['2014-06-24T12-0700','2014-06-24T18-0700'])
323325
ghi = pd.Series([1038.62, 254.53], index=times)
@@ -328,6 +330,7 @@ def test_dirint_no_delta_kt():
328330
assert_almost_equal(dirint_data.values,
329331
np.array([861.9, 670.4]), 1)
330332

333+
331334
def test_dirint_coeffs():
332335
coeffs = irradiance._get_dirint_coeffs()
333336
assert coeffs[0,0,0,0] == 0.385230
@@ -365,3 +368,38 @@ def test_erbs_all_scalar():
365368

366369
for k, v in out.items():
367370
assert_allclose(v, expected[k], 5)
371+
372+
@needs_numpy_1_10
373+
def test_dirindex():
374+
clearsky_data = tus.get_clearsky(times, model='ineichen',
375+
linke_turbidity=3)
376+
ghi = pd.Series([0, 0, 1038.62, 254.53], index=times)
377+
ghi_clearsky = pd.Series(
378+
np.array([0., 79.73860422, 1042.48031487, 257.20751138]),
379+
index=times
380+
)
381+
dni_clearsky = pd.Series(
382+
np.array([0., 316.1949056, 939.95469881, 646.22886049]),
383+
index=times
384+
)
385+
zenith = pd.Series(
386+
np.array([124.0390863, 82.85457044, 10.56413562, 72.41687122]),
387+
index=times
388+
)
389+
pressure = 93193.
390+
tdew = 10.
391+
out = irradiance.dirindex(ghi, ghi_clearsky, dni_clearsky,
392+
zenith, times, pressure=pressure,
393+
temp_dew=tdew)
394+
dirint_close_values = irradiance.dirint(ghi, zenith, times,
395+
pressure=pressure,
396+
use_delta_kt_prime=True,
397+
temp_dew=tdew).values
398+
expected_out = np.array([np.nan, 0., 748.31562753, 630.72592644])
399+
400+
tolerance = 1e-8
401+
assert np.allclose(out, expected_out, rtol=tolerance, atol=0,
402+
equal_nan=True)
403+
tol_dirint = 0.2
404+
assert np.allclose(out.values, dirint_close_values, rtol=tol_dirint, atol=0,
405+
equal_nan=True)

0 commit comments

Comments
 (0)