Skip to content

Commit a495ae7

Browse files
committed
Add function for logarithmic interpolation/extrapolation
1 parent 0049b90 commit a495ae7

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

windpowerlib/tools.py

Lines changed: 55 additions & 1 deletion
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.

0 commit comments

Comments
 (0)