Skip to content

Commit 66678d0

Browse files
authored
Merge pull request #93 from wind-python/add_on/to_pr90/data_height_of_type_str_for_turbineclustermodelchain
Add on/to pr90/data height of type str for turbineclustermodelchain
2 parents e20310b + 6ff4368 commit 66678d0

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

example/modelchain_example.ipynb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,6 @@
139139
" weather_df.index = pd.to_datetime(weather_df.index).tz_convert(\n",
140140
" 'Europe/Berlin')\n",
141141
" \n",
142-
" # change type of height from str to int by resetting columns\n",
143-
" l0 = [_[0] for _ in weather_df.columns]\n",
144-
" l1 = [int(_[1]) for _ in weather_df.columns]\n",
145-
" weather_df.columns = [l0, l1]\n",
146-
" \n",
147142
" return weather_df\n",
148143
"\n",
149144
"\n",

example/modelchain_example.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,6 @@ def get_weather_data(filename='weather.csv', **kwargs):
8383
"Europe/Berlin"
8484
)
8585

86-
# change type of height from str to int by resetting columns
87-
l0 = [_[0] for _ in weather_df.columns]
88-
l1 = [int(_[1]) for _ in weather_df.columns]
89-
weather_df.columns = [l0, l1]
90-
9186
return weather_df
9287

9388

tests/test_turbine_cluster_modelchain.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,3 +358,21 @@ def test_tc_modelchain_with_power_curve_as_dict(self):
358358
)
359359
test_tc_mc.run_model(self.weather_df)
360360
assert_series_equal(test_tc_mc.power_output, power_output_exp)
361+
362+
def test_heigths_as_string(self):
363+
"""Test run_model if data heights are of type string."""
364+
365+
# Convert data heights to str
366+
string_weather = self.weather_df.copy()
367+
string_weather.columns = pd.MultiIndex.from_arrays([
368+
string_weather.columns.get_level_values(0),
369+
string_weather.columns.get_level_values(1).astype(str)])
370+
371+
# Heights in the original DataFrame are of type np.int64
372+
assert isinstance(self.weather_df.columns.get_level_values(1)[0],
373+
np.int64)
374+
assert isinstance(string_weather.columns.get_level_values(1)[0], str)
375+
376+
test_mc = tc_mc.TurbineClusterModelChain(
377+
power_plant=wtc.WindTurbineCluster(**self.test_cluster))
378+
test_mc.run_model(string_weather)

windpowerlib/turbine_cluster_modelchain.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
SPDX-License-Identifier: MIT
99
"""
1010
import logging
11+
import pandas as pd
1112
from windpowerlib import wake_losses
1213
from windpowerlib.modelchain import ModelChain
1314

@@ -288,6 +289,10 @@ def run_model(self, weather_df):
288289
'wind_speed'
289290
290291
"""
292+
# Convert data heights to integer. In some case they are strings.
293+
weather_df.columns = pd.MultiIndex.from_arrays([
294+
weather_df.columns.get_level_values(0),
295+
pd.to_numeric(weather_df.columns.get_level_values(1))])
291296

292297
self.assign_power_curve(weather_df)
293298
self.power_plant.mean_hub_height()

0 commit comments

Comments
 (0)