Skip to content

Commit c4a5dbd

Browse files
authored
Merge pull request #90 from wind-python/features/allow-data-heigts-of-type-string
Features/allow data heigts of type string
2 parents a338694 + 0fb61e7 commit c4a5dbd

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

tests/test_modelchain.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,26 @@ def test_modelchain_with_power_coefficient_curve_as_dict(self):
341341
power_output_model='power_coefficient_curve')
342342
test_mc.run_model(self.weather_df)
343343
assert_series_equal(test_mc.power_output, power_output_exp)
344+
345+
def test_heigths_as_string(self):
346+
"""Test run_model if data heights are of type string."""
347+
test_turbine = {'hub_height': 100,
348+
'rotor_diameter': 80,
349+
'turbine_type': 'E-126/4200'}
350+
351+
# Convert data heights to str
352+
string_weather = self.weather_df.copy()
353+
string_weather.columns = pd.MultiIndex.from_arrays([
354+
string_weather.columns.get_level_values(0),
355+
string_weather.columns.get_level_values(1).astype(str)])
356+
357+
# Heights in the original DataFrame are of type np.int64
358+
assert isinstance(self.weather_df.columns.get_level_values(1)[0],
359+
np.int64)
360+
assert isinstance(string_weather.columns.get_level_values(1)[0], str)
361+
362+
test_modelchain = {'power_output_model': 'power_curve',
363+
'density_corr': True}
364+
test_mc = mc.ModelChain(wt.WindTurbine(**test_turbine),
365+
**test_modelchain)
366+
test_mc.run_model(string_weather)

windpowerlib/modelchain.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
SPDX-License-Identifier: MIT
88
"""
99
import logging
10+
import pandas as pd
1011
from windpowerlib import (wind_speed, density, temperature, power_output,
1112
tools)
1213

@@ -438,6 +439,11 @@ def run_model(self, weather_df):
438439
'wind_speed'
439440
440441
"""
442+
# Convert data heights to integer. In some case they are strings.
443+
weather_df.columns = pd.MultiIndex.from_arrays([
444+
weather_df.columns.get_level_values(0),
445+
pd.to_numeric(weather_df.columns.get_level_values(1))])
446+
441447
wind_speed_hub = self.wind_speed_hub(weather_df)
442448
density_hub = (None if (self.power_output_model == 'power_curve' and
443449
self.density_correction is False)

0 commit comments

Comments
 (0)