Skip to content

Commit ac421ff

Browse files
committed
Merge branch 'features/tools' into dev
2 parents df4d3b6 + d708f64 commit ac421ff

File tree

3 files changed

+90
-6
lines changed

3 files changed

+90
-6
lines changed

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)