1
1
import datetime
2
2
from collections import OrderedDict
3
+ import warnings
3
4
4
5
import numpy as np
5
6
from numpy import array , nan
@@ -107,18 +108,24 @@ def test_get_extra_radiation(input, expected, method):
107
108
assert_allclose (out , expected , atol = 1 )
108
109
109
110
110
- @requires_numba
111
- def test_get_extra_radiation_nrel_numba (times ):
112
- result = irradiance .get_extra_radiation (times , method = 'nrel' , how = 'numba' ,
113
- numthreads = 8 )
114
- assert_allclose (result , [1322.332316 , 1322.296282 , 1322.261205 , 1322.227091 ])
115
-
116
-
117
111
def test_get_extra_radiation_epoch_year ():
118
112
out = irradiance .get_extra_radiation (doy , method = 'nrel' , epoch_year = 2012 )
119
113
assert_allclose (out , 1382.4926804890767 , atol = 0.1 )
120
114
121
115
116
+ @requires_numba
117
+ def test_get_extra_radiation_nrel_numba (times ):
118
+ with warnings .catch_warnings ():
119
+ # don't warn on method reload or num threads
120
+ warnings .simplefilter ("ignore" )
121
+ result = irradiance .get_extra_radiation (
122
+ times , method = 'nrel' , how = 'numba' , numthreads = 4 )
123
+ # and reset to no-numba state
124
+ irradiance .get_extra_radiation (times , method = 'nrel' )
125
+ assert_allclose (result ,
126
+ [1322.332316 , 1322.296282 , 1322.261205 , 1322.227091 ])
127
+
128
+
122
129
def test_get_extra_radiation_invalid ():
123
130
with pytest .raises (ValueError ):
124
131
irradiance .get_extra_radiation (300 , method = 'invalid' )
@@ -135,13 +142,15 @@ def test_grounddiffuse_simple_series(irrad_data):
135
142
136
143
137
144
def test_grounddiffuse_albedo_0 (irrad_data ):
138
- ground_irrad = irradiance .get_ground_diffuse (40 , irrad_data ['ghi' ], albedo = 0 )
145
+ ground_irrad = irradiance .get_ground_diffuse (
146
+ 40 , irrad_data ['ghi' ], albedo = 0 )
139
147
assert 0 == ground_irrad .all ()
140
148
141
149
142
150
def test_grounddiffuse_albedo_invalid_surface (irrad_data ):
143
151
with pytest .raises (KeyError ):
144
- irradiance .get_ground_diffuse (40 , irrad_data ['ghi' ], surface_type = 'invalid' )
152
+ irradiance .get_ground_diffuse (
153
+ 40 , irrad_data ['ghi' ], surface_type = 'invalid' )
145
154
146
155
147
156
def test_grounddiffuse_albedo_surface (irrad_data ):
@@ -193,35 +202,33 @@ def test_klucher_series(irrad_data, ephem_data):
193
202
194
203
195
204
def test_haydavies (irrad_data , ephem_data , dni_et ):
196
- result = irradiance .haydavies (40 , 180 , irrad_data ['dhi' ], irrad_data ['dni' ],
197
- dni_et ,
198
- ephem_data ['apparent_zenith' ],
199
- ephem_data ['azimuth' ])
205
+ result = irradiance .haydavies (
206
+ 40 , 180 , irrad_data ['dhi' ], irrad_data ['dni' ], dni_et ,
207
+ ephem_data ['apparent_zenith' ], ephem_data ['azimuth' ])
200
208
# values from matlab 1.4 code
201
209
assert_allclose (result , [0 , 27.1775 , 102.9949 , 33.1909 ], atol = 1e-4 )
202
210
203
211
204
212
def test_reindl (irrad_data , ephem_data , dni_et ):
205
- result = irradiance .reindl (40 , 180 , irrad_data ['dhi' ], irrad_data ['dni' ],
206
- irrad_data ['ghi' ], dni_et ,
207
- ephem_data ['apparent_zenith' ],
208
- ephem_data ['azimuth' ])
213
+ result = irradiance .reindl (
214
+ 40 , 180 , irrad_data ['dhi' ], irrad_data ['dni' ], irrad_data ['ghi' ],
215
+ dni_et , ephem_data ['apparent_zenith' ], ephem_data ['azimuth' ])
209
216
# values from matlab 1.4 code
210
217
assert_allclose (result , [np .nan , 27.9412 , 104.1317 , 34.1663 ], atol = 1e-4 )
211
218
212
219
213
220
def test_king (irrad_data , ephem_data ):
214
221
result = irradiance .king (40 , irrad_data ['dhi' ], irrad_data ['ghi' ],
215
- ephem_data ['apparent_zenith' ])
222
+ ephem_data ['apparent_zenith' ])
216
223
assert_allclose (result , [0 , 44.629352 , 115.182626 , 79.719855 ], atol = 1e-4 )
217
224
218
225
219
226
def test_perez (irrad_data , ephem_data , dni_et , relative_airmass ):
220
227
dni = irrad_data ['dni' ].copy ()
221
228
dni .iloc [2 ] = np .nan
222
229
out = irradiance .perez (40 , 180 , irrad_data ['dhi' ], dni ,
223
- dni_et , ephem_data ['apparent_zenith' ],
224
- ephem_data ['azimuth' ], relative_airmass )
230
+ dni_et , ephem_data ['apparent_zenith' ],
231
+ ephem_data ['azimuth' ], relative_airmass )
225
232
expected = pd .Series (np .array (
226
233
[ 0. , 31.46046871 , np .nan , 45.45539877 ]),
227
234
index = irrad_data .index )
@@ -260,8 +267,9 @@ def test_perez_arrays(irrad_data, ephem_data, dni_et, relative_airmass):
260
267
dni = irrad_data ['dni' ].copy ()
261
268
dni .iloc [2 ] = np .nan
262
269
out = irradiance .perez (40 , 180 , irrad_data ['dhi' ].values , dni .values ,
263
- dni_et , ephem_data ['apparent_zenith' ].values ,
264
- ephem_data ['azimuth' ].values , relative_airmass .values )
270
+ dni_et , ephem_data ['apparent_zenith' ].values ,
271
+ ephem_data ['azimuth' ].values ,
272
+ relative_airmass .values )
265
273
expected = np .array (
266
274
[ 0. , 31.46046871 , np .nan , 45.45539877 ])
267
275
assert_allclose (out , expected , atol = 1e-2 )
@@ -289,8 +297,8 @@ def test_sky_diffuse_zenith_close_to_90(model):
289
297
290
298
291
299
def test_liujordan ():
292
- expected = pd .DataFrame (np .
293
- array ( [[863.859736967 , 653.123094076 , 220.65905025 ]]),
300
+ expected = pd .DataFrame (np .array (
301
+ [[863.859736967 , 653.123094076 , 220.65905025 ]]),
294
302
columns = ['ghi' , 'dni' , 'dhi' ],
295
303
index = [0 ])
296
304
out = irradiance .liujordan (
@@ -484,7 +492,7 @@ def test_dirint_nans():
484
492
485
493
486
494
def test_dirint_tdew ():
487
- times = pd .DatetimeIndex (['2014-06-24T12-0700' ,'2014-06-24T18-0700' ])
495
+ times = pd .DatetimeIndex (['2014-06-24T12-0700' , '2014-06-24T18-0700' ])
488
496
ghi = pd .Series ([1038.62 , 254.53 ], index = times )
489
497
zenith = pd .Series ([10.567 , 72.469 ], index = times )
490
498
pressure = 93193.
@@ -495,7 +503,7 @@ def test_dirint_tdew():
495
503
496
504
497
505
def test_dirint_no_delta_kt ():
498
- times = pd .DatetimeIndex (['2014-06-24T12-0700' ,'2014-06-24T18-0700' ])
506
+ times = pd .DatetimeIndex (['2014-06-24T12-0700' , '2014-06-24T18-0700' ])
499
507
ghi = pd .Series ([1038.62 , 254.53 ], index = times )
500
508
zenith = pd .Series ([10.567 , 72.469 ], index = times )
501
509
pressure = 93193.
@@ -507,16 +515,16 @@ def test_dirint_no_delta_kt():
507
515
508
516
def test_dirint_coeffs ():
509
517
coeffs = irradiance ._get_dirint_coeffs ()
510
- assert coeffs [0 ,0 , 0 , 0 ] == 0.385230
511
- assert coeffs [0 ,1 , 2 , 1 ] == 0.229970
512
- assert coeffs [3 ,2 , 6 , 3 ] == 1.032260
518
+ assert coeffs [0 , 0 , 0 , 0 ] == 0.385230
519
+ assert coeffs [0 , 1 , 2 , 1 ] == 0.229970
520
+ assert coeffs [3 , 2 , 6 , 3 ] == 1.032260
513
521
514
522
515
523
def test_dirint_min_cos_zenith_max_zenith ():
516
524
# map out behavior under difficult conditions with various
517
525
# limiting kwargs settings
518
526
# times don't have any physical relevance
519
- times = pd .DatetimeIndex (['2014-06-24T12-0700' ,'2014-06-24T18-0700' ])
527
+ times = pd .DatetimeIndex (['2014-06-24T12-0700' , '2014-06-24T18-0700' ])
520
528
ghi = pd .Series ([0 , 1 ], index = times )
521
529
solar_zenith = pd .Series ([90 , 89.99 ], index = times )
522
530
@@ -727,7 +735,7 @@ def test_dirindex_min_cos_zenith_max_zenith():
727
735
# map out behavior under difficult conditions with various
728
736
# limiting kwargs settings
729
737
# times don't have any physical relevance
730
- times = pd .DatetimeIndex (['2014-06-24T12-0700' ,'2014-06-24T18-0700' ])
738
+ times = pd .DatetimeIndex (['2014-06-24T12-0700' , '2014-06-24T18-0700' ])
731
739
ghi = pd .Series ([0 , 1 ], index = times )
732
740
ghi_clearsky = pd .Series ([0 , 1 ], index = times )
733
741
dni_clearsky = pd .Series ([0 , 5 ], index = times )
0 commit comments