-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolar Irradiance Calc Advanced.py
2914 lines (2343 loc) · 110 KB
/
Solar Irradiance Calc Advanced.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
The ``irradiance`` module contains functions for modeling global
horizontal irradiance, direct normal irradiance, diffuse horizontal
irradiance, and total irradiance under various conditions.
"""
from __future__ import division
import logging
import inspect
import os
import matplotlib.pyplot as plt
# seaborn makes your plots look better
import module as module
import pvlib as pvlib
try:
import seaborn as sns
sns.set(rc={"figure.figsize": (12, 6)})
except ImportError:
print('We suggest you install seaborn using conda or pip and rerun this cell')
import datetime
from collections import OrderedDict
from functools import partial
import numpy as np
import pandas as pd
from pvlib import atmosphere, solarposition, tools
# see References section of grounddiffuse function
SURFACE_ALBEDOS = {'urban': 0.18,
'grass': 0.20,
'fresh grass': 0.26,
'soil': 0.17,
'sand': 0.40,
'snow': 0.65,
'fresh snow': 0.75,
'asphalt': 0.12,
'concrete': 0.30,
'aluminum': 0.85,
'copper': 0.74,
'fresh steel': 0.35,
'dirty steel': 0.08,
'sea': 0.06}
def get_extra_radiation(datetime_or_doy, solar_constant=1366.1,
method='spencer', epoch_year=2014, **kwargs):
"""
Determine extraterrestrial radiation from day of year.
Parameters
----------
datetime_or_doy : numeric, array, date, datetime, Timestamp, DatetimeIndex
Day of year, array of days of year, or datetime-like object
solar_constant : float, default 1366.1
The solar constant.
method : string, default 'spencer'
The method by which the ET radiation should be calculated.
Options include ``'pyephem', 'spencer', 'asce', 'nrel'``.
epoch_year : int, default 2014
The year in which a day of year input will be calculated. Only
applies to day of year input used with the pyephem or nrel
methods.
kwargs :
Passed to solarposition.nrel_earthsun_distance
Returns
-------
dni_extra : float, array, or Series
The extraterrestrial radiation present in watts per square meter
on a surface which is normal to the sun. Pandas Timestamp and
DatetimeIndex inputs will yield a Pandas TimeSeries. All other
inputs will yield a float or an array of floats.
References
----------
.. [1] M. Reno, C. Hansen, and J. Stein, "Global Horizontal Irradiance
Clear Sky Models: Implementation and Analysis", Sandia National
Laboratories, SAND2012-2389, 2012.
.. [2] <http://solardat.uoregon.edu/SolarRadiationBasics.html>, Eqs.
SR1 and SR2
.. [3] Partridge, G. W. and Platt, C. M. R. 1976. Radiative Processes
in Meteorology and Climatology.
.. [4] Duffie, J. A. and Beckman, W. A. 1991. Solar Engineering of
Thermal Processes, 2nd edn. J. Wiley and Sons, New York.
.. [5] ASCE, 2005. The ASCE Standardized Reference Evapotranspiration
Equation, Environmental and Water Resources Institute of the American
Civil Engineers, Ed. R. G. Allen et al.
"""
to_doy, to_datetimeindex, to_output = \
_handle_extra_radiation_types(datetime_or_doy, epoch_year)
# consider putting asce and spencer methods in their own functions
method = method.lower()
if method == 'asce':
B = solarposition._calculate_simple_day_angle(to_doy(datetime_or_doy),
offset=0)
RoverR0sqrd = 1 + 0.033 * np.cos(B)
elif method == 'spencer':
B = solarposition._calculate_simple_day_angle(to_doy(datetime_or_doy))
RoverR0sqrd = (1.00011 + 0.034221 * np.cos(B) + 0.00128 * np.sin(B) +
0.000719 * np.cos(2 * B) + 7.7e-05 * np.sin(2 * B))
elif method == 'pyephem':
times = to_datetimeindex(datetime_or_doy)
RoverR0sqrd = solarposition.pyephem_earthsun_distance(times) ** (-2)
elif method == 'nrel':
times = to_datetimeindex(datetime_or_doy)
RoverR0sqrd = \
solarposition.nrel_earthsun_distance(times, **kwargs) ** (-2)
else:
raise ValueError('Invalid method: %s', method)
Ea = solar_constant * RoverR0sqrd
Ea = to_output(Ea)
return Ea
def _handle_extra_radiation_types(datetime_or_doy, epoch_year):
# This block will set the functions that can be used to convert the
# inputs to either day of year or pandas DatetimeIndex, and the
# functions that will yield the appropriate output type. It's
# complicated because there are many day-of-year-like input types,
# and the different algorithms need different types. Maybe you have
# a better way to do it.
if isinstance(datetime_or_doy, pd.DatetimeIndex):
to_doy = tools._pandas_to_doy # won't be evaluated unless necessary
def to_datetimeindex(x): return x # noqa: E306
to_output = partial(pd.Series, index=datetime_or_doy)
elif isinstance(datetime_or_doy, pd.Timestamp):
to_doy = tools._pandas_to_doy
to_datetimeindex = \
tools._datetimelike_scalar_to_datetimeindex
to_output = tools._scalar_out
elif isinstance(datetime_or_doy,
(datetime.date, datetime.datetime, np.datetime64)):
to_doy = tools._datetimelike_scalar_to_doy
to_datetimeindex = \
tools._datetimelike_scalar_to_datetimeindex
to_output = tools._scalar_out
elif np.isscalar(datetime_or_doy): # ints and floats of various types
def to_doy(x): return x # noqa: E306
to_datetimeindex = partial(tools._doy_to_datetimeindex,
epoch_year=epoch_year)
to_output = tools._scalar_out
else: # assume that we have an array-like object of doy
def to_doy(x): return x # noqa: E306
to_datetimeindex = partial(tools._doy_to_datetimeindex,
epoch_year=epoch_year)
to_output = tools._array_out
return to_doy, to_datetimeindex, to_output
def aoi_projection(surface_tilt, surface_azimuth, solar_zenith, solar_azimuth):
"""
Calculates the dot product of the sun position unit vector and the surface
normal unit vector; in other words, the cosine of the angle of incidence.
Usage note: When the sun is behind the surface the value returned is
negative. For many uses negative values must be set to zero.
Input all angles in degrees.
Parameters
----------
surface_tilt : numeric
Panel tilt from horizontal.
surface_azimuth : numeric
Panel azimuth from north.
solar_zenith : numeric
Solar zenith angle.
solar_azimuth : numeric
Solar azimuth angle.
Returns
-------
projection : numeric
Dot product of panel normal and solar angle.
"""
projection = (
tools.cosd(surface_tilt) * tools.cosd(solar_zenith) +
tools.sind(surface_tilt) * tools.sind(solar_zenith) *
tools.cosd(solar_azimuth - surface_azimuth))
try:
projection.name = 'aoi_projection'
except AttributeError:
pass
return projection
print(aoi_projection(1.46, 90, 16.48, 174))
def aoi(surface_tilt, surface_azimuth, solar_zenith, solar_azimuth):
"""
Calculates the angle of incidence of the solar vector on a surface.
This is the angle between the solar vector and the surface normal.
Input all angles in degrees.
Parameters
----------
surface_tilt : numeric
Panel tilt from horizontal.
surface_azimuth : numeric
Panel azimuth from north.
solar_zenith : numeric
Solar zenith angle.
solar_azimuth : numeric
Solar azimuth angle.
Returns
-------
aoi : numeric
Angle of incidence in degrees.
"""
projection = aoi_projection(surface_tilt, surface_azimuth,
solar_zenith, solar_azimuth)
aoi_value = np.rad2deg(np.arccos(projection))
try:
aoi_value.name = 'aoi'
except AttributeError:
pass
return aoi_value
# print(aoi(0, 90, 16.48, 174))
def poa_horizontal_ratio(surface_tilt, surface_azimuth,
solar_zenith, solar_azimuth):
"""
Calculates the ratio of the beam components of the plane of array
irradiance and the horizontal irradiance.
Input all angles in degrees.
Parameters
----------
surface_tilt : numeric
Panel tilt from horizontal.
surface_azimuth : numeric
Panel azimuth from north.
solar_zenith : numeric
Solar zenith angle.
solar_azimuth : numeric
Solar azimuth angle.
Returns
-------
ratio : numeric
Ratio of the plane of array irradiance to the horizontal plane
irradiance
"""
cos_poa_zen = aoi_projection(surface_tilt, surface_azimuth,
solar_zenith, solar_azimuth)
cos_solar_zenith = tools.cosd(solar_zenith)
# ratio of tilted and horizontal beam irradiance
ratio = cos_poa_zen / cos_solar_zenith
try:
ratio.name = 'poa_ratio'
except AttributeError:
pass
return ratio
def beam_component(surface_tilt, surface_azimuth, solar_zenith, solar_azimuth,
dni):
"""
Calculates the beam component of the plane of array irradiance.
Parameters
----------
surface_tilt : numeric
Panel tilt from horizontal.
surface_azimuth : numeric
Panel azimuth from north.
solar_zenith : numeric
Solar zenith angle.
solar_azimuth : numeric
Solar azimuth angle.
dni : numeric
Direct Normal Irradiance
Returns
-------
beam : numeric
Beam component
"""
beam = dni * aoi_projection(surface_tilt, surface_azimuth,
solar_zenith, solar_azimuth)
beam = np.maximum(beam, 0)
return beam
def isotropic(surface_tilt, dhi):
r'''
Determine diffuse irradiance from the sky on a tilted surface using
the isotropic sky model.
.. math::
I_{d} = DHI \frac{1 + \cos\beta}{2}
Hottel and Woertz's model treats the sky as a uniform source of
diffuse irradiance. Thus the diffuse irradiance from the sky (ground
reflected irradiance is not included in this algorithm) on a tilted
surface can be found from the diffuse horizontal irradiance and the
tilt angle of the surface.
Parameters
----------
surface_tilt : numeric
Surface tilt angle in decimal degrees. Tilt must be >=0 and
<=180. The tilt angle is defined as degrees from horizontal
(e.g. surface facing up = 0, surface facing horizon = 90)
dhi : numeric
Diffuse horizontal irradiance in W/m^2. DHI must be >=0.
Returns
-------
diffuse : numeric
The sky diffuse component of the solar radiation.
References
----------
.. [1] Loutzenhiser P.G. et. al. "Empirical validation of models to
compute solar irradiance on inclined surfaces for building energy
simulation" 2007, Solar Energy vol. 81. pp. 254-267
.. [2] Hottel, H.C., Woertz, B.B., 1942. Evaluation of flat-plate solar
heat collector. Trans. ASME 64, 91.
'''
sky_diffuse = dhi * (1 + tools.cosd(surface_tilt)) * 0.5
return sky_diffuse
isotropic(5, 70)
def get_sky_diffuse(surface_tilt, surface_azimuth,
solar_zenith, solar_azimuth,
dni, ghi, dhi, dni_extra=None, airmass=None,
model='isotropic',
model_perez='allsitescomposite1990'):
r"""
Determine in-plane sky diffuse irradiance component
using the specified sky diffuse irradiance model.
Sky diffuse models include:
* isotropic (default)
* klucher
* haydavies
* reindl
* king
* perez
Parameters
----------
surface_tilt : numeric
Panel tilt from horizontal.
surface_azimuth : numeric
Panel azimuth from north.
solar_zenith : numeric
Solar zenith angle.
solar_azimuth : numeric
Solar azimuth angle.
dni : numeric
Direct Normal Irradiance
ghi : numeric
Global horizontal irradiance
dhi : numeric
Diffuse horizontal irradiance
dni_extra : None or numeric, default None
Extraterrestrial direct normal irradiance
airmass : None or numeric, default None
Airmass
model : String, default 'isotropic'
Irradiance model.
model_perez : String, default 'allsitescomposite1990'
See perez.
Returns
-------
poa_sky_diffuse : numeric
"""
model = model.lower()
if model == 'isotropic':
sky = isotropic(surface_tilt, dhi)
elif model == 'klucher':
sky = klucher(surface_tilt, surface_azimuth, dhi, ghi,
solar_zenith, solar_azimuth)
elif model == 'haydavies':
sky = haydavies(surface_tilt, surface_azimuth, dhi, dni, dni_extra,
solar_zenith, solar_azimuth)
elif model == 'reindl':
sky = reindl(surface_tilt, surface_azimuth, dhi, dni, ghi, dni_extra,
solar_zenith, solar_azimuth)
elif model == 'king':
sky = king(surface_tilt, dhi, ghi, solar_zenith)
elif model == 'perez':
sky = perez(surface_tilt, surface_azimuth, dhi, dni, dni_extra,
solar_zenith, solar_azimuth, airmass,
model=model_perez)
else:
raise ValueError('invalid model selection {}'.format(model))
return sky
get_sky_diffuse(5, 0, 180, 0, 1050, 1120, 70)
def get_ground_diffuse(surface_tilt, ghi, albedo=.25, surface_type=None):
'''
Estimate diffuse irradiance from ground reflections given
irradiance, albedo, and surface tilt
Function to determine the portion of irradiance on a tilted surface
due to ground reflections. Any of the inputs may be DataFrames or
scalars.
Parameters
----------
surface_tilt : numeric
Surface tilt angles in decimal degrees. Tilt must be >=0 and
<=180. The tilt angle is defined as degrees from horizontal
(e.g. surface facing up = 0, surface facing horizon = 90).
ghi : numeric
Global horizontal irradiance in W/m^2.
albedo : numeric, default 0.25
Ground reflectance, typically 0.1-0.4 for surfaces on Earth
(land), may increase over snow, ice, etc. May also be known as
the reflection coefficient. Must be >=0 and <=1. Will be
overridden if surface_type is supplied.
surface_type: None or string, default None
If not None, overrides albedo. String can be one of 'urban',
'grass', 'fresh grass', 'snow', 'fresh snow', 'asphalt', 'concrete',
'aluminum', 'copper', 'fresh steel', 'dirty steel', 'sea'.
Returns
-------
grounddiffuse : numeric
Ground reflected irradiances in W/m^2.
References
----------
.. [1] Loutzenhiser P.G. et. al. "Empirical validation of models to compute
solar irradiance on inclined surfaces for building energy simulation"
2007, Solar Energy vol. 81. pp. 254-267.
The calculation is the last term of equations 3, 4, 7, 8, 10, 11, and 12.
.. [2] albedos from:
http://files.pvsyst.com/help/albedo.htm
and
http://en.wikipedia.org/wiki/Albedo
and
https://doi.org/10.1175/1520-0469(1972)029<0959:AOTSS>2.0.CO;2
'''
if surface_type is not None:
albedo = SURFACE_ALBEDOS[surface_type]
diffuse_irrad = ghi * albedo * (1 - np.cos(np.radians(surface_tilt))) * 0.5
try:
diffuse_irrad.name = 'diffuse_ground'
except AttributeError:
pass
return diffuse_irrad
get_ground_diffuse(5, 1120)
def poa_components(aoi, dni, poa_sky_diffuse, poa_ground_diffuse):
r'''
Determine in-plane irradiance components.
Combines DNI with sky diffuse and ground-reflected irradiance to calculate
total, direct and diffuse irradiance components in the plane of array.
Parameters
----------
aoi : numeric
Angle of incidence of solar rays with respect to the module
surface, from :func:`aoi`.
dni : numeric
Direct normal irradiance (W/m^2), as measured from a TMY file or
calculated with a clearsky model.
poa_sky_diffuse : numeric
Diffuse irradiance (W/m^2) in the plane of the modules, as
calculated by a diffuse irradiance translation function
poa_ground_diffuse : numeric
Ground reflected irradiance (W/m^2) in the plane of the modules,
as calculated by an albedo model (eg. :func:`grounddiffuse`)
Returns
-------
irrads : OrderedDict or DataFrame
Contains the following keys:
* ``poa_global`` : Total in-plane irradiance (W/m^2)
* ``poa_direct`` : Total in-plane beam irradiance (W/m^2)
* ``poa_diffuse`` : Total in-plane diffuse irradiance (W/m^2)
* ``poa_sky_diffuse`` : In-plane diffuse irradiance from sky (W/m^2)
* ``poa_ground_diffuse`` : In-plane diffuse irradiance from ground
(W/m^2)
Notes
------
Negative beam irradiation due to aoi :math:`> 90^{\circ}` or AOI
:math:`< 0^{\circ}` is set to zero.
'''
poa_direct = np.maximum(dni * np.cos(np.radians(aoi)), 0)
poa_diffuse = poa_sky_diffuse + poa_ground_diffuse
poa_global = poa_direct + poa_diffuse
irrads = OrderedDict()
irrads['poa_global'] = poa_global
irrads['poa_direct'] = poa_direct
irrads['poa_diffuse'] = poa_diffuse
irrads['poa_sky_diffuse'] = poa_sky_diffuse
irrads['poa_ground_diffuse'] = poa_ground_diffuse
if isinstance(poa_direct, pd.Series):
irrads = pd.DataFrame(irrads)
return irrads
poa_components(aoi(5, 0, 180, 0), 1050, get_sky_diffuse(5, 0, 180, 0, 1050, 1120, 70), get_ground_diffuse(5, 1120))
def get_total_irradiance(surface_tilt, surface_azimuth,
solar_zenith, solar_azimuth,
dni, ghi, dhi, dni_extra=None, airmass=None,
albedo=.25, surface_type=None,
model='isotropic',
model_perez='allsitescomposite1990', **kwargs):
r"""
Determine total in-plane irradiance and its beam, sky diffuse and ground
reflected components, using the specified sky diffuse irradiance model.
.. math::
I_{tot} = I_{beam} + I_{sky diffuse} + I_{ground}
Sky diffuse models include:
* isotropic (default)
* klucher
* haydavies
* reindl
* king
* perez
Parameters
----------
surface_tilt : numeric
Panel tilt from horizontal.
surface_azimuth : numeric
Panel azimuth from north.
solar_zenith : numeric
Solar zenith angle.
solar_azimuth : numeric
Solar azimuth angle.
dni : numeric
Direct Normal Irradiance
ghi : numeric
Global horizontal irradiance
dhi : numeric
Diffuse horizontal irradiance
dni_extra : None or numeric, default None
Extraterrestrial direct normal irradiance
airmass : None or numeric, default None
Airmass
albedo : numeric, default 0.25
Surface albedo
surface_type : None or String, default None
Surface type. See grounddiffuse.
model : String, default 'isotropic'
Irradiance model.
model_perez : String, default 'allsitescomposite1990'
Used only if model='perez'. See :py:func:`perez`.
Returns
-------
total_irrad : OrderedDict or DataFrame
Contains keys/columns ``'poa_global', 'poa_direct', 'poa_diffuse',
'poa_sky_diffuse', 'poa_ground_diffuse'``.
"""
poa_sky_diffuse = get_sky_diffuse(
surface_tilt, surface_azimuth, solar_zenith, solar_azimuth,
dni, ghi, dhi, dni_extra=dni_extra, airmass=airmass, model=model,
model_perez=model_perez)
poa_ground_diffuse = get_ground_diffuse(surface_tilt, ghi, albedo,
surface_type)
aoi_ = aoi(surface_tilt, surface_azimuth, solar_zenith, solar_azimuth)
total_irrads = poa_components(aoi_, dni, poa_sky_diffuse, poa_ground_diffuse)
return total_irrads
# print(get_total_irradiance(1, 90, 16.48, 174, 1050, 1120, 70))
print(get_total_irradiance(1.46, 90, 18.47, 161.85, 1050, 1120, 70))
#Need to Find Solar Azimuth and Zentith for 38 latitude from 9am-6pm
# for j in [0, 2, 4, 6, 5, 5.5, 2.5, -7.5, -2.5, -3, -4, -5, -11.5]: (SR3 V1)
# for j in [-8,-7,5,-7, -6, -5, 1, 2, 4, 5, 6,8,10,12, 13,15]: (ADD)
for j in [-1, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4]:
sum = 0.0
average = 0.0
sa = 96.75
sz = 46.84
count = 0
for i in range(26):
sum += (get_total_irradiance(j, 90, sz, sa, 1050, 1120, 70))['poa_global']
sa += 7.11
sz += .97
average = round(sum/26, 2)
count += 1
tot_average = average/count
print (average)
print ("tot_avg: " + str(tot_average))
#race hours = 10am-6pm and 9am-5pm
#9am-6pm: Zenith = 42.64-77.31, Azimuth = 92.62-287.55 (FSGP)
#9am-6pm on July 20: Zenith = 47.41 - 72.6, Azimuth = 97.69 - 282.53 (Average for FSGP and ASC)
#delta of zenith: 34.67
#deltta of azimuth: 194.93
#If factoring in heading north or south east, average surface azimuth comes to 67.5
#Otherwise, if heading east the surface azimuth is 90
from pvlib import pvsystem
from pvlib.location import Location
tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson')
times_loc = pd.date_range(start=datetime.datetime(2014,4,1), end=datetime.datetime(2014,4,2), freq='30s', tz=tus.tz)
solpos = pvlib.solarposition.get_solarposition(times_loc, tus.latitude, tus.longitude)
dni_extra = get_extra_radiation(times_loc)
airmass = pvlib.atmosphere.get_relative_airmass(solpos['apparent_zenith'])
pressure = pvlib.atmosphere.alt2pres(tus.altitude)
am_abs = pvlib.atmosphere.get_absolute_airmass(airmass, pressure)
cs = tus.get_clearsky(times_loc)
surface_tilt = 0
surface_azimuth = 90 # pointing south
aoi = pvlib.irradiance.aoi(surface_tilt, surface_azimuth,
solpos['apparent_zenith'], solpos['azimuth'])
total_irrad = pvlib.irradiance.get_total_irradiance(surface_tilt,
surface_azimuth,
solpos['apparent_zenith'],
solpos['azimuth'],
cs['dni'], cs['ghi'], cs['dhi'],
dni_extra=dni_extra,
model='haydavies')
module = sandia_module
# a sunny, calm, and hot day in the desert
temps = pvsystem.sapm_celltemp(total_irrad['poa_global'], 0, 30)
sapm_1 = pvlib.pvsystem.sapm(get_total_irradiance(5, 90, 18.47, 161.85, 1050, 1120, 70, 0, 30), module)
sapm_1.plot()
def klucher(surface_tilt, surface_azimuth, dhi, ghi, solar_zenith,
solar_azimuth):
r'''
Determine diffuse irradiance from the sky on a tilted surface
using Klucher's 1979 model
.. math::
I_{d} = DHI \frac{1 + \cos\beta}{2} (1 + F' \sin^3(\beta/2))
(1 + F' \cos^2\theta\sin^3\theta_z)
where
.. math::
F' = 1 - (I_{d0} / GHI)
Klucher's 1979 model determines the diffuse irradiance from the sky
(ground reflected irradiance is not included in this algorithm) on a
tilted surface using the surface tilt angle, surface azimuth angle,
diffuse horizontal irradiance, direct normal irradiance, global
horizontal irradiance, extraterrestrial irradiance, sun zenith
angle, and sun azimuth angle.
Parameters
----------
surface_tilt : numeric
Surface tilt angles in decimal degrees. surface_tilt must be >=0
and <=180. The tilt angle is defined as degrees from horizontal
(e.g. surface facing up = 0, surface facing horizon = 90)
surface_azimuth : numeric
Surface azimuth angles in decimal degrees. surface_azimuth must
be >=0 and <=360. The Azimuth convention is defined as degrees
east of north (e.g. North = 0, South=180 East = 90, West = 270).
dhi : numeric
Diffuse horizontal irradiance in W/m^2. DHI must be >=0.
ghi : numeric
Global irradiance in W/m^2. DNI must be >=0.
solar_zenith : numeric
Apparent (refraction-corrected) zenith angles in decimal
degrees. solar_zenith must be >=0 and <=180.
solar_azimuth : numeric
Sun azimuth angles in decimal degrees. solar_azimuth must be >=0
and <=360. The Azimuth convention is defined as degrees east of
north (e.g. North = 0, East = 90, West = 270).
Returns
-------
diffuse : numeric
The sky diffuse component of the solar radiation.
References
----------
.. [1] Loutzenhiser P.G. et. al. "Empirical validation of models to compute
solar irradiance on inclined surfaces for building energy simulation"
2007, Solar Energy vol. 81. pp. 254-267
.. [2] Klucher, T.M., 1979. Evaluation of models to predict insolation on
tilted surfaces. Solar Energy 23 (2), 111-114.
'''
# zenith angle with respect to panel normal.
cos_tt = aoi_projection(surface_tilt, surface_azimuth,
solar_zenith, solar_azimuth)
cos_tt = np.maximum(cos_tt, 0) # GH 526
# silence warning from 0 / 0
with np.errstate(invalid='ignore'):
F = 1 - ((dhi / ghi) ** 2)
try:
# fails with single point input
F.fillna(0, inplace=True)
except AttributeError:
F = np.where(np.isnan(F), 0, F)
term1 = 0.5 * (1 + tools.cosd(surface_tilt))
term2 = 1 + F * (tools.sind(0.5 * surface_tilt) ** 3)
term3 = 1 + F * (cos_tt ** 2) * (tools.sind(solar_zenith) ** 3)
sky_diffuse = dhi * term1 * term2 * term3
return sky_diffuse
def haydavies(surface_tilt, surface_azimuth, dhi, dni, dni_extra,
solar_zenith=None, solar_azimuth=None, projection_ratio=None):
r'''
Determine diffuse irradiance from the sky on a tilted surface using
Hay & Davies' 1980 model
.. math::
I_{d} = DHI ( A R_b + (1 - A) (\frac{1 + \cos\beta}{2}) )
Hay and Davies' 1980 model determines the diffuse irradiance from
the sky (ground reflected irradiance is not included in this
algorithm) on a tilted surface using the surface tilt angle, surface
azimuth angle, diffuse horizontal irradiance, direct normal
irradiance, extraterrestrial irradiance, sun zenith angle, and sun
azimuth angle.
Parameters
----------
surface_tilt : numeric
Surface tilt angles in decimal degrees. The tilt angle is
defined as degrees from horizontal (e.g. surface facing up = 0,
surface facing horizon = 90)
surface_azimuth : numeric
Surface azimuth angles in decimal degrees. The azimuth
convention is defined as degrees east of north (e.g. North=0,
South=180, East=90, West=270).
dhi : numeric
Diffuse horizontal irradiance in W/m^2.
dni : numeric
Direct normal irradiance in W/m^2.
dni_extra : numeric
Extraterrestrial normal irradiance in W/m^2.
solar_zenith : None or numeric, default None
Solar apparent (refraction-corrected) zenith angles in decimal
degrees. Must supply ``solar_zenith`` and ``solar_azimuth`` or
supply ``projection_ratio``.
solar_azimuth : None or numeric, default None
Solar azimuth angles in decimal degrees. Must supply
``solar_zenith`` and ``solar_azimuth`` or supply
``projection_ratio``.
projection_ratio : None or numeric, default None
Ratio of angle of incidence projection to solar zenith angle
projection. Must supply ``solar_zenith`` and ``solar_azimuth``
or supply ``projection_ratio``.
Returns
--------
sky_diffuse : numeric
The sky diffuse component of the solar radiation.
References
-----------
.. [1] Loutzenhiser P.G. et. al. "Empirical validation of models to
compute solar irradiance on inclined surfaces for building energy
simulation" 2007, Solar Energy vol. 81. pp. 254-267
.. [2] Hay, J.E., Davies, J.A., 1980. Calculations of the solar
radiation incident on an inclined surface. In: Hay, J.E., Won, T.K.
(Eds.), Proc. of First Canadian Solar Radiation Data Workshop, 59.
Ministry of Supply and Services, Canada.
'''
# if necessary, calculate ratio of titled and horizontal beam irradiance
if projection_ratio is None:
cos_tt = aoi_projection(surface_tilt, surface_azimuth,
solar_zenith, solar_azimuth)
cos_tt = np.maximum(cos_tt, 0) # GH 526
cos_solar_zenith = tools.cosd(solar_zenith)
Rb = cos_tt / np.maximum(cos_solar_zenith, 0.01745) # GH 432
else:
Rb = projection_ratio
# Anisotropy Index
AI = dni / dni_extra
# these are the () and [] sub-terms of the second term of eqn 7
term1 = 1 - AI
term2 = 0.5 * (1 + tools.cosd(surface_tilt))
sky_diffuse = dhi * (AI * Rb + term1 * term2)
sky_diffuse = np.maximum(sky_diffuse, 0)
return sky_diffuse
def reindl(surface_tilt, surface_azimuth, dhi, dni, ghi, dni_extra,
solar_zenith, solar_azimuth):
r'''
Determine diffuse irradiance from the sky on a tilted surface using
Reindl's 1990 model
.. math::
I_{d} = DHI (A R_b + (1 - A) (\frac{1 + \cos\beta}{2})
(1 + \sqrt{\frac{I_{hb}}{I_h}} \sin^3(\beta/2)) )
Reindl's 1990 model determines the diffuse irradiance from the sky
(ground reflected irradiance is not included in this algorithm) on a
tilted surface using the surface tilt angle, surface azimuth angle,
diffuse horizontal irradiance, direct normal irradiance, global
horizontal irradiance, extraterrestrial irradiance, sun zenith
angle, and sun azimuth angle.
Parameters
----------
surface_tilt : numeric
Surface tilt angles in decimal degrees. The tilt angle is
defined as degrees from horizontal (e.g. surface facing up = 0,
surface facing horizon = 90)
surface_azimuth : numeric
Surface azimuth angles in decimal degrees. The azimuth
convention is defined as degrees east of north (e.g. North = 0,
South=180 East = 90, West = 270).
dhi : numeric
diffuse horizontal irradiance in W/m^2.
dni : numeric
direct normal irradiance in W/m^2.
ghi: numeric
Global irradiance in W/m^2.
dni_extra : numeric
Extraterrestrial normal irradiance in W/m^2.
solar_zenith : numeric
Apparent (refraction-corrected) zenith angles in decimal degrees.
solar_azimuth : numeric
Sun azimuth angles in decimal degrees. The azimuth convention is
defined as degrees east of north (e.g. North = 0, East = 90,
West = 270).
Returns
-------
poa_sky_diffuse : numeric
The sky diffuse component of the solar radiation.
Notes
-----
The poa_sky_diffuse calculation is generated from the Loutzenhiser et al.
(2007) paper, equation 8. Note that I have removed the beam and ground
reflectance portion of the equation and this generates ONLY the diffuse
radiation from the sky and circumsolar, so the form of the equation
varies slightly from equation 8.
References
----------
.. [1] Loutzenhiser P.G. et. al. "Empirical validation of models to
compute solar irradiance on inclined surfaces for building energy
simulation" 2007, Solar Energy vol. 81. pp. 254-267
.. [2] Reindl, D.T., Beckmann, W.A., Duffie, J.A., 1990a. Diffuse
fraction correlations. Solar Energy 45(1), 1-7.
.. [3] Reindl, D.T., Beckmann, W.A., Duffie, J.A., 1990b. Evaluation of
hourly tilted surface radiation models. Solar Energy 45(1), 9-17.
'''
cos_tt = aoi_projection(surface_tilt, surface_azimuth,
solar_zenith, solar_azimuth)
cos_tt = np.maximum(cos_tt, 0) # GH 526
# do not apply cos(zen) limit here (needed for HB below)
cos_solar_zenith = tools.cosd(solar_zenith)
# ratio of titled and horizontal beam irradiance
Rb = cos_tt / np.maximum(cos_solar_zenith, 0.01745) # GH 432
# Anisotropy Index
AI = dni / dni_extra
# DNI projected onto horizontal
HB = dni * cos_solar_zenith
HB = np.maximum(HB, 0)
# these are the () and [] sub-terms of the second term of eqn 8
term1 = 1 - AI
term2 = 0.5 * (1 + tools.cosd(surface_tilt))
term3 = 1 + np.sqrt(HB / ghi) * (tools.sind(0.5 * surface_tilt) ** 3)
sky_diffuse = dhi * (AI * Rb + term1 * term2 * term3)
sky_diffuse = np.maximum(sky_diffuse, 0)
return sky_diffuse
def king(surface_tilt, dhi, ghi, solar_zenith):
'''
Determine diffuse irradiance from the sky on a tilted surface using
the King model.
King's model determines the diffuse irradiance from the sky (ground
reflected irradiance is not included in this algorithm) on a tilted
surface using the surface tilt angle, diffuse horizontal irradiance,
global horizontal irradiance, and sun zenith angle. Note that this
model is not well documented and has not been published in any
fashion (as of January 2012).
Parameters