Skip to content

Commit 3ac4d64

Browse files
committed
Merge branch 'dev' into features/wind_farms_and_clusters
2 parents d2011c6 + 44a7f75 commit 3ac4d64

File tree

6 files changed

+135
-8
lines changed

6 files changed

+135
-8
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)

windpowerlib/modelchain.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class ModelChain(object):
2323
wind_speed_model : string
2424
Parameter to define which model to use to calculate the wind speed at
2525
hub height. Valid options are 'logarithmic', 'hellman' and
26-
'interpolation_extrapolation'. Default: 'logarithmic'.
26+
'interpolation_extrapolation', 'log_interpolation_extrapolation'.
27+
Default: 'logarithmic'.
2728
temperature_model : string
2829
Parameter to define which model to use to calculate the temperature of
2930
air at hub height. Valid options are 'linear_gradient' and
@@ -55,7 +56,8 @@ class ModelChain(object):
5556
wind_speed_model : string
5657
Parameter to define which model to use to calculate the wind speed at
5758
hub height. Valid options are 'logarithmic', 'hellman' and
58-
'interpolation_extrapolation'. Default: 'logarithmic'.
59+
'interpolation_extrapolation', 'log_interpolation_extrapolation'.
60+
Default: 'logarithmic'.
5961
temperature_model : string
6062
Parameter to define which model to use to calculate the temperature of
6163
air at hub height. Valid options are 'linear_gradient' and
@@ -300,6 +302,11 @@ def wind_speed_hub(self, weather_df):
300302
'extrapolation.')
301303
wind_speed_hub = tools.linear_interpolation_extrapolation(
302304
weather_df['wind_speed'], self.wind_turbine.hub_height)
305+
elif self.wind_speed_model == 'log_interpolation_extrapolation':
306+
logging.debug('Calculating wind speed using logarithmic inter- or '
307+
'extrapolation.')
308+
wind_speed_hub = tools.logarithmic_interpolation_extrapolation(
309+
weather_df['wind_speed'], self.wind_turbine.hub_height)
303310
else:
304311
raise ValueError("'{0}' is an invalid value. ".format(
305312
self.wind_speed_model) + "`wind_speed_model` must be "

windpowerlib/tools.py

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
def linear_interpolation_extrapolation(df, target_height):
1515
r"""
16-
Inter- or extrapolates between the values of a data frame.
16+
Linear inter- or extrapolates between the values of a data frame.
1717
1818
This function can be used for the inter-/extrapolation of a parameter
1919
(e.g wind speed) available at two or more different heights, to approximate
@@ -73,6 +73,60 @@ def linear_interpolation_extrapolation(df, target_height):
7373
(target_height - heights_sorted[0]) + df[heights_sorted[0]])
7474

7575

76+
def logarithmic_interpolation_extrapolation(df, target_height):
77+
r"""
78+
Logarithmic inter- or extrapolates between the values of a data frame.
79+
80+
This function can be used for the inter-/extrapolation of the wind speed if
81+
it is available at two or more different heights, to approximate
82+
the value at hub height. The function is carried out when the parameter
83+
`wind_speed_model` :class:`~.modelchain.ModelChain` class is
84+
'log_interpolation_extrapolation'.
85+
86+
Parameters
87+
----------
88+
df : pandas.DataFrame
89+
DataFrame with time series for parameter that is to be interpolated or
90+
extrapolated. The columns of the DataFrame are the different heights
91+
for which the parameter is available. If more than two heights are
92+
given, the two closest heights are used. See example in
93+
:py:func:`~.linear_interpolation_extrapolation` on how the
94+
DataFrame should look like and how the function can be used.
95+
target_height : float
96+
Height for which the parameter is approximated (e.g. hub height).
97+
98+
Returns
99+
-------
100+
pandas.Series
101+
Result of the inter-/extrapolation (e.g. wind speed at hub height).
102+
103+
Notes
104+
-----
105+
106+
For the logarithmic inter- and extrapolation the following equation is
107+
used [1]_:
108+
109+
.. math:: f(x) = \frac{\ln(x) \cdot (f(x_2) - f(x_1)) - f(x_2) \cdot \ln(x_1) + f(x_1) \cdot \ln(x_2)}{\ln(x_2) - \ln(x_1)}
110+
111+
References
112+
----------
113+
.. [1] Knorr, K.: "Modellierung von raum-zeitlichen Eigenschaften der
114+
Windenergieeinspeisung für wetterdatenbasierte
115+
Windleistungssimulationen". Universität Kassel, Diss., 2016,
116+
p. 83
117+
118+
"""
119+
# find closest heights
120+
heights_sorted = df.columns[
121+
sorted(range(len(df.columns)),
122+
key=lambda i: abs(df.columns[i] - target_height))]
123+
return ((np.log(target_height) *
124+
(df[heights_sorted[1]] - df[heights_sorted[0]]) -
125+
df[heights_sorted[1]] * np.log(heights_sorted[0]) +
126+
df[heights_sorted[0]] * np.log(heights_sorted[1])) /
127+
(np.log(heights_sorted[1]) - np.log(heights_sorted[0])))
128+
129+
76130
def gaussian_distribution(function_variable, standard_deviation, mean=0):
77131
r"""
78132
Normal distribution or gaussian distribution.
@@ -105,7 +159,7 @@ def gaussian_distribution(function_variable, standard_deviation, mean=0):
105159
----------
106160
.. [1] Berendsen, H.: "A Student's Guide to Data and Error Analysis".
107161
New York, Cambridge University Press, 2011, p. 37
108-
162+
109163
# TODO: add references
110164
111165
"""
@@ -118,6 +172,29 @@ def estimate_turbulence_intensity(height, roughness_length):
118172
"""
119173
Calculate turbulence intensity.
120174
175+
Parameters
176+
----------
177+
height : Float
178+
Height above ground in m at which the turbulence intensity is
179+
calculated.
180+
roughness_length : pandas.Series or numpy.array or float
181+
Roughness length.
182+
183+
Notes
184+
-----
185+
The following equation is used [1]_:
186+
187+
.. math:: TI = \frac{1}{ln \left(\frac{h}{z_\text{0}} \right)}
188+
189+
with:
190+
TI: turbulence intensity, h: height, :math:`z_{0}`: roughness length
191+
192+
References
193+
----------
194+
.. [1] Knorr, K.: "Modellierung von raum-zeitlichen Eigenschaften der
195+
Windenergieeinspeisung für wetterdatenbasierte
196+
Windleistungssimulationen". Universität Kassel, Diss., 2016,
197+
p. 88
198+
121199
"""
122-
# TODO: Search other possibilities for TI.
123200
return 1 / (np.log(height / roughness_length))

windpowerlib/wind_speed.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def logarithmic_profile(wind_speed, wind_speed_height, hub_height,
4242
4343
Notes
4444
-----
45-
The following equation is used [1]_:
45+
The following equation is used [1]_, [2]_, [3]_:
4646
4747
.. math:: v_{wind,hub}=v_{wind,data}\cdot
4848
\frac{\ln\left(\frac{h_{hub}-d}{z_{0}}\right)}{\ln\left(

0 commit comments

Comments
 (0)