Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions windpowerlib/modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"""
import logging
import pandas as pd
from windpowerlib import (wind_speed, density, temperature, power_output,
tools)
from windpowerlib import wind_speed, density, temperature, power_output, tools


class ModelChain(object):
Expand Down Expand Up @@ -511,10 +510,7 @@ def run_model(self, weather_df):
'wind_speed'

"""
# Convert data heights to integer. In some case they are strings.
weather_df.columns = pd.MultiIndex.from_arrays([
weather_df.columns.get_level_values(0),
pd.to_numeric(weather_df.columns.get_level_values(1))])
weather_df = tools.check_weather_data(weather_df)

wind_speed_hub = self.wind_speed_hub(weather_df)
density_hub = (
Expand Down
28 changes: 28 additions & 0 deletions windpowerlib/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
import numpy as np
import warnings
import pandas as pd


class WindpowerlibUserWarning(UserWarning):
Expand Down Expand Up @@ -221,3 +222,30 @@ def estimate_turbulence_intensity(height, roughness_length):

"""
return 1 / (np.log(height / roughness_length))


def check_weather_data(weather_df):
"""
Check weather Data Frame.

- Raise warning if there are nan values.
- Convert columns if heights are string and not numeric.

"""
# Convert data heights to integer. In some case they are strings.
weather_df.columns = pd.MultiIndex.from_arrays(
[
weather_df.columns.get_level_values(0),
pd.to_numeric(weather_df.columns.get_level_values(1)),
]
)

# check for nan values
if weather_df.isnull().any().any():
nan_columns = list(weather_df.columns[weather_df.isnull().any()])
msg = (
"The following columns of the weather data contain invalid "
"values like 'nan': {0}"
)
warnings.warn(msg.format(nan_columns), WindpowerlibUserWarning)
return weather_df
7 changes: 2 additions & 5 deletions windpowerlib/turbine_cluster_modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import logging
import pandas as pd
from windpowerlib import wake_losses
from windpowerlib.modelchain import ModelChain
from windpowerlib.modelchain import ModelChain, tools


class TurbineClusterModelChain(ModelChain):
Expand Down Expand Up @@ -289,10 +289,7 @@ def run_model(self, weather_df):
'wind_speed'

"""
# Convert data heights to integer. In some case they are strings.
weather_df.columns = pd.MultiIndex.from_arrays([
weather_df.columns.get_level_values(0),
pd.to_numeric(weather_df.columns.get_level_values(1))])
weather_df = tools.check_weather_data(weather_df)

self.assign_power_curve(weather_df)
self.power_plant.mean_hub_height()
Expand Down