Skip to content

Commit

Permalink
Merge pull request #93 from wind-python/add_on/to_pr90/data_height_of…
Browse files Browse the repository at this point in the history
…_type_str_for_turbineclustermodelchain

Add on/to pr90/data height of type str for turbineclustermodelchain
  • Loading branch information
SabineHaas committed Jan 8, 2020
2 parents e20310b + 6ff4368 commit 66678d0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
5 changes: 0 additions & 5 deletions example/modelchain_example.ipynb
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
Expand Up @@ -83,11 +83,6 @@ def get_weather_data(filename='weather.csv', **kwargs):
"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
Expand Up @@ -358,3 +358,21 @@ def test_tc_modelchain_with_power_curve_as_dict(self):
)
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
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 @@ -288,6 +289,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

0 comments on commit 66678d0

Please sign in to comment.