17
17
from . import requires_ephem
18
18
19
19
# setup times and locations to be tested.
20
- times = pd .date_range (start = datetime .datetime (2014 ,6 ,24 ),
20
+ times = pd .date_range (start = datetime .datetime (2014 ,6 ,24 ),
21
21
end = datetime .datetime (2014 ,6 ,26 ), freq = '15Min' )
22
22
23
23
tus = Location (32.2 , - 111 , 'US/Arizona' , 700 ) # no DST issues possible
37
37
38
38
# the physical tests are run at the same time as the NREL SPA test.
39
39
# pyephem reproduces the NREL result to 2 decimal places.
40
- # this doesn't mean that one code is better than the other.
40
+ # this doesn't mean that one code is better than the other.
41
41
42
42
43
43
def test_spa_c_physical ():
@@ -46,15 +46,15 @@ def test_spa_c_physical():
46
46
try :
47
47
ephem_data = solarposition .spa_c (times , golden_mst .latitude ,
48
48
golden_mst .longitude ,
49
- pressure = 82000 ,
49
+ pressure = 82000 ,
50
50
temperature = 11 )
51
51
except ImportError :
52
52
raise SkipTest
53
53
this_expected = expected .copy ()
54
54
this_expected .index = times
55
55
assert_frame_equal (this_expected , ephem_data [expected .columns ])
56
-
57
-
56
+
57
+
58
58
def test_spa_c_physical_dst ():
59
59
times = pd .date_range (datetime .datetime (2003 ,10 ,17 ,13 ,30 ,30 ),
60
60
periods = 1 , freq = 'D' , tz = golden .tz )
@@ -64,7 +64,7 @@ def test_spa_c_physical_dst():
64
64
pressure = 82000 ,
65
65
temperature = 11 )
66
66
except ImportError :
67
- raise SkipTest
67
+ raise SkipTest
68
68
this_expected = expected .copy ()
69
69
this_expected .index = times
70
70
assert_frame_equal (this_expected , ephem_data [expected .columns ])
@@ -75,8 +75,8 @@ def test_spa_python_numpy_physical():
75
75
periods = 1 , freq = 'D' , tz = golden_mst .tz )
76
76
ephem_data = solarposition .spa_python (times , golden_mst .latitude ,
77
77
golden_mst .longitude ,
78
- pressure = 82000 ,
79
- temperature = 11 , delta_t = 67 ,
78
+ pressure = 82000 ,
79
+ temperature = 11 , delta_t = 67 ,
80
80
atmos_refract = 0.5667 ,
81
81
how = 'numpy' )
82
82
this_expected = expected .copy ()
@@ -89,8 +89,8 @@ def test_spa_python_numpy_physical_dst():
89
89
periods = 1 , freq = 'D' , tz = golden .tz )
90
90
ephem_data = solarposition .spa_python (times , golden .latitude ,
91
91
golden .longitude ,
92
- pressure = 82000 ,
93
- temperature = 11 , delta_t = 67 ,
92
+ pressure = 82000 ,
93
+ temperature = 11 , delta_t = 67 ,
94
94
atmos_refract = 0.5667 ,
95
95
how = 'numpy' )
96
96
this_expected = expected .copy ()
@@ -106,13 +106,13 @@ def test_spa_python_numba_physical():
106
106
vers = numba .__version__ .split ('.' )
107
107
if int (vers [0 ] + vers [1 ]) < 17 :
108
108
raise SkipTest
109
-
109
+
110
110
times = pd .date_range (datetime .datetime (2003 ,10 ,17 ,12 ,30 ,30 ),
111
111
periods = 1 , freq = 'D' , tz = golden_mst .tz )
112
112
ephem_data = solarposition .spa_python (times , golden_mst .latitude ,
113
113
golden_mst .longitude ,
114
- pressure = 82000 ,
115
- temperature = 11 , delta_t = 67 ,
114
+ pressure = 82000 ,
115
+ temperature = 11 , delta_t = 67 ,
116
116
atmos_refract = 0.5667 ,
117
117
how = 'numba' , numthreads = 1 )
118
118
this_expected = expected .copy ()
@@ -132,8 +132,8 @@ def test_spa_python_numba_physical_dst():
132
132
times = pd .date_range (datetime .datetime (2003 ,10 ,17 ,13 ,30 ,30 ),
133
133
periods = 1 , freq = 'D' , tz = golden .tz )
134
134
ephem_data = solarposition .spa_python (times , golden .latitude ,
135
- golden .longitude , pressure = 82000 ,
136
- temperature = 11 , delta_t = 67 ,
135
+ golden .longitude , pressure = 82000 ,
136
+ temperature = 11 , delta_t = 67 ,
137
137
atmos_refract = 0.5667 ,
138
138
how = 'numba' , numthreads = 1 )
139
139
this_expected = expected .copy ()
@@ -153,7 +153,7 @@ def test_get_sun_rise_set_transit():
153
153
datetime .datetime (2004 , 12 , 4 , 19 , 2 , 2 , 499704 )]
154
154
).tz_localize ('UTC' ).tolist ()
155
155
result = solarposition .get_sun_rise_set_transit (times , south .latitude ,
156
- south .longitude ,
156
+ south .longitude ,
157
157
delta_t = 64.0 )
158
158
frame = pd .DataFrame ({'sunrise' :sunrise , 'sunset' :sunset }, index = times )
159
159
del result ['transit' ]
@@ -211,7 +211,7 @@ def test_calc_time():
211
211
212
212
epoch = datetime .datetime (1970 ,1 ,1 )
213
213
epoch_dt = pytz .utc .localize (epoch )
214
-
214
+
215
215
loc = tus
216
216
loc .pressure = 0
217
217
actual_time = pytz .timezone (loc .tz ).localize (datetime .datetime (2014 , 10 , 10 , 8 , 30 ))
@@ -222,12 +222,12 @@ def test_calc_time():
222
222
az = solarposition .calc_time (lb , ub , loc .latitude , loc .longitude ,
223
223
'az' , math .radians (116.3 ))
224
224
actual_timestamp = (actual_time - epoch_dt ).total_seconds ()
225
-
226
- assert_almost_equals ((alt .replace (second = 0 , microsecond = 0 ) -
225
+
226
+ assert_almost_equals ((alt .replace (second = 0 , microsecond = 0 ) -
227
227
epoch_dt ).total_seconds (), actual_timestamp )
228
- assert_almost_equals ((az .replace (second = 0 , microsecond = 0 ) -
228
+ assert_almost_equals ((az .replace (second = 0 , microsecond = 0 ) -
229
229
epoch_dt ).total_seconds (), actual_timestamp )
230
-
230
+
231
231
@requires_ephem
232
232
def test_earthsun_distance ():
233
233
times = pd .date_range (datetime .datetime (2003 ,10 ,17 ,13 ,30 ,30 ),
@@ -261,3 +261,80 @@ def test_ephemeris_physical_dst():
261
261
this_expected = np .round (this_expected , 2 )
262
262
ephem_data = np .round (ephem_data , 2 )
263
263
assert_frame_equal (this_expected , ephem_data [this_expected .columns ])
264
+
265
+ @raises (ValueError )
266
+ def test_get_solarposition_error ():
267
+ times = pd .date_range (datetime .datetime (2003 ,10 ,17 ,13 ,30 ,30 ),
268
+ periods = 1 , freq = 'D' , tz = golden .tz )
269
+ ephem_data = solarposition .get_solarposition (times , golden .latitude ,
270
+ golden .longitude ,
271
+ pressure = 82000 ,
272
+ temperature = 11 ,
273
+ method = 'error this' )
274
+
275
+ def test_get_solarposition_pressure ():
276
+ times = pd .date_range (datetime .datetime (2003 ,10 ,17 ,13 ,30 ,30 ),
277
+ periods = 1 , freq = 'D' , tz = golden .tz )
278
+ ephem_data = solarposition .get_solarposition (times , golden .latitude ,
279
+ golden .longitude ,
280
+ pressure = 82000 ,
281
+ temperature = 11 )
282
+ this_expected = expected .copy ()
283
+ this_expected .index = times
284
+ this_expected = np .round (this_expected , 5 )
285
+ ephem_data = np .round (ephem_data , 5 )
286
+ assert_frame_equal (this_expected , ephem_data [this_expected .columns ])
287
+
288
+ ephem_data = solarposition .get_solarposition (times , golden .latitude ,
289
+ golden .longitude ,
290
+ pressure = 0.0 ,
291
+ temperature = 11 )
292
+ this_expected = expected .copy ()
293
+ this_expected .index = times
294
+ this_expected = np .round (this_expected , 5 )
295
+ ephem_data = np .round (ephem_data , 5 )
296
+ try :
297
+ assert_frame_equal (this_expected , ephem_data [this_expected .columns ])
298
+ except AssertionError :
299
+ pass
300
+ else :
301
+ raise AssertionError
302
+
303
+ def test_get_solarposition_altitude ():
304
+ times = pd .date_range (datetime .datetime (2003 ,10 ,17 ,13 ,30 ,30 ),
305
+ periods = 1 , freq = 'D' , tz = golden .tz )
306
+ ephem_data = solarposition .get_solarposition (times , golden .latitude ,
307
+ golden .longitude ,
308
+ altitude = golden .altitude ,
309
+ temperature = 11 )
310
+ this_expected = expected .copy ()
311
+ this_expected .index = times
312
+ this_expected = np .round (this_expected , 5 )
313
+ ephem_data = np .round (ephem_data , 5 )
314
+ assert_frame_equal (this_expected , ephem_data [this_expected .columns ])
315
+
316
+ ephem_data = solarposition .get_solarposition (times , golden .latitude ,
317
+ golden .longitude ,
318
+ altitude = 0.0 ,
319
+ temperature = 11 )
320
+ this_expected = expected .copy ()
321
+ this_expected .index = times
322
+ this_expected = np .round (this_expected , 5 )
323
+ ephem_data = np .round (ephem_data , 5 )
324
+ try :
325
+ assert_frame_equal (this_expected , ephem_data [this_expected .columns ])
326
+ except AssertionError :
327
+ pass
328
+ else :
329
+ raise AssertionError
330
+
331
+ def test_get_solarposition_no_kwargs ():
332
+ times = pd .date_range (datetime .datetime (2003 ,10 ,17 ,13 ,30 ,30 ),
333
+ periods = 1 , freq = 'D' , tz = golden .tz )
334
+ ephem_data = solarposition .get_solarposition (times , golden .latitude ,
335
+ golden .longitude )
336
+ this_expected = expected .copy ()
337
+ this_expected .index = times
338
+ this_expected = np .round (this_expected , 2 )
339
+ ephem_data = np .round (ephem_data , 2 )
340
+ assert_frame_equal (this_expected , ephem_data [this_expected .columns ])
0 commit comments