Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions tests/test_modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,26 @@ def test_modelchain_with_power_coefficient_curve_as_dict(self):
power_output_model='power_coefficient_curve')
test_mc.run_model(self.weather_df)
assert_series_equal(test_mc.power_output, power_output_exp)

def test_heigths_as_string(self):
"""Test run_model if data heights are of type string."""
test_turbine = {'hub_height': 100,
'rotor_diameter': 80,
'turbine_type': 'E-126/4200'}

# 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_modelchain = {'power_output_model': 'power_curve',
'density_corr': True}
test_mc = mc.ModelChain(wt.WindTurbine(**test_turbine),
**test_modelchain)
test_mc.run_model(string_weather)
6 changes: 6 additions & 0 deletions windpowerlib/modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
SPDX-License-Identifier: MIT
"""
import logging
import pandas as pd
from windpowerlib import (wind_speed, density, temperature, power_output,
tools)

Expand Down Expand Up @@ -438,6 +439,11 @@ 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),
weather_df.columns.get_level_values(1).astype(int)])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why int and not float type? In the provided example the values are integers but that shouldn't be a rule, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion the inaccuracy of the model is higher than the decimal digit. Therefore I would always prefer integer.

But at them moment floats are allowed and it might be easier to allow floats than to forbid them and to explain why.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe putting in a try statement and re-raising the error? In case someone passes in 80 m that cannot be converted to a number?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me the error message is quite clear. It also indicates the exact value that causes the problem. For us it would be more difficult to indicate the problematic value. We could add something like "The heights should be convertible to numeric." but it in my opinion the original message is better. We could also check the array and show all problematic values but I think it is not worth it.


wind_speed_hub = self.wind_speed_hub(weather_df)
density_hub = (None if (self.power_output_model == 'power_curve' and
self.density_correction is False)
Expand Down