-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathtest_wind_speed.py
More file actions
116 lines (103 loc) · 4.84 KB
/
test_wind_speed.py
File metadata and controls
116 lines (103 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
"""
SPDX-FileCopyrightText: 2019 oemof developer group <contact@oemof.org>
SPDX-License-Identifier: MIT
"""
import pandas as pd
import numpy as np
import pytest
from pandas.testing import assert_series_equal
from numpy.testing import assert_allclose
from windpowerlib.wind_speed import logarithmic_profile, hellman
class TestWindSpeed:
def test_logarithmic_profile(self):
parameters = {
"wind_speed": pd.Series(data=[5.0, 6.5]),
"wind_speed_height": 10,
"hub_height": 100,
"roughness_length": pd.Series(data=[0.15, 0.15]),
"obstacle_height": 0,
}
# Test wind_speed as pd.Series with roughness_length as pd.Series,
# np.array and float
v_wind_hub_exp = pd.Series(data=[7.74136523, 10.0637748])
assert_series_equal(logarithmic_profile(**parameters), v_wind_hub_exp)
parameters["roughness_length"] = np.array(
parameters["roughness_length"]
)
assert_series_equal(logarithmic_profile(**parameters), v_wind_hub_exp)
parameters["roughness_length"] = parameters["roughness_length"][0]
assert_series_equal(logarithmic_profile(**parameters), v_wind_hub_exp)
# Test wind_speed as np.array with roughness_length as float, pd.Series
# and np.array
v_wind_hub_exp = np.array([7.74136523, 10.0637748])
parameters["wind_speed"] = np.array(parameters["wind_speed"])
assert_allclose(logarithmic_profile(**parameters), v_wind_hub_exp)
assert isinstance(logarithmic_profile(**parameters), np.ndarray)
parameters["roughness_length"] = pd.Series(
data=[
parameters["roughness_length"],
parameters["roughness_length"],
]
)
assert_allclose(logarithmic_profile(**parameters), v_wind_hub_exp)
assert isinstance(logarithmic_profile(**parameters), np.ndarray)
parameters["roughness_length"] = np.array(
parameters["roughness_length"]
)
assert_allclose(logarithmic_profile(**parameters), v_wind_hub_exp)
assert isinstance(logarithmic_profile(**parameters), np.ndarray)
# Test obstacle_height is not zero
v_wind_hub_exp = np.array([13.54925281, 17.61402865])
parameters["obstacle_height"] = 12
assert_allclose(logarithmic_profile(**parameters), v_wind_hub_exp)
# Raise ValueError due to 0.7 * `obstacle_height` > `wind_speed_height`
with pytest.raises(ValueError):
parameters["obstacle_height"] = 20
logarithmic_profile(**parameters)
def test_hellman(self):
parameters = {
"wind_speed": pd.Series(data=[5.0, 6.5]),
"wind_speed_height": 10,
"hub_height": 100,
"roughness_length": pd.Series(data=[0.15, 0.15]),
"hellman_exponent": None,
}
# Test wind_speed is pd.Series with roughness_length is pd.Series,
# np.array and float
v_wind_hub_exp = pd.Series(data=[7.12462437, 9.26201168])
assert_series_equal(hellman(**parameters), v_wind_hub_exp)
parameters["roughness_length"] = np.array(
parameters["roughness_length"]
)
assert_series_equal(hellman(**parameters), v_wind_hub_exp)
parameters["roughness_length"] = parameters["roughness_length"][0]
assert_series_equal(hellman(**parameters), v_wind_hub_exp)
# Test wind_speed as np.array with roughness_length is float, pd.Series
# and np.array
v_wind_hub_exp = np.array([7.12462437, 9.26201168])
parameters["wind_speed"] = np.array(parameters["wind_speed"])
assert_allclose(hellman(**parameters), v_wind_hub_exp)
assert isinstance(hellman(**parameters), np.ndarray)
parameters["roughness_length"] = pd.Series(
data=(
parameters["roughness_length"],
parameters["roughness_length"],
)
)
assert_allclose(hellman(**parameters), v_wind_hub_exp)
assert isinstance(hellman(**parameters), np.ndarray)
parameters["roughness_length"] = np.array(
parameters["roughness_length"]
)
assert_allclose(hellman(**parameters), v_wind_hub_exp)
assert isinstance(hellman(**parameters), np.ndarray)
# Test roughness_length is None and hellman_exponent is None
v_wind_hub_exp = pd.Series(data=[6.9474774, 9.03172])
parameters["wind_speed"] = pd.Series(data=parameters["wind_speed"])
parameters["roughness_length"] = None
assert_series_equal(hellman(**parameters), v_wind_hub_exp)
# Test hellman_exponent is not None
v_wind_hub_exp = pd.Series(data=[7.92446596, 10.30180575])
parameters["roughness_length"] = 0.15
parameters["hellman_exponent"] = 0.2
assert_series_equal(hellman(**parameters), v_wind_hub_exp)