1
+ import datetime
2
+
3
+ import numpy as np
4
+ from numpy import nan
5
+ import pandas as pd
1
6
import pytz
7
+
2
8
from nose .tools import raises
3
9
from pytz .exceptions import UnknownTimeZoneError
10
+ from pandas .util .testing import assert_series_equal , assert_frame_equal
4
11
5
12
from ..location import Location
6
13
@@ -18,11 +25,15 @@ def test_location_invalid_tz():
18
25
19
26
@raises (TypeError )
20
27
def test_location_invalid_tz_type ():
21
- Location (32.2 , - 111 , 5 )
28
+ Location (32.2 , - 111 , [ 5 ] )
22
29
23
30
def test_location_pytz_tz ():
24
31
Location (32.2 , - 111 , aztz )
25
32
33
+ def test_location_int_float_tz ():
34
+ Location (32.2 , - 111 , - 7 )
35
+ Location (32.2 , - 111 , - 7.0 )
36
+
26
37
def test_location_print_all ():
27
38
tus = Location (32.2 , - 111 , 'US/Arizona' , 700 , 'Tucson' )
28
39
expected_str = 'Tucson: latitude=32.2, longitude=-111, tz=US/Arizona, altitude=700'
@@ -33,14 +44,85 @@ def test_location_print_pytz():
33
44
expected_str = 'Tucson: latitude=32.2, longitude=-111, tz=US/Arizona, altitude=700'
34
45
assert tus .__str__ () == expected_str
35
46
47
+
36
48
def test_get_clearsky ():
37
- raise Exception ('test me' )
49
+ tus = Location (32.2 , - 111 , 'US/Arizona' , 700 , 'Tucson' )
50
+ times = pd .DatetimeIndex (start = '20160101T0600-0700' ,
51
+ end = '20160101T1800-0700' ,
52
+ freq = '3H' )
53
+ clearsky = tus .get_clearsky (times )
54
+ expected = pd .DataFrame (data = np .array (
55
+ [[ 0. , 0. , 0. ],
56
+ [ 49.99776128 , 763.02009659 , 258.93387913 ],
57
+ [ 70.79971557 , 957.15432484 , 612.08052529 ],
58
+ [ 59.01912609 , 879.09965133 , 415.32459426 ],
59
+ [ 0. , 0. , 0. ]]),
60
+ columns = ['dhi' , 'dni' , 'ghi' ],
61
+ index = times )
62
+ assert_frame_equal (expected , clearsky )
63
+
64
+
65
+ def test_from_tmy_3 ():
66
+ from .test_tmy import tmy3_testfile
67
+ from ..tmy import readtmy3
68
+ data , meta = readtmy3 (tmy3_testfile )
69
+ print (meta )
70
+ loc = Location .from_tmy (meta , data )
71
+ assert loc .name is not None
72
+ assert loc .altitude != 0
73
+ assert loc .tz != 'UTC'
74
+ assert_frame_equal (loc .tmy_data , data )
75
+
76
+
77
+ def test_from_tmy_2 ():
78
+ from .test_tmy import tmy2_testfile
79
+ from ..tmy import readtmy2
80
+ data , meta = readtmy2 (tmy2_testfile )
81
+ print (meta )
82
+ loc = Location .from_tmy (meta , data )
83
+ assert loc .name is not None
84
+ assert loc .altitude != 0
85
+ assert loc .tz != 'UTC'
86
+ assert_frame_equal (loc .tmy_data , data )
38
87
39
- def test_from_tmy ():
40
- raise Exception ('test me' )
41
88
42
89
def test_get_solarposition ():
43
- raise Exception ('test me' )
90
+ from .test_solarposition import expected , golden_mst
91
+ times = pd .date_range (datetime .datetime (2003 ,10 ,17 ,12 ,30 ,30 ),
92
+ periods = 1 , freq = 'D' , tz = golden_mst .tz )
93
+ ephem_data = golden_mst .get_solarposition (times , temperature = 11 )
94
+ ephem_data = np .round (ephem_data , 3 )
95
+ this_expected = expected .copy ()
96
+ this_expected .index = times
97
+ this_expected = np .round (this_expected , 3 )
98
+ print (this_expected , ephem_data [expected .columns ])
99
+ assert_frame_equal (this_expected , ephem_data [expected .columns ])
100
+
44
101
45
102
def test_get_airmass ():
46
- raise Exception ('test me' )
103
+ tus = Location (32.2 , - 111 , 'US/Arizona' , 700 , 'Tucson' )
104
+ times = pd .DatetimeIndex (start = '20160101T0600-0700' ,
105
+ end = '20160101T1800-0700' ,
106
+ freq = '3H' )
107
+ airmass = tus .get_airmass (times )
108
+ expected = pd .DataFrame (data = np .array (
109
+ [[ nan , nan ],
110
+ [ 3.61046506 , 3.32072602 ],
111
+ [ 1.76470864 , 1.62309115 ],
112
+ [ 2.45582153 , 2.25874238 ],
113
+ [ nan , nan ]]),
114
+ columns = ['airmass_relative' , 'airmass_absolute' ],
115
+ index = times )
116
+ assert_frame_equal (expected , airmass )
117
+
118
+ airmass = tus .get_airmass (times , model = 'young1994' )
119
+ expected = pd .DataFrame (data = np .array (
120
+ [[ nan , nan ],
121
+ [ 3.6075018 , 3.31800056 ],
122
+ [ 1.7641033 , 1.62253439 ],
123
+ [ 2.45413091 , 2.25718744 ],
124
+ [ nan , nan ]]),
125
+ columns = ['airmass_relative' , 'airmass_absolute' ],
126
+ index = times )
127
+ assert_frame_equal (expected , airmass )
128
+
0 commit comments