|
14 | 14 | SINGLEAXIS_COL_ORDER = ['tracker_theta', 'aoi',
|
15 | 15 | 'surface_azimuth', 'surface_tilt']
|
16 | 16 |
|
| 17 | + |
17 | 18 | def test_solar_noon():
|
18 |
| - apparent_zenith = pd.Series([10]) |
19 |
| - apparent_azimuth = pd.Series([180]) |
| 19 | + index = pd.DatetimeIndex(start='20180701T1200', freq='1s', periods=1) |
| 20 | + apparent_zenith = pd.Series([10], index=index) |
| 21 | + apparent_azimuth = pd.Series([180], index=index) |
20 | 22 | tracker_data = tracking.singleaxis(apparent_zenith, apparent_azimuth,
|
21 | 23 | axis_tilt=0, axis_azimuth=0,
|
22 | 24 | max_angle=90, backtrack=True,
|
23 | 25 | gcr=2.0/7.0)
|
24 | 26 |
|
25 | 27 | expect = pd.DataFrame({'tracker_theta': 0, 'aoi': 10,
|
26 | 28 | 'surface_azimuth': 90, 'surface_tilt': 0},
|
27 |
| - index=[0], dtype=np.float64) |
| 29 | + index=index, dtype=np.float64) |
28 | 30 | expect = expect[SINGLEAXIS_COL_ORDER]
|
29 | 31 |
|
30 | 32 | assert_frame_equal(expect, tracker_data)
|
31 | 33 |
|
32 | 34 |
|
| 35 | +def test_scalars(): |
| 36 | + apparent_zenith = 10 |
| 37 | + apparent_azimuth = 180 |
| 38 | + tracker_data = tracking.singleaxis(apparent_zenith, apparent_azimuth, |
| 39 | + axis_tilt=0, axis_azimuth=0, |
| 40 | + max_angle=90, backtrack=True, |
| 41 | + gcr=2.0/7.0) |
| 42 | + assert isinstance(tracker_data, dict) |
| 43 | + expect = {'tracker_theta': 0, 'aoi': 10, 'surface_azimuth': 90, |
| 44 | + 'surface_tilt': 0} |
| 45 | + for k, v in expect.items(): |
| 46 | + assert_allclose(tracker_data[k], v) |
| 47 | + |
| 48 | + |
| 49 | +def test_arrays(): |
| 50 | + apparent_zenith = np.array([10]) |
| 51 | + apparent_azimuth = np.array([180]) |
| 52 | + tracker_data = tracking.singleaxis(apparent_zenith, apparent_azimuth, |
| 53 | + axis_tilt=0, axis_azimuth=0, |
| 54 | + max_angle=90, backtrack=True, |
| 55 | + gcr=2.0/7.0) |
| 56 | + assert isinstance(tracker_data, dict) |
| 57 | + expect = {'tracker_theta': 0, 'aoi': 10, 'surface_azimuth': 90, |
| 58 | + 'surface_tilt': 0} |
| 59 | + for k, v in expect.items(): |
| 60 | + assert_allclose(tracker_data[k], v) |
| 61 | + |
| 62 | + |
| 63 | +def test_nans(): |
| 64 | + apparent_zenith = np.array([10, np.nan, 10]) |
| 65 | + apparent_azimuth = np.array([180, 180, np.nan]) |
| 66 | + with np.errstate(invalid='ignore'): |
| 67 | + tracker_data = tracking.singleaxis(apparent_zenith, apparent_azimuth, |
| 68 | + axis_tilt=0, axis_azimuth=0, |
| 69 | + max_angle=90, backtrack=True, |
| 70 | + gcr=2.0/7.0) |
| 71 | + expect = {'tracker_theta': np.array([0, nan, nan]), |
| 72 | + 'aoi': np.array([10, nan, nan]), |
| 73 | + 'surface_azimuth': np.array([90, nan, nan]), |
| 74 | + 'surface_tilt': np.array([0, nan, nan])} |
| 75 | + for k, v in expect.items(): |
| 76 | + assert_allclose(tracker_data[k], v) |
| 77 | + |
| 78 | + # repeat with Series because nans can differ |
| 79 | + apparent_zenith = pd.Series(apparent_zenith) |
| 80 | + apparent_azimuth = pd.Series(apparent_azimuth) |
| 81 | + with np.errstate(invalid='ignore'): |
| 82 | + tracker_data = tracking.singleaxis(apparent_zenith, apparent_azimuth, |
| 83 | + axis_tilt=0, axis_azimuth=0, |
| 84 | + max_angle=90, backtrack=True, |
| 85 | + gcr=2.0/7.0) |
| 86 | + expect = pd.DataFrame(np.array( |
| 87 | + [[ 0., 10., 90., 0.], |
| 88 | + [nan, nan, nan, nan], |
| 89 | + [nan, nan, nan, nan]]), |
| 90 | + columns=['tracker_theta', 'aoi', 'surface_azimuth', 'surface_tilt']) |
| 91 | + assert_frame_equal(tracker_data, expect) |
| 92 | + |
| 93 | + |
| 94 | +def test_arrays_multi(): |
| 95 | + apparent_zenith = np.array([[10, 10], [10, 10]]) |
| 96 | + apparent_azimuth = np.array([[180, 180], [180, 180]]) |
| 97 | + # singleaxis should fail for num dim > 1 |
| 98 | + with pytest.raises(ValueError): |
| 99 | + tracker_data = tracking.singleaxis(apparent_zenith, apparent_azimuth, |
| 100 | + axis_tilt=0, axis_azimuth=0, |
| 101 | + max_angle=90, backtrack=True, |
| 102 | + gcr=2.0/7.0) |
| 103 | + # uncomment if we ever get singleaxis to support num dim > 1 arrays |
| 104 | + # assert isinstance(tracker_data, dict) |
| 105 | + # expect = {'tracker_theta': np.full_like(apparent_zenith, 0), |
| 106 | + # 'aoi': np.full_like(apparent_zenith, 10), |
| 107 | + # 'surface_azimuth': np.full_like(apparent_zenith, 90), |
| 108 | + # 'surface_tilt': np.full_like(apparent_zenith, 0)} |
| 109 | + # for k, v in expect.items(): |
| 110 | + # assert_allclose(tracker_data[k], v) |
| 111 | + |
| 112 | + |
33 | 113 | def test_azimuth_north_south():
|
34 | 114 | apparent_zenith = pd.Series([60])
|
35 | 115 | apparent_azimuth = pd.Series([90])
|
@@ -163,14 +243,38 @@ def test_axis_azimuth():
|
163 | 243 | assert_frame_equal(expect, tracker_data)
|
164 | 244 |
|
165 | 245 |
|
166 |
| -def test_index_mismatch(): |
167 |
| - apparent_zenith = pd.Series([30]) |
168 |
| - apparent_azimuth = pd.Series([90,180]) |
169 |
| - with pytest.raises(ValueError): |
170 |
| - tracker_data = tracking.singleaxis(apparent_zenith, apparent_azimuth, |
171 |
| - axis_tilt=0, axis_azimuth=90, |
172 |
| - max_angle=90, backtrack=True, |
173 |
| - gcr=2.0/7.0) |
| 246 | +def test_horizon_flat(): |
| 247 | + # GH 569 |
| 248 | + solar_azimuth = np.array([0, 180, 359]) |
| 249 | + solar_zenith = np.array([100, 45, 100]) |
| 250 | + solar_azimuth = pd.Series(solar_azimuth) |
| 251 | + solar_zenith = pd.Series(solar_zenith) |
| 252 | + # depending on platform and numpy versions this will generate |
| 253 | + # RuntimeWarning: invalid value encountered in > < >= |
| 254 | + out = tracking.singleaxis(solar_zenith, solar_azimuth, axis_tilt=0, |
| 255 | + axis_azimuth=180, backtrack=False, max_angle=180) |
| 256 | + expected = pd.DataFrame(np.array( |
| 257 | + [[ nan, nan, nan, nan], |
| 258 | + [ 0., 45., 270., 0.], |
| 259 | + [ nan, nan, nan, nan]]), |
| 260 | + columns=['tracker_theta', 'aoi', 'surface_azimuth', 'surface_tilt']) |
| 261 | + assert_frame_equal(out, expected) |
| 262 | + |
| 263 | + |
| 264 | +def test_horizon_tilted(): |
| 265 | + # GH 569 |
| 266 | + solar_azimuth = np.array([0, 180, 359]) |
| 267 | + solar_zenith = np.full_like(solar_azimuth, 45) |
| 268 | + solar_azimuth = pd.Series(solar_azimuth) |
| 269 | + solar_zenith = pd.Series(solar_zenith) |
| 270 | + out = tracking.singleaxis(solar_zenith, solar_azimuth, axis_tilt=90, |
| 271 | + axis_azimuth=180, backtrack=False, max_angle=180) |
| 272
E377
td> | + expected = pd.DataFrame(np.array( |
| 273 | + [[ 180., 45., 0., 90.], |
| 274 | + [ 0., 45., 180., 90.], |
| 275 | + [ 179., 45., 359., 90.]]), |
| 276 | + columns=['tracker_theta', 'aoi', 'surface_azimuth', 'surface_tilt']) |
| 277 | + assert_frame_equal(out, expected) |
174 | 278 |
|
175 | 279 |
|
176 | 280 | def test_SingleAxisTracker_creation():
|
@@ -285,19 +389,25 @@ def test_get_irradiance():
|
285 | 389 | end='20160101 1800-0700', freq='6H')
|
286 | 390 | location = Location(latitude=32, longitude=-111)
|
287 | 391 | solar_position = location.get_solarposition(times)
|
288 |
| - irrads = pd.DataFrame({'dni':[900,0], 'ghi':[600,0], 'dhi':[100,0]}, |
| 392 | + irrads = pd.DataFrame({'dni': [900, 0], 'ghi': [600, 0], 'dhi': [100, 0]}, |
289 | 393 | index=times)
|
290 | 394 | solar_zenith = solar_position['apparent_zenith']
|
291 | 395 | solar_azimuth = solar_position['azimuth']
|
292 |
| - tracker_data = system.singleaxis(solar_zenith, solar_azimuth) |
293 |
| - |
294 |
| - irradiance = system.get_irradiance(tracker_data['surface_tilt'], |
295 |
| - tracker_data['surface_azimuth'], |
296 |
| - solar_zenith, |
297 |
| - solar_azimuth, |
298 |
| - irrads['dni'], |
299 |
| - irrads['ghi'], |
300 |
| - irrads['dhi']) |
| 396 | + |
| 397 | + # invalid warnings already generated in horizon test above, |
| 398 | + # no need to clutter test output here |
| 399 | + with np.errstate(invalid='ignore'): |
| 400 | + tracker_data = system.singleaxis(solar_zenith, solar_azimuth) |
| 401 | + |
| 402 | + # some invalid values in irradiance.py. not our problem here |
| 403 | + with np.errstate(invalid='ignore'): |
| 404 | + irradiance = system.get_irradiance(tracker_data['surface_tilt'], |
| 405 | + tracker_data['surface_azimuth'], |
| 406 | + solar_zenith, |
| 407 | + solar_azimuth, |
| 408 | + irrads['dni'], |
| 409 | + irrads['ghi'], |
| 410 | + irrads['dhi']) |
301 | 411 |
|
302 | 412 | expected = pd.DataFrame(data=np.array(
|
303 | 413 | [[961.80070, 815.94490, 145.85580, 135.32820, 10.52757492],
|
|
0 commit comments