@@ -149,17 +149,22 @@ def rho_hub(self, weather, data_height):
149149 if 'temp_air_2' not in weather :
150150 weather ['temp_air_2' ] = None
151151 data_height ['temp_air_2' ] = None
152- if data_height ['temp_air' ] == self .wind_turbine .hub_height :
153- logging .debug ('Using given temperature (at hub height).' )
154- temp_hub = weather ['temp_air' ]
155- elif data_height ['temp_air_2' ] == self .wind_turbine .hub_height :
156- logging .debug ('Using given temperature (2) (at hub height).' )
157- temp_hub = weather ['temp_air_2' ]
152+ # Select temperature closer to hub height using smallest_difference()
153+ values = tools .smallest_difference (
154+ data_height ['temp_air' ], data_height ['temp_air_2' ],
155+ self .wind_turbine .hub_height , weather ['temp_air' ],
156+ weather ['temp_air_2' ])
157+ temp_air_height = values .closest_value
158+ temp_air_closest = values .corresp_value
159+ # Check if temperature data is at hub height.
160+ if temp_air_height == self .wind_turbine .hub_height :
161+ logging .debug ('Using given temperature ' + values .logging_string )
162+ temp_hub = temp_air_closest
158163 # Calculation of temperature in K at hub height.
159164 elif self .temperature_model == 'gradient' :
160165 logging .debug ('Calculating temperature using a temp. gradient.' )
161166 temp_hub = density .temperature_gradient (
162- weather [ 'temp_air' ], data_height [ 'temp_air' ] ,
167+ temp_air_closest , temp_air_height ,
163168 self .wind_turbine .hub_height )
164169 elif self .temperature_model == 'interpolation' :
165170 logging .debug ('Calculating temperature using interpolation.' )
0 commit comments