@@ -15,8 +15,8 @@ def smallest_difference(data_frame, comp_value, column_name):
1515
1616 Additionally returns a corresponding value. This function is for example
1717 used in :py:func:`~.modelchain.v_wind_hub` of the
18- :class:`~.modelchain.ModelChain` to choose the wind speed data that is
19- close to the hub height of the examined wind turbine. In this case the
18+ :class:`~.modelchain.ModelChain` to choose the wind speed data that is the
19+ closest to the hub height of the examined wind turbine. In this case the
2020 column of the data frame contains wind speed time series and the indices
2121 are the corresponding heights for which these time series apply.
2222
@@ -35,14 +35,16 @@ def smallest_difference(data_frame, comp_value, column_name):
3535
3636 Returns
3737 -------
38- Tuple(float, pd.Series or np.array or float )
38+ Tuple(float, float or pd.Series or np.array)
3939 Closest value to comparative value as float and its corresponding value
40- as float.
40+ as float, pd.Series or np.array .
4141
4242 """
43+ # Calculate difference to comp_value for all indices of data_frame
4344 diff = []
4445 for index in sorted (data_frame .index ):
4546 diff .append (abs (comp_value - index ))
47+ # Find smallest difference
4648 closest_value = sorted (data_frame .index )[diff .index (min (diff ))]
4749 corresp_value = data_frame [column_name ][closest_value ]
4850 return (closest_value , corresp_value )
@@ -53,15 +55,15 @@ def linear_extra_interpolation(data_frame, requested_height, column_name):
5355 Inter- or extrapolates between the values of a data frame.
5456
5557 This function can for example be used for the interpolation of a wind
56- speed, density or temperature.
58+ speed, density or temperature to calculated these values at hub height of a
59+ wind turbine.
5760
5861 Parameters
5962 ----------
6063 data_frame : DataFrame
6164 Indices are the values between which will be interpolated or from which
6265 will be extrapolated, the corresponding values are in the column
63- specified by `column_name` and they can be floats, pd.Series or
64- np.arrays.
66+ specified by `column_name` and can be floats, pd.Series or np.arrays.
6567 requested_height : float
6668 Height for which the interpolation takes place (e.g. hub height of wind
6769 turbine).
@@ -71,32 +73,35 @@ def linear_extra_interpolation(data_frame, requested_height, column_name):
7173
7274 Returns
7375 -------
74- interpolant : pandas.Series, numpy.array or float
76+ interpolant : float or pandas.Series or numpy.array
7577 Result of the interpolation (e.g. density at hub height).
7678
7779 Notes
7880 -----
7981
80- For the interpolation np.interp() is used and the following equation is
81- used for extrapolation:
82+ For the inter- and extrapolation the following equation is used:
8283
8384 .. math:: interpolant = (value_2 - value_1) / (height_2 - height_1) *
8485 (height_{requested} - height_1) + value_1
8586
8687 with:
87- :math:`height_2`: largest/smallest index of data frame,
88- :math:`height_1`: second largest/smallest index of data frame,
88+ :math:`height_2`: index of data frame closest to
89+ :math:`height_{requested}`, :math:`height_1`: index of data frame
90+ second closest to :math:`height_{requested}`,
8991 :math:`value_2`: corresponding value to `height_2`,
9092 :math:`value_1`: correponding value to `height_1`,
9193 :math:`height_{requested}` : height for which the interpolation takes
9294 place
9395
9496 """
97+ # Get closest index of data_frame to requested_height
9598 height_2 , value_2 = smallest_difference (data_frame , requested_height ,
9699 column_name )
100+ # Drop row with closest index to requested_height and get second closest
97101 data_frame_2 = data_frame .drop (height_2 )
98102 height_1 , value_1 = smallest_difference (data_frame_2 , requested_height ,
99103 column_name )
104+ # Interpolation
100105 interpolant = ((value_2 - value_1 ) / (height_2 - height_1 ) *
101106 (requested_height - height_1 ) + value_1 )
102107 return interpolant
0 commit comments