diff --git a/example/modelchain_example.ipynb b/example/modelchain_example.ipynb index 14714a2f..f4b1f748 100644 --- a/example/modelchain_example.ipynb +++ b/example/modelchain_example.ipynb @@ -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", diff --git a/example/modelchain_example.py b/example/modelchain_example.py index c4686e61..acf85b8e 100644 --- a/example/modelchain_example.py +++ b/example/modelchain_example.py @@ -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 diff --git a/tests/test_turbine_cluster_modelchain.py b/tests/test_turbine_cluster_modelchain.py index 2b20e151..8a827978 100644 --- a/tests/test_turbine_cluster_modelchain.py +++ b/tests/test_turbine_cluster_modelchain.py @@ -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) diff --git a/windpowerlib/turbine_cluster_modelchain.py b/windpowerlib/turbine_cluster_modelchain.py index 5e0eeba1..a72ae52a 100644 --- a/windpowerlib/turbine_cluster_modelchain.py +++ b/windpowerlib/turbine_cluster_modelchain.py @@ -8,6 +8,7 @@ SPDX-License-Identifier: MIT """ import logging +import pandas as pd from windpowerlib import wake_losses from windpowerlib.modelchain import ModelChain @@ -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()