|
13 | 13 |
|
14 | 14 | def linear_interpolation_extrapolation(df, target_height): |
15 | 15 | r""" |
16 | | - Inter- or extrapolates between the values of a data frame. |
| 16 | + Linear inter- or extrapolates between the values of a data frame. |
17 | 17 |
|
18 | 18 | This function can be used for the inter-/extrapolation of a parameter |
19 | 19 | (e.g wind speed) available at two or more different heights, to approximate |
@@ -73,6 +73,60 @@ def linear_interpolation_extrapolation(df, target_height): |
73 | 73 | (target_height - heights_sorted[0]) + df[heights_sorted[0]]) |
74 | 74 |
|
75 | 75 |
|
| 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 | + |
76 | 130 | def gaussian_distribution(function_variable, standard_deviation, mean=0): |
77 | 131 | r""" |
78 | 132 | Normal distribution or gaussian distribution. |
|
0 commit comments