@@ -1313,12 +1313,12 @@ def _get_perez_coefficients(perezmodelt):
1313
1313
1314
1314
def disc (ghi , zenith , times , pressure = 101325 ):
1315
1315
'''
1316
- Estimate Direct Normal Irradiance from Global Horizontal Irradiance
1316
+ Estimate Direct Normal Irradiance from Global Horizontal Irradiance
1317
1317
using the DISC model.
1318
1318
1319
1319
The DISC algorithm converts global horizontal irradiance to direct
1320
1320
normal irradiance through empirical relationships between the global
1321
- and direct clearness indices.
1321
+ and direct clearness indices.
1322
1322
1323
1323
Parameters
1324
1324
----------
@@ -1327,62 +1327,62 @@ def disc(ghi, zenith, times, pressure=101325):
1327
1327
Global horizontal irradiance in W/m^2.
1328
1328
1329
1329
solar_zenith : Series
1330
- True (not refraction - corrected) solar zenith
1331
- angles in decimal degrees.
1330
+ True (not refraction - corrected) solar zenith
1331
+ angles in decimal degrees.
1332
1332
1333
1333
times : DatetimeIndex
1334
1334
1335
1335
pressure : float or Series
1336
1336
Site pressure in Pascal.
1337
1337
1338
- Returns
1338
+ Returns
1339
1339
-------
1340
1340
DataFrame with the following keys:
1341
- * ``dni``: The modeled direct normal irradiance
1341
+ * ``dni``: The modeled direct normal irradiance
1342
1342
in W/m^2 provided by the
1343
- Direct Insolation Simulation Code (DISC) model.
1344
- * ``kt``: Ratio of global to extraterrestrial
1343
+ Direct Insolation Simulation Code (DISC) model.
1344
+ * ``kt``: Ratio of global to extraterrestrial
1345
1345
irradiance on a horizontal plane.
1346
1346
* ``airmass``: Airmass
1347
1347
1348
1348
References
1349
1349
----------
1350
1350
1351
- [1] Maxwell, E. L., "A Quasi-Physical Model for Converting Hourly
1352
- Global Horizontal to Direct Normal Insolation", Technical
1353
- Report No. SERI/TR-215-3087, Golden, CO: Solar Energy Research
1351
+ [1] Maxwell, E. L., "A Quasi-Physical Model for Converting Hourly
1352
+ Global Horizontal to Direct Normal Insolation", Technical
1353
+ Report No. SERI/TR-215-3087, Golden, CO: Solar Energy Research
1354
1354
Institute, 1987.
1355
1355
1356
- [2] J.W. "Fourier series representation of the position of the sun".
1356
+ [2] J.W. "Fourier series representation of the position of the sun".
1357
1357
Found at:
1358
1358
http://www.mail-archive.com/[email protected] /msg01050.html on
1359
1359
January 12, 2012
1360
1360
1361
- See Also
1362
- --------
1363
- atmosphere.alt2pres
1361
+ See Also
1362
+ --------
1363
+ atmosphere.alt2pres
1364
1364
dirint
1365
1365
'''
1366
1366
1367
1367
pvl_logger .debug ('clearsky.disc' )
1368
-
1368
+
1369
1369
temp = pd .DataFrame (index = times , columns = ['A' ,'B' ,'C' ], dtype = float )
1370
1370
1371
1371
doy = times .dayofyear
1372
-
1372
+
1373
1373
DayAngle = 2. * np .pi * (doy - 1 ) / 365
1374
-
1374
+
1375
1375
re = (1.00011 + 0.034221 * np .cos (DayAngle ) + 0.00128 * np .sin (DayAngle )
1376
1376
+ 0.000719 * np .cos (2. * DayAngle ) + 7.7e-05 * np .sin (2. * DayAngle ) )
1377
-
1377
+
1378
1378
I0 = re * 1370.
1379
1379
I0h = I0 * np .cos (np .radians (zenith ))
1380
-
1380
+
1381
1381
Ztemp = zenith .copy ()
1382
1382
Ztemp [zenith > 87 ] = np .NaN
1383
-
1383
+
1384
1384
AM = 1.0 / ( np .cos (np .radians (Ztemp )) + 0.15 * ( (93.885 - Ztemp )** (- 1.253 ) ) ) * (pressure / 101325 )
1385
-
1385
+
1386
1386
Kt = ghi / I0h
1387
1387
Kt [Kt < 0 ] = 0
1388
1388
Kt [Kt > 2 ] = np .NaN
@@ -1395,10 +1395,10 @@ def disc(ghi, zenith, times, pressure=101325):
1395
1395
temp .C [Kt <= 0.6 ] = - 0.28 + 0.932 * (Kt [Kt <= 0.6 ]) - 2.048 * (Kt [Kt <= 0.6 ] ** 2 )
1396
1396
1397
1397
delKn = temp .A + temp .B * np .exp (temp .C * AM )
1398
-
1398
+
1399
1399
Knc = 0.866 - 0.122 * (AM ) + 0.0121 * (AM ** 2 ) - 0.000653 * (AM ** 3 ) + 1.4e-05 * (AM ** 4 )
1400
1400
Kn = Knc - delKn
1401
-
1401
+
1402
1402
dni = Kn * I0
1403
1403
1404
1404
dni [zenith > 87 ] = np .NaN
@@ -1409,14 +1409,14 @@ def disc(ghi, zenith, times, pressure=101325):
1409
1409
dfout ['airmass' ] = AM
1410
1410
1411
1411
return dfout
1412
-
1413
1412
1414
- def dirint (ghi , zenith , times , pressure = 101325 , use_delta_kt_prime = True ,
1413
+
1414
+ def dirint (ghi , zenith , times , pressure = 101325 , use_delta_kt_prime = True ,
1415
1415
temp_dew = None ):
1416
1416
"""
1417
- Determine DNI from GHI using the DIRINT modification
1417
+ Determine DNI from GHI using the DIRINT modification
1418
1418
of the DISC model.
1419
-
1419
+
1420
1420
Implements the modified DISC model known as "DIRINT" introduced in [1].
1421
1421
DIRINT predicts direct normal irradiance (DNI) from measured global
1422
1422
horizontal irradiance (GHI). DIRINT improves upon the DISC model by
@@ -1425,22 +1425,22 @@ def dirint(ghi, zenith, times, pressure=101325, use_delta_kt_prime=True,
1425
1425
information provided.
1426
1426
1427
1427
Parameters
1428
- ----------
1428
+ ----------
1429
1429
ghi : pd.Series
1430
- Global horizontal irradiance in W/m^2.
1431
-
1430
+ Global horizontal irradiance in W/m^2.
1431
+
1432
1432
zenith : pd.Series
1433
1433
True (not refraction-corrected) zenith
1434
1434
angles in decimal degrees. If Z is a vector it must be of the
1435
1435
same size as all other vector inputs. Z must be >=0 and <=180.
1436
-
1436
+
1437
1437
times : DatetimeIndex
1438
-
1438
+
1439
1439
pressure : float or pd.Series
1440
- The site pressure in Pascal.
1441
- Pressure may be measured or an average pressure may be
1440
+ The site pressure in Pascal.
1441
+ Pressure may be measured or an average pressure may be
1442
1442
calculated from site altitude.
1443
-
1443
+
1444
1444
use_delta_kt_prime : bool
1445
1445
Indicates if the user would like to
1446
1446
utilize the time-series nature of the GHI measurements. A value of ``False``
@@ -1450,13 +1450,13 @@ def dirint(ghi, zenith, times, pressure=101325, use_delta_kt_prime=True,
1450
1450
than 1.5 hours. If none of the input arguments are
1451
1451
vectors, then time-series improvements are not used (because it's not
1452
1452
a time-series).
1453
-
1454
- temp_dew : None, float, or pd.Series
1455
- Surface dew point temperatures, in degrees C.
1453
+
1454
+ temp_dew : None, float, or pd.Series
1455
+ Surface dew point temperatures, in degrees C.
1456
1456
Values of temp_dew may be numeric or NaN. Any
1457
1457
single time period point with a DewPtTemp=NaN does not have dew point
1458
- improvements applied. If DewPtTemp is not provided, then dew point
1459
- improvements are not applied.
1458
+ improvements applied. If DewPtTemp is not provided, then dew point
1459
+ improvements are not applied.
1460
1460
1461
1461
Returns
1462
1462
-------
@@ -1467,57 +1467,58 @@ def dirint(ghi, zenith, times, pressure=101325, use_delta_kt_prime=True,
1467
1467
References
1468
1468
----------
1469
1469
[1] Perez, R., P. Ineichen, E. Maxwell, R. Seals and A. Zelenka, (1992).
1470
- "Dynamic Global-to-Direct Irradiance Conversion Models". ASHRAE
1470
+ "Dynamic Global-to-Direct Irradiance Conversion Models". ASHRAE
1471
1471
Transactions-Research Series, pp. 354-369
1472
1472
1473
- [2] Maxwell, E. L., "A Quasi-Physical Model for Converting Hourly
1474
- Global Horizontal to Direct Normal Insolation", Technical
1475
- Report No. SERI/TR-215-3087, Golden, CO: Solar Energy Research
1473
+ [2] Maxwell, E. L., "A Quasi-Physical Model for Converting Hourly
1474
+ Global Horizontal to Direct Normal Insolation", Technical
1475
+ Report No. SERI/TR-215-3087, Golden, CO: Solar Energy Research
1476
1476
Institute, 1987.
1477
1477
1478
1478
DIRINT model requires time series data (ie. one of the inputs must be a
1479
1479
vector of length >2.
1480
1480
"""
1481
-
1481
+
1482
1482
pvl_logger .debug ('clearsky.dirint' )
1483
-
1483
+
1484
1484
disc_out = disc (ghi , zenith , times )
1485
1485
kt = disc_out ['kt' ]
1486
-
1486
+
1487
1487
# Absolute Airmass, per the DISC model
1488
1488
# Note that we calculate the AM pressure correction slightly differently
1489
1489
# than Perez. He uses altitude, we use pressure (which we calculate
1490
1490
# slightly differently)
1491
- airmass = (1. / (tools .cosd (zenith ) + 0.15 * ((93.885 - zenith )** (- 1.253 ))) *
1491
+ airmass = (1. / (tools .cosd (zenith ) + 0.15 * ((93.885 - zenith )** (- 1.253 ))) *
1492
1492
pressure / 101325 )
1493
-
1493
+
1494
1494
coeffs = _get_dirint_coeffs ()
1495
-
1495
+
1496
1496
kt_prime = kt / (1.031 * np .exp (- 1.4 / (0.9 + 9.4 / airmass )) + 0.1 )
1497
1497
kt_prime [kt_prime > 0.82 ] = 0.82 # From SRRL code. consider np.NaN
1498
- kt_prime .fillna (0 , inplace = True )
1499
1498
pvl_logger .debug ('kt_prime:\n %s' , kt_prime )
1500
-
1501
- # wholmgren:
1499
+
1500
+ # wholmgren:
1502
1501
# the use_delta_kt_prime statement is a port of the MATLAB code.
1503
1502
# I am confused by the abs() in the delta_kt_prime calculation.
1504
1503
# It is not the absolute value of the central difference.
1505
1504
if use_delta_kt_prime :
1506
1505
delta_kt_prime = 0.5 * ( (kt_prime - kt_prime .shift (1 )).abs ()
1507
1506
.add (
1508
- (kt_prime - kt_prime .shift (- 1 )).abs (),
1507
+ (kt_prime - kt_prime .shift (- 1 )).abs (),
1509
1508
fill_value = 0 ))
1510
1509
else :
1511
1510
delta_kt_prime = pd .Series (- 1 , index = times )
1512
-
1511
+
1513
1512
if temp_dew is not None :
1514
1513
w = pd .Series (np .exp (0.07 * temp_dew - 0.075 ), index = times )
1515
1514
else :
1516
1515
w = pd .Series (- 1 , index = times )
1517
-
1516
+
1518
1517
# @wholmgren: the following bin assignments use MATLAB's 1-indexing.
1519
1518
# Later, we'll subtract 1 to conform to Python's 0-indexing.
1520
-
1519
+ # The initial filled 0s will result in nans.
1520
+ # see discussion at https://github.com/pvlib/pvlib-python/pull/164
1521
+
1521
1522
# Create kt_prime bins
1522
1523
kt_prime_bin = pd .Series (0 , index = times , dtype = np .int64 )
1523
1524
kt_prime_bin [(kt_prime >= 0 ) & (kt_prime < 0.24 )] = 1
@@ -1527,7 +1528,7 @@ def dirint(ghi, zenith, times, pressure=101325, use_delta_kt_prime=True,
1527
1528
kt_prime_bin [(kt_prime >= 0.7 ) & (kt_prime < 0.8 )] = 5
1528
1529
kt_prime_bin [(kt_prime >= 0.8 ) & (kt_prime <= 1 )] = 6
1529
1530
pvl_logger .debug ('kt_prime_bin:\n %s' , kt_prime_bin )
1530
-
1531
+
1531
1532
# Create zenith angle bins
1532
1533
zenith_bin = pd .Series (0 , index = times , dtype = np .int64 )
1533
1534
zenith_bin [(zenith >= 0 ) & (zenith < 25 )] = 1
@@ -1537,7 +1538,7 @@ def dirint(ghi, zenith, times, pressure=101325, use_delta_kt_prime=True,
1537
1538
zenith_bin [(zenith >= 70 ) & (zenith < 80 )] = 5
1538
1539
zenith_bin [(zenith >= 80 )] = 6
1539
1540
pvl_logger .debug ('zenith_bin:\n %s' , zenith_bin )
1540
-
1541
+
1541
1542
# Create the bins for w based on dew point temperature
1542
1543
w_bin = pd .Series (0 , index = times , dtype = np .int64 )
1543
1544
w_bin [(w >= 0 ) & (w < 1 )] = 1
@@ -1557,11 +1558,16 @@ def dirint(ghi, zenith, times, pressure=101325, use_delta_kt_prime=True,
1557
1558
delta_kt_prime_bin [(delta_kt_prime >= 0.3 ) & (delta_kt_prime <= 1 )] = 6
1558
1559
delta_kt_prime_bin [delta_kt_prime == - 1 ] = 7
1559
1560
pvl_logger .debug ('delta_kt_prime_bin:\n %s' , delta_kt_prime_bin )
1560
-
1561
+
1561
1562
# subtract 1 to account for difference between MATLAB-style bin
1562
1563
# assignment and Python-style array lookup.
1563
1564
dirint_coeffs = coeffs [kt_prime_bin - 1 , zenith_bin - 1 ,
1564
1565
delta_kt_prime_bin - 1 , w_bin - 1 ]
1566
+ # convert unassigned bins to nan
1567
+ # use where to avoid boolean indexing deprecation
1568
+ dirint_coeffs [np .where ((kt_prime_bin == 0 ) | (zenith_bin == 0 ) |
1569
+ (w_bin == 0 ) | (delta_kt_prime_bin == 0 ))] = np .nan
1570
+
1565
1571
dni = disc_out ['dni' ] * dirint_coeffs
1566
1572
1567
1573
dni .name = 'dni'
@@ -1572,19 +1578,19 @@ def dirint(ghi, zenith, times, pressure=101325, use_delta_kt_prime=True,
1572
1578
def _get_dirint_coeffs ():
1573
1579
"""
1574
1580
A place to stash the dirint coefficients.
1575
-
1581
+
1576
1582
Returns
1577
1583
-------
1578
1584
np.array with shape ``(6, 6, 7, 5)``.
1579
1585
Ordering is ``[kt_prime_bin, zenith_bin, delta_kt_prime_bin, w_bin]``
1580
1586
"""
1581
1587
1582
- # To allow for maximum copy/paste from the MATLAB 1-indexed code,
1588
+ # To allow for maximum copy/paste from the MATLAB 1-indexed code,
1583
1589
# we create and assign values to an oversized array.
1584
1590
# Then, we return the [1:, 1:, :, :] slice.
1585
-
1591
+
1586
1592
coeffs = np .zeros ((7 ,7 ,7 ,5 ))
1587
-
1593
+
1588
1594
coeffs [1 ,1 ,:,:] = [
1589
1595
[0.385230 , 0.385230 , 0.385230 , 0.462880 , 0.317440 ],
1590
1596
[0.338390 , 0.338390 , 0.221270 , 0.316730 , 0.503650 ],
@@ -1908,6 +1914,6 @@ def _get_dirint_coeffs():
1908
1914
[0.570000 , 0.550000 , 0.598800 , 0.400000 , 0.560150 ],
1909
1915
[0.475230 , 0.500000 , 0.518640 , 0.339970 , 0.520230 ],
1910
1916
[0.743440 , 0.592190 , 0.603060 , 0.316930 , 0.794390 ]]
1911
-
1917
+
1912
1918
return coeffs [1 :,1 :,:,:]
1913
1919
0 commit comments