Skip to content

Commit c547c3c

Browse files
committed
make location tests work
1 parent 3391abf commit c547c3c

File tree

1 file changed

+88
-6
lines changed

1 file changed

+88
-6
lines changed

pvlib/test/test_location.py

Lines changed: 88 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
import datetime
2+
3+
import numpy as np
4+
from numpy import nan
5+
import pandas as pd
16
import pytz
7+
28
from nose.tools import raises
39
from pytz.exceptions import UnknownTimeZoneError
10+
from pandas.util.testing import assert_series_equal, assert_frame_equal
411

512
from ..location import Location
613

@@ -18,11 +25,15 @@ def test_location_invalid_tz():
1825

1926
@raises(TypeError)
2027
def test_location_invalid_tz_type():
21-
Location(32.2, -111, 5)
28+
Location(32.2, -111, [5])
2229

2330
def test_location_pytz_tz():
2431
Location(32.2, -111, aztz)
2532

33+
def test_location_int_float_tz():
34+
Location(32.2, -111, -7)
35+
Location(32.2, -111, -7.0)
36+
2637
def test_location_print_all():
2738
tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson')
2839
expected_str = 'Tucson: latitude=32.2, longitude=-111, tz=US/Arizona, altitude=700'
@@ -33,14 +44,85 @@ def test_location_print_pytz():
3344
expected_str = 'Tucson: latitude=32.2, longitude=-111, tz=US/Arizona, altitude=700'
3445
assert tus.__str__() == expected_str
3546

47+
3648
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)
3887

39-
def test_from_tmy():
40-
raise Exception('test me')
4188

4289
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+
44101

45102
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

Comments
 (0)