Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 0 additions & 5 deletions example/modelchain_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,6 @@
" weather_df.index = pd.to_datetime(weather_df.index).tz_convert(\n",
" 'Europe/Berlin')\n",
" \n",
" # change type of height from str to int by resetting columns\n",
" l0 = [_[0] for _ in weather_df.columns]\n",
" l1 = [int(_[1]) for _ in weather_df.columns]\n",
" weather_df.columns = [l0, l1]\n",
" \n",
" return weather_df\n",
"\n",
"\n",
Expand Down
5 changes: 0 additions & 5 deletions example/modelchain_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ def get_weather_data(filename='weather.csv', **kwargs):
weather_df.index = pd.to_datetime(weather_df.index).tz_convert(
'Europe/Berlin')

# change type of height from str to int by resetting columns
l0 = [_[0] for _ in weather_df.columns]
l1 = [int(_[1]) for _ in weather_df.columns]
weather_df.columns = [l0, l1]

return weather_df


Expand Down
18 changes: 18 additions & 0 deletions tests/test_turbine_cluster_modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,21 @@ def test_tc_modelchain_with_power_curve_as_dict(self):
power_plant=wtc.WindTurbineCluster(**my_cluster))
test_tc_mc.run_model(self.weather_df)
assert_series_equal(test_tc_mc.power_output, power_output_exp)

def test_heigths_as_string(self):
"""Test run_model if data heights are of type string."""

# Convert data heights to str
string_weather = self.weather_df.copy()
string_weather.columns = pd.MultiIndex.from_arrays([
string_weather.columns.get_level_values(0),
string_weather.columns.get_level_values(1).astype(str)])

# Heights in the original DataFrame are of type np.int64
assert isinstance(self.weather_df.columns.get_level_values(1)[0],
np.int64)
assert isinstance(string_weather.columns.get_level_values(1)[0], str)

test_mc = tc_mc.TurbineClusterModelChain(
power_plant=wtc.WindTurbineCluster(**self.test_cluster))
test_mc.run_model(string_weather)
5 changes: 5 additions & 0 deletions windpowerlib/turbine_cluster_modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
SPDX-License-Identifier: MIT
"""
import logging
import pandas as pd
from windpowerlib import wake_losses
from windpowerlib.modelchain import ModelChain

Expand Down Expand Up @@ -266,6 +267,10 @@ 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))])

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