@@ -385,7 +385,7 @@ def disc(GHI, zenith, times, pressure=101325):
385
385
386
386
387
387
def dirint (ghi , zenith , times , pressure , use_delta_kt_prime = True ,
388
- temp_dew = None )
388
+ temp_dew = None ):
389
389
"""
390
390
Determine DNI from GHI using the DIRINT modification
391
391
of the DISC model.
@@ -461,13 +461,15 @@ def dirint(ghi, zenith, times, pressure, use_delta_kt_prime=True,
461
461
# Note that we calculate the AM pressure correction slightly differently
462
462
# than Perez. He uses altitude, we use pressure (which we calculate
463
463
# slightly differently)
464
- airmass = (1. / (cosd (zenith ) + 0.15 * ((93.885 - zenith )** (- 1.253 ))) *
464
+ airmass = (1. / (tools . cosd (zenith ) + 0.15 * ((93.885 - zenith )** (- 1.253 ))) *
465
465
pressure / 101325 )
466
466
467
467
coeffs = _get_dirint_coeffs ()
468
468
469
469
kt_prime = kt / (1.031 * np .exp (- 1.4 / (0.9 + 9.4 / airmass )) + 0.1 )
470
470
kt_prime [kt_prime > 0.82 ] = 0.82 # From SRRL code. consider np.NaN
471
+ kt_prime .fillna (0 , inplace = True )
472
+ logger .debug ('kt_prime:\n {}' .format (kt_prime ))
471
473
472
474
# wholmgren:
473
475
# the use_delta_kt_prime statement is a port of the MATLAB code.
@@ -486,33 +488,39 @@ def dirint(ghi, zenith, times, pressure, use_delta_kt_prime=True,
486
488
else :
487
489
w = pd .Series (- 1 , index = times )
488
490
489
- # Error check KtPrime and create KtPrime bins
491
+ # @wholmgren: the following bin assignments use MATLAB's 1-indexing.
492
+ # Later, we'll subtract 1 to conform to Python's 0-indexing.
493
+
494
+ # Create kt_prime bins
490
495
kt_prime_bin = pd .Series (index = times )
491
496
kt_prime_bin [(kt_prime >= 0 ) & (kt_prime < 0.24 )] = 1
492
497
kt_prime_bin [(kt_prime >= 0.24 ) & (kt_prime < 0.4 )] = 2
493
498
kt_prime_bin [(kt_prime >= 0.4 ) & (kt_prime < 0.56 )] = 3
494
499
kt_prime_bin [(kt_prime >= 0.56 ) & (kt_prime < 0.7 )] = 4
495
500
kt_prime_bin [(kt_prime >= 0.7 ) & (kt_prime < 0.8 )] = 5
496
501
kt_prime_bin [(kt_prime >= 0.8 ) & (kt_prime <= 1 )] = 6
502
+ logger .debug ('kt_prime_bin:\n {}' .format (kt_prime_bin ))
497
503
498
- # Create Zenith angle bins
504
+ # Create zenith angle bins
499
505
zenith_bin = pd .Series (index = times )
500
506
zenith_bin [(zenith >= 0 ) & (zenith < 25 )] = 1
501
507
zenith_bin [(zenith >= 25 ) & (zenith < 40 )] = 2
502
508
zenith_bin [(zenith >= 40 ) & (zenith < 55 )] = 3
503
509
zenith_bin [(zenith >= 55 ) & (zenith < 70 )] = 4
504
510
zenith_bin [(zenith >= 70 ) & (zenith < 80 )] = 5
505
511
zenith_bin [(zenith >= 80 )] = 6
512
+ logger .debug ('zenith_bin:\n {}' .format (zenith_bin ))
506
513
507
- # Create the bins for W based on dew point temperature
514
+ # Create the bins for w based on dew point temperature
508
515
w_bin = pd .Series (index = times )
509
516
w_bin [(w >= 0 ) & (w < 1 )] = 1
510
517
w_bin [(w >= 1 ) & (w < 2 )] = 2
511
518
w_bin [(w >= 2 ) & (w < 3 )] = 3
512
519
w_bin [(w >= 3 )] = 4
513
520
w_bin [(w == - 1 )] = 5
521
+ logger .debug ('w_bin:\n {}' .format (w_bin ))
514
522
515
- # Error check values of DelKtPrime, and create DelKtPrime binning.
523
+ # Create delta_kt_prime binning.
516
524
delta_kt_prime_bin = pd .Series (index = times )
517
525
delta_kt_prime_bin [(delta_kt_prime >= 0 ) & (delta_kt_prime < 0.015 )] = 1
518
526
delta_kt_prime_bin [(delta_kt_prime >= 0.015 ) & (delta_kt_prime < 0.035 )] = 2
@@ -521,9 +529,12 @@ def dirint(ghi, zenith, times, pressure, use_delta_kt_prime=True,
521
529
delta_kt_prime_bin [(delta_kt_prime >= 0.15 ) & (delta_kt_prime < 0.3 )] = 5
522
530
delta_kt_prime_bin [(delta_kt_prime >= 0.3 ) & (delta_kt_prime <= 1 )] = 6
523
531
delta_kt_prime_bin [delta_kt_prime == - 1 ] = 7
532
+ logger .debug ('delta_kt_prime_bin:\n {}' .format (delta_kt_prime_bin ))
524
533
525
- dirint_coeffs = coeffs [kt_prime_bin , zenith_bin ,
526
- delta_kt_prime_bin , w_bin ]
534
+ # subtract 1 to account for difference between MATLAB-style bin
535
+ # assignment and Python-style array lookup.
536
+ dirint_coeffs = coeffs [kt_prime_bin - 1 , zenith_bin - 1 ,
537
+ delta_kt_prime_bin - 1 , w_bin - 1 ]
527
538
528
539
dni = disc_out ['DNI_gen_DISC' ] * dirint_coeffs
529
540
@@ -536,10 +547,15 @@ def _get_dirint_coeffs():
536
547
537
548
Returns
538
549
-------
539
- np.array with shape ``(7, 7 , 7, 5)``. The MATLAB indicies are preserved,
540
- meaning that 0 padding has been added to the "left" side of the array(s).
550
+ np.array with shape ``(6, 6 , 7, 5)``.
551
+ Ordering is ``[kt_prime_bin, zenith_bin, delta_kt_prime_bin, w_bin]``
541
552
"""
542
553
554
+
555
+ # To allow for maximum copy/paste from the MATLAB 1-indexed code,
556
+ # we create and assign values to an oversized array.
557
+ # Then, we return the [1:, 1:, :, :] slice.
558
+
543
559
coeffs = np .zeros ((7 ,7 ,7 ,5 ))
544
560
545
561
coeffs [1 ,1 ,:,:] = [
@@ -866,5 +882,5 @@ def _get_dirint_coeffs():
866
882
[0.475230 , 0.500000 , 0.518640 , 0.339970 , 0.520230 ],
867
883
[0.743440 , 0.592190 , 0.603060 , 0.316930 , 0.794390 ]]
868
884
869
- return coeffs
885
+ return coeffs [ 1 :, 1 :,:,:]
870
886
0 commit comments