@@ -223,40 +223,28 @@ def v_wind_hub(self, weather, data_height):
223223 if 'v_wind_2' not in weather :
224224 weather ['v_wind_2' ] = None
225225 data_height ['v_wind_2' ] = None
226- if data_height ['v_wind' ] == self .wind_turbine .hub_height :
227- logging .debug ('Using given wind speed (at hub height).' )
228- v_wind = weather ['v_wind' ]
229- elif data_height ['v_wind_2' ] == self .wind_turbine .hub_height :
230- logging .debug ('Using given wind speed (2) (at hub height).' )
231- v_wind = weather ['v_wind_2' ]
226+ # Select wind speed closer to hub height with smallest_difference()
227+ values = tools .smallest_difference (
228+ data_height ['v_wind' ], data_height ['v_wind_2' ],
229+ self .wind_turbine .hub_height , weather ['v_wind' ],
230+ weather ['v_wind_2' ])
231+ v_wind_height = values .closest_value
232+ v_wind_closest = values .corresp_value
233+
234+ if v_wind_height == self .wind_turbine .hub_height :
235+ logging .debug ('Using given wind speed ' + values .logging_string )
236+ v_wind = v_wind_closest
232237 # Calculation of wind speed in m/s at hub height.
233238 elif self .wind_model == 'logarithmic' :
234239 logging .debug ('Calculating v_wind using logarithmic wind profile.' )
235- if weather ['v_wind_2' ] is None :
236- v_wind = wind_speed .logarithmic_wind_profile (
237- weather ['v_wind' ], data_height ['v_wind' ],
238- self .wind_turbine .hub_height ,
239- weather ['z0' ], self .obstacle_height )
240- else :
241- if (abs (data_height ['v_wind' ] -
242- self .wind_turbine .hub_height ) <=
243- abs (data_height ['v_wind_2' ] -
244- self .wind_turbine .hub_height )):
245- v_wind = wind_speed .logarithmic_wind_profile (
246- weather ['v_wind' ], data_height ['v_wind' ],
247- self .wind_turbine .hub_height , weather ['z0' ],
248- self .obstacle_height )
249- else :
250- v_wind = wind_speed .logarithmic_wind_profile (
251- weather ['v_wind_2' ], data_height ['v_wind_2' ],
252- self .wind_turbine .hub_height , weather ['z0' ],
253- self .obstacle_height )
240+ v_wind = wind_speed .logarithmic_wind_profile (
241+ v_wind_closest , v_wind_height , self .wind_turbine .hub_height ,
242+ weather ['z0' ], self .obstacle_height )
254243 elif self .wind_model == 'hellman' :
255244 logging .debug ('Calculating v_wind using hellman equation.' )
256- v_wind = wind_speed .v_wind_hellman (
257- weather ['v_wind' ], data_height ['v_wind' ],
258- self .wind_turbine .hub_height ,
259- self .hellman_exp , weather ['z0' ])
245+ v_wind = wind_speed .v_wind_hellman (v_wind_closest , v_wind_height ,
246+ self .wind_turbine .hub_height ,
247+ self .hellman_exp , weather ['z0' ])
260248 else :
261249 raise ValueError ("'{0}' is an invalid value." .format (
262250 self .wind_model ) + "`wind_model` " +
0 commit comments