Skip to content

Commit 44a7f75

Browse files
committed
Merge branch 'features/tests' into dev
2 parents ac421ff + d5f41de commit 44a7f75

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

example/basic_example.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,5 +361,5 @@
361361
}
362362
},
363363
"nbformat": 4,
364-
"nbformat_minor": 1
364+
"nbformat_minor": 0
365365
}

tests/test_modelchain.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ def test_wind_speed_hub(self):
124124
test_mc_3 = mc.ModelChain(
125125
wt.WindTurbine(**self.test_turbine),
126126
wind_speed_model='interpolation_extrapolation')
127+
# Test modelchain with
128+
# wind_speed_model='log_interpolation_extrapolation'
129+
test_mc_4 = mc.ModelChain(
130+
wt.WindTurbine(**self.test_turbine),
131+
wind_speed_model='log_interpolation_extrapolation')
127132

128133
# Parameters for tests
129134
wind_speed_8m = np.array([[4.0], [5.0]])
@@ -145,6 +150,8 @@ def test_wind_speed_hub(self):
145150
assert_series_equal(test_mc_2.wind_speed_hub(weather_df), v_wind_exp)
146151
v_wind_exp = pd.Series(data=[50.0, 74.0])
147152
assert_series_equal(test_mc_3.wind_speed_hub(weather_df), v_wind_exp)
153+
v_wind_exp = pd.Series(data=[15.3188511585, 21.9782767378])
154+
assert_series_equal(test_mc_4.wind_speed_hub(weather_df), v_wind_exp)
148155

149156
# wind_speed is given at hub height
150157
weather_df.columns = [np.array(['wind_speed', 'wind_speed',

tests/test_tools.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import pandas as pd
22
from pandas.util.testing import assert_series_equal
33

4-
from windpowerlib.tools import linear_interpolation_extrapolation
4+
from windpowerlib.tools import (linear_interpolation_extrapolation,
5+
logarithmic_interpolation_extrapolation)
56

67

78
class TestTools:
@@ -39,3 +40,38 @@ def test_linear_interpolation_extrapolation(self):
3940
assert_series_equal(linear_interpolation_extrapolation(
4041
df, **parameters), exp_output)
4142

43+
def test_logarithmic_interpolation_extrapolation(self):
44+
parameters = {'target_height': 80}
45+
df = pd.DataFrame(data={10: [2.0, 2.0, 3.0],
46+
80: [4.0, 5.0, 6.0],
47+
200: [5.0, 8.0, 10.0]},
48+
index=[0, 1, 2])
49+
# target_height is equal to height given in a column of the DataFrame
50+
exp_output = pd.Series(data=[4.0, 5.0, 6.0])
51+
assert_series_equal(logarithmic_interpolation_extrapolation(
52+
df, **parameters), exp_output)
53+
# target_height is between heights given in the columns of the
54+
# DataFrame
55+
exp_output = pd.Series(
56+
data=[4.61074042165, 6.83222126494, 8.44296168659])
57+
parameters['target_height'] = 140
58+
assert_series_equal(logarithmic_interpolation_extrapolation(
59+
df, **parameters), exp_output)
60+
exp_output = pd.Series(
61+
data=[4.11328333429, 5.16992500144, 6.16992500144])
62+
parameters['target_height'] = 90
63+
assert_series_equal(logarithmic_interpolation_extrapolation(
64+
df, **parameters), exp_output)
65+
# target_height is greater than the heights given in the columns of the
66+
# DataFrame
67+
exp_output = pd.Series(
68+
data=[5.19897784672, 8.59693354015, 10.7959113869])
69+
parameters['target_height'] = 240
70+
assert_series_equal(logarithmic_interpolation_extrapolation(
71+
df, **parameters), exp_output)
72+
# target_height is smaller than the heights given in the columns of the
73+
# DataFrame
74+
exp_output = pd.Series(data=[1.33333333333, 1.0, 2.0])
75+
parameters['target_height'] = 5
76+
assert_series_equal(logarithmic_interpolation_extrapolation(
77+
df, **parameters), exp_output)

0 commit comments

Comments
 (0)