Skip to content

Commit ce7864f

Browse files
committed
Adapt modelchain to changes in smallest_difference() tool
1 parent e16ec3c commit ce7864f

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

windpowerlib/modelchain.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import logging
1212
from windpowerlib import wind_speed, density, power_output, tools
13-
13+
import pandas as pd
1414

1515
class ModelChain(object):
1616
r"""Model to determine the output of a wind turbine
@@ -136,13 +136,17 @@ def rho_hub(self, weather, data_height):
136136
if 'temp_air_2' not in weather:
137137
weather['temp_air_2'] = None
138138
data_height['temp_air_2'] = None
139-
# Select temperature closer to hub height using smallest_difference()
140-
values = tools.smallest_difference(
141-
data_height['temp_air'], data_height['temp_air_2'],
142-
self.wind_turbine.hub_height, weather['temp_air'],
143-
weather['temp_air_2'])
144-
temp_air_height = values[0]
145-
temp_air_closest = values[1]
139+
temp_air_height = data_height['temp_air']
140+
temp_air_closest = weather['temp_air']
141+
else:
142+
# Select temperature closer to hub height using
143+
# smallest_difference()
144+
temp_air_height, temp_air_closest = tools.smallest_difference(
145+
pd.DataFrame(data={'temp_air': [weather['temp_air'],
146+
weather['temp_air_2']]},
147+
index=[data_height['temp_air'],
148+
data_height['temp_air_2']]),
149+
self.wind_turbine.hub_height, 'temp_air')
146150
# Check if temperature data is at hub height.
147151
if temp_air_height == self.wind_turbine.hub_height:
148152
logging.debug('Using given temperature at hub height.')
@@ -204,13 +208,16 @@ def v_wind_hub(self, weather, data_height):
204208
if 'v_wind_2' not in weather:
205209
weather['v_wind_2'] = None
206210
data_height['v_wind_2'] = None
207-
# Select wind speed closer to hub height using smallest_difference()
208-
values = tools.smallest_difference(
209-
data_height['v_wind'], data_height['v_wind_2'],
210-
self.wind_turbine.hub_height, weather['v_wind'],
211-
weather['v_wind_2'])
212-
v_wind_height = values[0]
213-
v_wind_closest = values[1]
211+
v_wind_height = data_height['v_wind']
212+
v_wind_closest = weather['v_wind']
213+
else:
214+
# Select wind speed closer to hub height using smallest_difference()
215+
v_wind_height, v_wind_closest = tools.smallest_difference(
216+
pd.DataFrame(data={'v_wind': [weather['v_wind'],
217+
weather['v_wind_2']]},
218+
index=[data_height['v_wind'],
219+
data_height['v_wind_2']]),
220+
self.wind_turbine.hub_height, 'v_wind')
214221
# Check if wind speed data is at hub height.
215222
if v_wind_height == self.wind_turbine.hub_height:
216223
logging.debug('Using given wind speed at hub height.')

0 commit comments

Comments
 (0)