3
3
from collections import OrderedDict
4
4
5
5
import numpy as np
6
+ from numpy import nan
6
7
import pandas as pd
7
8
import pytz
8
9
20
21
21
22
22
23
def test_ineichen_series ():
23
- tus = Location (32.2 , - 111 , 'US/Arizona' , 700 )
24
- times = pd .date_range (start = '2014-06-24' , end = '2014-06-25' , freq = '3h' )
25
- times_localized = times .tz_localize (tus .tz )
26
- ephem_data = solarposition .get_solarposition (times_localized , tus .latitude ,
27
- tus .longitude )
28
- am = atmosphere .relativeairmass (ephem_data ['apparent_zenith' ])
29
- am = atmosphere .absoluteairmass (am , atmosphere .alt2pres (tus .altitude ))
24
+ times = pd .date_range (start = '2014-06-24' , end = '2014-06-25' , freq = '3h' ,
25
+ tz = 'America/Phoenix' )
26
+ apparent_zenith = pd .Series (np .array (
27
+ [124.0390863 , 113.38779941 , 82.85457044 , 46.0467599 , 10.56413562 ,
28
+ 34.86074109 , 72.41687122 , 105.69538659 , 124.05614124 ]),
29
+ index = times )
30
+ am = pd .Series (np .array (
31
+ [nan , nan , 6.97935524 , 1.32355476 , 0.93527685 ,
32
+ 1.12008114 , 3.01614096 , nan , nan ]),
33
+ index = times )
30
34
expected = pd .DataFrame (np .
31
- array ([[ 0. , 0. , 0. ],
32
- [ 0. , 0. , 0. ],
33
- [ 91.12492792 , 321.16092181 , 51.17628184 ],
34
- [ 716.46580533 , 888.90147035 , 99.5050056 ],
35
- [ 1053.42066043 , 953.24925854 , 116.32868969 ],
36
- [ 863.54692781 , 922.06124712 , 106.95536561 ],
37
- [ 271.06382274 , 655.44925241 , 73.05968071 ],
38
- [ 0. , 0. , 0. ],
39
- [ 0. , 0. , 0. ]]),
35
+ array ([[ 0. , 0. , 0. ],
36
+ [ 0. , 0. , 0. ],
37
+ [ 65.49426624 , 321.16092181 , 25.54562017 ],
38
+ [ 704.6968125 , 888.90147035 , 87.73601277 ],
39
+ [1044.1230677 , 953.24925854 , 107.03109696 ],
40
+ [ 853.02065704 , 922.06124712 , 96.42909484 ],
41
+ [ 251.99427693 , 655.44925241 , 53.9901349 ],
42
+ [ 0. , 0. , 0. ],
43
+ [ 0. , 0. , 0. ]]),
40
44
columns = ['ghi' , 'dni' , 'dhi' ],
41
- index = times_localized )
45
+ index = times )
42
46
43
- out = clearsky .ineichen (ephem_data ['apparent_zenith' ], am , 3 )
47
+ out = clearsky .ineichen (apparent_zenith , am , 3 )
48
+ assert_frame_equal (expected , out )
49
+
50
+
51
+ def test_ineichen_series_perez_enhancement ():
52
+ times = pd .date_range (start = '2014-06-24' , end = '2014-06-25' , freq = '3h' ,
53
+ tz = 'America/Phoenix' )
54
+ apparent_zenith = pd .Series (np .array (
55
+ [124.0390863 , 113.38779941 , 82.85457044 , 46.0467599 , 10.56413562 ,
56
+ 34.86074109 , 72.41687122 , 105.69538659 , 124.05614124 ]),
57
+ index = times )
58
+ am = pd .Series (np .array (
59
+ [nan , nan , 6.97935524 , 1.32355476 , 0.93527685 ,
60
+ 1.12008114 , 3.01614096 , nan , nan ]),
61
+ index = times )
62
+ expected = pd .DataFrame (np .
63
+ array ([[ 0. , 0. , 0. ],
64
+ [ 0. , 0. , 0. ],
65
+ [ 91.1249279 , 321.16092171 , 51.17628184 ],
66
+ [ 716.46580547 , 888.9014706 , 99.50500553 ],
67
+ [1053.42066073 , 953.24925905 , 116.3286895 ],
68
+ [ 863.54692748 , 922.06124652 , 106.9553658 ],
69
+ [ 271.06382275 , 655.44925213 , 73.05968076 ],
70
+ [ 0. , 0. , 0. ],
71
+ [ 0. , 0. , 0. ]]),
72
+ columns = ['ghi' , 'dni' , 'dhi' ],
73
+ index = times )
74
+
75
+ out = clearsky .ineichen (apparent_zenith , am , 3 , perez_enhancement = True )
44
76
assert_frame_equal (expected , out )
45
77
46
78
47
79
def test_ineichen_scalar_input ():
48
80
expected = OrderedDict ()
49
- expected ['ghi' ] = 1048.592893113678
81
+ expected ['ghi' ] = 1038.159219
50
82
expected ['dni' ] = 942.2081860378344
51
- expected ['dhi' ] = 120.6989665520498
83
+ expected ['dhi' ] = 110.26529293612793
52
84
53
85
out = clearsky .ineichen (10. , 1. , 3. )
54
86
for k , v in expected .items ():
@@ -74,9 +106,9 @@ def test_ineichen_nans():
74
106
expected ['dni' ] = np .full (length , np .nan )
75
107
expected ['dhi' ] = np .full (length , np .nan )
76
108
77
- expected ['ghi' ][length - 1 ] = 1053.205472
78
- expected ['dni' ][length - 1 ] = 946.352797
79
- expected ['dhi' ][length - 1 ] = 121.2299
109
+ expected ['ghi' ][length - 1 ] = 1042.72590228
110
+ expected ['dni' ][length - 1 ] = 946.35279683
111
+ expected ['dhi' ][length - 1 ] = 110.75033088
80
112
81
113
out = clearsky .ineichen (apparent_zenith , airmass_absolute ,
82
114
linke_turbidity , dni_extra = dni_extra )
@@ -89,43 +121,43 @@ def test_ineichen_arrays():
89
121
expected = OrderedDict ()
90
122
91
123
expected ['ghi' ] = (np .
92
- array ([[[ 1106.78342709 , 1064.7691287 , 1024.34972343 ],
93
- [ 847.84529406 , 815.66047425 , 784.69741345 ],
94
- [ 192.19092519 , 184.89521884 , 177.87646277 ]],
124
+ array ([[[1095.77074798 , 1054.17449885 , 1014.15727338 ],
125
+ [ 839.40909243 , 807.54451692 , 776.88954373 ],
126
+ [ 190.27859353 , 183.05548067 , 176.10656239 ]],
95
127
96
- [[ 959.12310134 , 775.2374976 , 626.60692548 ],
97
- [ 734.73092205 , 593.86637713 , 480.00875328 ],
98
- [ 166.54997871 , 134.61857872 , 108.80915072 ]],
128
+ [[ 773.49041181 , 625.19479557 , 505.33080493 ],
129
+ [ 592.52803177 , 478.92699901 , 387.10585505 ],
130
+ [ 134.31520045 , 108.56393694 , 87.74977339 ]],
99
131
100
- [[ 1026.15144142 , 696.85030591 , 473.22483724 ],
101
- [ 786.0776095 , 533.81830453 , 362.51125692 ],
102
- [ 178.18932781 , 121.00678573 , 82.17463061 ]]]))
132
+ [[ 545.9968869 , 370.78162375 , 251.79449885 ],
133
+ [ 418.25788117 , 284.03520249 , 192.88577665 ],
134
+ [ 94.81136442 , 64.38555328 , 43.72365587 ]]]))
103
135
104
136
expected ['dni' ] = (np .
105
- array ([[[ 1024.58284359 , 942.20818604 , 861.11344424 ],
106
- [ 1024.58284359 , 942.20818604 , 861.11344424 ],
107
- [ 1024.58284359 , 942.20818604 , 861.11344424 ]],
137
+ array ([[[1014.38807396 , 942.20818604 , 861.11344424 ],
138
+ [1014.38807396 , 942.20818604 , 861.11344424 ],
139
+ [1014.38807396 , 942.20818604 , 861.11344424 ]],
108
140
109
- [[ 687.61305142 , 419.14891162 , 255.50098235 ],
110
- [ 687.61305142 , 419.14891162 , 255.50098235 ],
111
- [ 687.61305142 , 419.14891162 , 255.50098235 ]],
141
+ [[ 687.61305142 , 419.14891162 , 255.50098235 ],
142
+ [ 687.61305142 , 419.14891162 , 255.50098235 ],
143
+ [ 687.61305142 , 419.14891162 , 255.50098235 ]],
112
144
113
- [[ 458.62196014 , 186.46177428 , 75.80970012 ],
114
- [ 458.62196014 , 186.46177428 , 75.80970012 ],
115
- [ 458.62196014 , 186.46177428 , 75.80970012 ]]]))
145
+ [[ 458.62196014 , 186.46177428 , 75.80970012 ],
146
+ [ 458.62196014 , 186.46177428 , 75.80970012 ],
147
+ [ 458.62196014 , 186.46177428 , 75.80970012 ]]]))
116
148
117
149
expected ['dhi' ] = (np .
118
- array ([[[ 82.20058349 , 122.56094266 , 163.23627919 ],
119
- [ 62.96930021 , 93.88712907 , 125.04624459 ],
120
- [ 14.27398153 , 21.28248435 , 28.34568241 ]],
150
+ array ([[[ 81.38267402 , 111.96631281 , 153.04382915 ],
151
+ [ 62.3427452 , 85.77117175 , 117.23837487 ],
152
+ [ 14.13195304 , 19.44274618 , 26.57578203 ]],
121
153
122
- [[ 271.51004993 , 356.08858598 , 371.10594313 ],
123
- [ 207.988765 , 272.77968255 , 284.28364554 ],
124
- [ 47.14722539 , 61.83413404 , 64.44187075 ]],
154
+ [[ 85.87736039 , 206.04588395 , 249.82982258 ],
155
+ [ 65.78587472 , 157.84030442 , 191.38074731 ],
156
+ [ 14.91244713 , 35.77949226 , 43.38249342 ]],
125
157
126
- [[ 567.52948128 , 510.38853163 , 397.41513712 ],
127
- [ 434.75280544 , 390.98029849 , 304.4376574 ],
128
- [ 98.5504602 , 88.62803842 , 69.01041434 ]]]))
158
+ [[ 87.37492676 , 184.31984947 , 175.98479873 ],
159
+ [ 66.93307711 , 141.19719644 , 134.81217714 ],
160
+ [ 15.17249681 , 32.00680597 , 30.5594396 ]]]))
129
161
130
162
apparent_zenith = np .linspace (0 , 80 , 3 )
131
163
airmass_absolute = np .linspace (1 , 10 , 3 )
@@ -142,7 +174,7 @@ def test_ineichen_arrays():
142
174
143
175
def test_ineichen_dni_extra ():
144
176
expected = pd .DataFrame (
145
- np .array ([[ 1053.20547182 , 946.35279683 , 121.22990042 ]]),
177
+ np .array ([[1042.72590228 , 946.35279683 , 110.75033088 ]]),
146
178
columns = ['ghi' , 'dni' , 'dhi' ])
147
179
148
180
out = clearsky .ineichen (10 , 1 , 3 , dni_extra = pd .Series (1370 ))
@@ -151,7 +183,7 @@ def test_ineichen_dni_extra():
151
183
152
184
def test_ineichen_altitude ():
153
185
expected = pd .DataFrame (
154
- np .array ([[ 1145.64245696 , 994.95377835 , 165.80426215 ]]),
186
+ np .array ([[1134.24312405 , 994.95377835 , 154.40492924 ]]),
155
187
columns = ['ghi' , 'dni' , 'dhi' ])
156
188
157
189
out = clearsky .ineichen (10 , 1 , 3 , altitude = pd .Series (2000 ))
@@ -526,18 +558,18 @@ def test_detect_clearsky_components(detect_clearsky_data):
526
558
assert_series_equal (expected ['Clear or not' ], clear_samples ,
527
559
check_dtype = False , check_names = False )
528
560
assert isinstance (components , OrderedDict )
529
- assert np .allclose (alpha , 0.95345573579557108 )
561
+ assert np .allclose (alpha , 0.9633903181941296 )
530
562
531
563
532
564
@requires_scipy
533
565
def test_detect_clearsky_iterations (detect_clearsky_data ):
534
566
expected , cs = detect_clearsky_data
535
- alpha = 1.0348
567
+ alpha = 1.0448
536
568
with pytest .warns (RuntimeWarning ):
537
569
clear_samples = clearsky .detect_clearsky (
538
570
expected ['GHI' ], cs ['ghi' ]* alpha , cs .index , 10 , max_iterations = 1 )
539
- assert (clear_samples [:'2012-04-01 10:39 :00' ] == True ).all ()
540
- assert (clear_samples ['2012-04-01 10:40 :00' :] == False ).all ()
571
+ assert (clear_samples [:'2012-04-01 10:41 :00' ] == True ).all ()
572
+ assert (clear_samples ['2012-04-01 10:42 :00' :] == False ).all ()
541
573
clear_samples = clearsky .detect_clearsky (
542
574
expected ['GHI' ], cs ['ghi' ]* alpha , cs .index , 10 , max_iterations = 20 )
543
575
assert_series_equal (expected ['Clear or not' ], clear_samples ,
0 commit comments