Skip to content

Commit

Permalink
Convert str to numeric in TurbineClusterModelChain incl. test
Browse files Browse the repository at this point in the history
  • Loading branch information
SabineHaas committed Jan 8, 2020
1 parent c4a5dbd commit 66bbe0c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/test_turbine_cluster_modelchain.py
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
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

0 comments on commit 66bbe0c

Please sign in to comment.