Skip to content

Commit 2ea5a81

Browse files
committed
Move the checks of the weather file to tools
1 parent abaf3b8 commit 2ea5a81

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

windpowerlib/modelchain.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -512,17 +512,7 @@ def run_model(self, weather_df):
512512
'wind_speed'
513513
514514
"""
515-
# Convert data heights to integer. In some case they are strings.
516-
weather_df.columns = pd.MultiIndex.from_arrays([
517-
weather_df.columns.get_level_values(0),
518-
pd.to_numeric(weather_df.columns.get_level_values(1))])
519-
520-
if weather_df.isnull().any().any():
521-
nan_columns = list(weather_df.columns[weather_df.isnull().any()])
522-
msg = ("The following columns of the weather data contain invalid "
523-
"values like 'nan': {0}")
524-
warnings.warn(msg.format(nan_columns),
525-
tools.WindpowerlibUserWarning)
515+
weather_df = tools.check_weather_data(weather_df)
526516

527517
wind_speed_hub = self.wind_speed_hub(weather_df)
528518
density_hub = (

windpowerlib/tools.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"""
88
import numpy as np
99
import warnings
10+
import pandas as pd
1011

1112

1213
class WindpowerlibUserWarning(UserWarning):
@@ -221,3 +222,25 @@ def estimate_turbulence_intensity(height, roughness_length):
221222
222223
"""
223224
return 1 / (np.log(height / roughness_length))
225+
226+
227+
def check_weather_data(weather_df):
228+
"""
229+
Check weather Data Frame.
230+
231+
- Raise warning if there are nan values.
232+
- Convert columns if heights are string and not numeric.
233+
234+
"""
235+
# Convert data heights to integer. In some case they are strings.
236+
weather_df.columns = pd.MultiIndex.from_arrays([
237+
weather_df.columns.get_level_values(0),
238+
pd.to_numeric(weather_df.columns.get_level_values(1))])
239+
240+
# check for nan values
241+
if weather_df.isnull().any().any():
242+
nan_columns = list(weather_df.columns[weather_df.isnull().any()])
243+
msg = ("The following columns of the weather data contain invalid "
244+
"values like 'nan': {0}")
245+
warnings.warn(msg.format(nan_columns), WindpowerlibUserWarning)
246+
return weather_df

windpowerlib/turbine_cluster_modelchain.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import logging
1111
import pandas as pd
1212
from windpowerlib import wake_losses
13-
from windpowerlib.modelchain import ModelChain
13+
from windpowerlib.modelchain import ModelChain, tools
1414

1515

1616
class TurbineClusterModelChain(ModelChain):
@@ -289,10 +289,7 @@ def run_model(self, weather_df):
289289
'wind_speed'
290290
291291
"""
292-
# Convert data heights to integer. In some case they are strings.
293-
weather_df.columns = pd.MultiIndex.from_arrays([
294-
weather_df.columns.get_level_values(0),
295-
pd.to_numeric(weather_df.columns.get_level_values(1))])
292+
weather_df = tools.check_weather_data(weather_df)
296293

297294
self.assign_power_curve(weather_df)
298295
self.power_plant.mean_hub_height()

0 commit comments

Comments
 (0)