|
1 | 1 | import logging
|
2 | 2 | pvl_logger = logging.getLogger('pvlib')
|
3 | 3 |
|
4 |
| -import datetime |
5 |
| - |
6 | 4 | import numpy as np
|
7 | 5 | import pandas as pd
|
8 | 6 |
|
9 | 7 | from nose.tools import raises
|
10 |
| - |
11 | 8 | from numpy.testing import assert_almost_equal
|
| 9 | +from pandas.util.testing import assert_frame_equal, assert_series_equal |
12 | 10 |
|
13 | 11 | from pvlib.location import Location
|
14 | 12 | from pvlib import clearsky
|
15 | 13 | from pvlib import solarposition
|
16 | 14 |
|
17 | 15 | # setup times and location to be tested.
|
18 |
| -times = pd.date_range(start=datetime.datetime(2014,6,24), |
19 |
| - end=datetime.datetime(2014,6,26), freq='1Min') |
20 |
| - |
21 | 16 | tus = Location(32.2, -111, 'US/Arizona', 700)
|
22 |
| - |
| 17 | +times = pd.date_range(start='2014-06-24', end='2014-06-25', freq='3h') |
23 | 18 | times_localized = times.tz_localize(tus.tz)
|
24 | 19 |
|
25 | 20 | ephem_data = solarposition.get_solarposition(times, tus)
|
26 | 21 |
|
27 | 22 |
|
28 |
| - |
29 |
| -# test the ineichen clear sky model implementation in a few ways |
30 |
| - |
31 | 23 | def test_ineichen_required():
|
32 |
| - # the clearsky function should lookup the linke turbidity on its own |
| 24 | + # the clearsky function should call lookup_linke_turbidity by default |
33 | 25 | # will fail without scipy
|
34 |
| - clearsky.ineichen(times, tus) |
| 26 | + expected = pd.DataFrame(np.array([[0.,0.,0.], |
| 27 | + [0.,0.,0.], |
| 28 | + [40.53660309,302.47614235,78.1470311], |
| 29 | + [98.88372629,865.98938602,699.93403875], |
| 30 | + [122.57870881,931.83716051,1038.62116584], |
| 31 | + [109.30270612,899.88002304,847.68806472], |
| 32 | + [64.25699595,629.91187925,254.53048144], |
| 33 | + [0.,0.,0.], |
| 34 | + [0.,0.,0.]]), |
| 35 | + columns=['dhi', 'dni', 'ghi'], |
| 36 | + index=times_localized) |
| 37 | + out = clearsky.ineichen(times, tus) |
| 38 | + assert_frame_equal(expected, out) |
35 | 39 |
|
| 40 | + |
36 | 41 | def test_ineichen_supply_linke():
|
37 |
| - clearsky.ineichen(times, tus, linke_turbidity=3) |
| 42 | + expected = pd.DataFrame(np.array([[0.,0.,0.], |
| 43 | + [0.,0.,0.], |
| 44 | + [40.18673553,322.0649964,80.23287692], |
| 45 | + [95.14405816,876.49507151,703.48596755], |
| 46 | + [118.45873721,939.81653473,1042.34531752], |
| 47 | + [105.36671577,909.113377,851.3283881], |
| 48 | + [61.91607984,647.40869542,257.47471759], |
| 49 | + [0.,0.,0.], |
| 50 | + [0.,0.,0.]]), |
| 51 | + columns=['dhi', 'dni', 'ghi'], |
| 52 | + index=times_localized) |
| 53 | + out = clearsky.ineichen(times, tus, linke_turbidity=3) |
| 54 | + assert_frame_equal(expected, out) |
| 55 | + |
38 | 56 |
|
39 | 57 | def test_ineichen_solpos():
|
40 | 58 | clearsky.ineichen(times, tus, linke_turbidity=3,
|
41 |
| - solarposition_method='pyephem') |
| 59 | + solarposition_method='ephemeris') |
| 60 | + |
42 | 61 |
|
43 | 62 | def test_ineichen_airmass():
|
44 |
| - clearsky.ineichen(times, tus, linke_turbidity=3, |
45 |
| - airmass_model='simple') |
| 63 | + expected = pd.DataFrame(np.array([[0.,0.,0.], |
| 64 | + [0.,0.,0.], |
| 65 | + [41.70761136,293.72203458,78.22953786], |
| 66 | + [95.20590465,876.1650047,703.31872722], |
| 67 | + [118.46089555,939.8078753,1042.33896321], |
| 68 | + [105.39577655,908.97804342,851.24640259], |
| 69 | + [62.35382269,642.91022293,256.55363539], |
| 70 | + [0.,0.,0.], |
| 71 | + [0.,0.,0.]]), |
| 72 | + columns=['dhi', 'dni', 'ghi'], |
| 73 | + index=times_localized) |
| 74 | + out = clearsky.ineichen(times, tus, linke_turbidity=3, |
| 75 | + airmass_model='simple') |
| 76 | + assert_frame_equal(expected, out) |
| 77 | + |
| 78 | + |
| 79 | +def test_lookup_linke_turbidity(): |
| 80 | + times = pd.date_range(start='2014-06-24', end='2014-06-25', |
| 81 | + freq='12h', tz=tus.tz) |
| 82 | + # expect same value on 2014-06-24 0000 and 1200, and |
| 83 | + # diff value on 2014-06-25 |
| 84 | + expected = pd.Series(np.array([3.10126582, 3.10126582, 3.11443038]), |
| 85 | + index=times) |
| 86 | + out = clearsky.lookup_linke_turbidity(times, tus.latitude, tus.longitude) |
| 87 | + assert_series_equal(expected, out) |
| 88 | + |
| 89 | + |
| 90 | +def test_lookup_linke_turbidity_nointerp(): |
| 91 | + times = pd.date_range(start='2014-06-24', end='2014-06-25', |
| 92 | + freq='12h', tz=tus.tz) |
| 93 | + # expect same value for all days |
| 94 | + expected = pd.Series(np.array([3., 3., 3.]), index=times) |
| 95 | + out = clearsky.lookup_linke_turbidity(times, tus.latitude, tus.longitude, |
| 96 | + interp_turbidity=False) |
| 97 | + assert_series_equal(expected, out) |
| 98 | + |
| 99 | + |
| 100 | +def test_lookup_linke_turbidity_months(): |
| 101 | + times = pd.date_range(start='2014-04-01', end='2014-07-01', |
| 102 | + freq='1M', tz=tus.tz) |
| 103 | + expected = pd.Series(np.array([2.8943038, 2.97316456, 3.18025316]), |
| 104 | + index=times) |
| 105 | + out = clearsky.lookup_linke_turbidity(times, tus.latitude, |
| 106 | + tus.longitude) |
| 107 | + assert_series_equal(expected, out) |
| 108 | + |
| 109 | + |
| 110 | +def test_lookup_linke_turbidity_nointerp_months(): |
| 111 | + times = pd.date_range(start='2014-04-10', end='2014-07-10', |
| 112 | + freq='1M', tz=tus.tz) |
| 113 | + expected = pd.Series(np.array([2.85, 2.95, 3.]), index=times) |
| 114 | + out = clearsky.lookup_linke_turbidity(times, tus.latitude, tus.longitude, |
| 115 | + interp_turbidity=False) |
| 116 | + assert_series_equal(expected, out) |
| 117 | + # changing the dates shouldn't matter if interp=False |
| 118 | + times = pd.date_range(start='2014-04-05', end='2014-07-05', |
| 119 | + freq='1M', tz=tus.tz) |
| 120 | + out = clearsky.lookup_linke_turbidity(times, tus.latitude, tus.longitude, |
| 121 | + interp_turbidity=False) |
| 122 | + assert_series_equal(expected, out) |
46 | 123 |
|
47 |
| -def test_ineichen_keys(): |
48 |
| - clearsky_data = clearsky.ineichen(times, tus, linke_turbidity=3) |
49 |
| - assert 'ghi' in clearsky_data.columns |
50 |
| - assert 'dni' in clearsky_data.columns |
51 |
| - assert 'dhi' in clearsky_data.columns |
52 | 124 |
|
53 |
| -# test the haurwitz clear sky implementation |
54 | 125 | def test_haurwitz():
|
55 |
| - clearsky.haurwitz(ephem_data['zenith']) |
56 |
| - |
57 |
| -def test_haurwitz_keys(): |
58 |
| - clearsky_data = clearsky.haurwitz(ephem_data['zenith']) |
59 |
| - assert 'ghi' in clearsky_data.columns |
| 126 | + expected = pd.DataFrame(np.array([[0.], |
| 127 | + [0.], |
| 128 | + [82.85934048], |
| 129 | + [699.74514735], |
| 130 | + [1016.50198354], |
| 131 | + [838.32103769], |
| 132 | + [271.90853863], |
| 133 | + [0.], |
| 134 | + [0.]]), |
| 135 | + columns=['ghi'], index=times_localized) |
| 136 | + out = clearsky.haurwitz(ephem_data['zenith']) |
| 137 | + assert_frame_equal(expected, out) |
0 commit comments