def test_logarithmic_interpolation_extrapolation(self): parameters = {'target_height': 80} df = pd.DataFrame(data={10: [2.0, 2.0, 3.0], 80: [4.0, 5.0, 6.0], 200: [5.0, 8.0, 10.0]}, index=[0, 1, 2]) # target_height is equal to height given in a column of the DataFrame exp_output = pd.Series(data=[4.0, 5.0, 6.0]) assert_series_equal(logarithmic_interpolation_extrapolation( df, **parameters), exp_output) # target_height is between heights given in the columns of the # DataFrame exp_output = pd.Series( data=[4.61074042165, 6.83222126494, 8.44296168659]) parameters['target_height'] = 140 assert_series_equal(logarithmic_interpolation_extrapolation( df, **parameters), exp_output) exp_output = pd.Series( data=[4.11328333429, 5.16992500144, 6.16992500144]) parameters['target_height'] = 90 assert_series_equal(logarithmic_interpolation_extrapolation( df, **parameters), exp_output) # target_height is greater than the heights given in the columns of the # DataFrame exp_output = pd.Series( data=[5.19897784672, 8.59693354015, 10.7959113869]) parameters['target_height'] = 240 assert_series_equal(logarithmic_interpolation_extrapolation( df, **parameters), exp_output) # target_height is smaller than the heights given in the columns of the # DataFrame exp_output = pd.Series(data=[1.33333333333, 1.0, 2.0]) parameters['target_height'] = 5 assert_series_equal(logarithmic_interpolation_extrapolation( df, **parameters), exp_output)
def wind_speed_hub(self, weather_df): r""" Calculates the wind speed at hub height. The method specified by the parameter `wind_speed_model` is used. Parameters ---------- weather_df : :pandas:`pandas.DataFrame<frame>` DataFrame with time series for wind speed `wind_speed` in m/s and roughness length `roughness_length` in m. The columns of the DataFrame are a MultiIndex where the first level contains the variable name (e.g. wind_speed) and the second level contains the height at which it applies (e.g. 10, if it was measured at a height of 10 m). See documentation of :func:`ModelChain.run_model` for an example on how to create the weather_df DataFrame. Returns ------- :pandas:`pandas.Series<series>` or numpy.array Wind speed in m/s at hub height. Notes ----- If `weather_df` contains wind speeds at different heights the given wind speed(s) closest to the hub height are used. """ if self.power_plant.hub_height in weather_df["wind_speed"]: wind_speed_hub = weather_df["wind_speed"][ self.power_plant.hub_height] elif self.wind_speed_model == "logarithmic": logging.debug("Calculating wind speed using logarithmic wind " "profile.") closest_height = weather_df["wind_speed"].columns[min( range(len(weather_df["wind_speed"].columns)), key=lambda i: abs(weather_df["wind_speed"].columns[i] - self. power_plant.hub_height), )] wind_speed_hub = wind_speed.logarithmic_profile( weather_df["wind_speed"][closest_height], closest_height, self.power_plant.hub_height, weather_df["roughness_length"].iloc[:, 0], self.obstacle_height, ) elif self.wind_speed_model == "hellman": logging.debug("Calculating wind speed using hellman equation.") closest_height = weather_df["wind_speed"].columns[min( range(len(weather_df["wind_speed"].columns)), key=lambda i: abs(weather_df["wind_speed"].columns[i] - self. power_plant.hub_height), )] wind_speed_hub = wind_speed.hellman( weather_df["wind_speed"][closest_height], closest_height, self.power_plant.hub_height, weather_df["roughness_length"].iloc[:, 0], self.hellman_exp, ) elif self.wind_speed_model == "interpolation_extrapolation": logging.debug("Calculating wind speed using linear inter- or " "extrapolation.") wind_speed_hub = tools.linear_interpolation_extrapolation( weather_df["wind_speed"], self.power_plant.hub_height) elif self.wind_speed_model == "log_interpolation_extrapolation": logging.debug("Calculating wind speed using logarithmic inter- or " "extrapolation.") wind_speed_hub = tools.logarithmic_interpolation_extrapolation( weather_df["wind_speed"], self.power_plant.hub_height) else: raise ValueError( "'{0}' is an invalid value. ".format(self.wind_speed_model) + "`wind_speed_model` must be " "'logarithmic', 'hellman', 'interpolation_extrapolation' " + "or 'log_interpolation_extrapolation'.") return wind_speed_hub