Skip to content
6 changes: 3 additions & 3 deletions .github/workflows/tests-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ jobs:

steps:
- name: Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v7

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}

- name: Set up Conda
if: runner.os == 'Windows'
uses: conda-incubator/setup-miniconda@v2
uses: conda-incubator/setup-miniconda@v4
with:
miniconda-version: "latest"
python-version: ${{ matrix.python-version }}
Expand Down
3 changes: 2 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[pytest]
addopts = --doctest-modules
addopts = --doctest-modules
testpaths = tests windpowerlib
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def read(fname):
"nbsphinx",
"numpy",
"pytest",
"pytest-notebook",
"sphinx >= 1.4",
"sphinx_rtd_theme",
]
Expand Down
4 changes: 2 additions & 2 deletions tests/test_data_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_store_turbine_data_from_oedb(self, caplog):
for fn in os.listdir(self.orig_path):
t[fn] = os.path.getmtime(os.path.join(self.orig_path, fn))
with caplog.at_level(logging.WARNING):
store_turbine_data_from_oedb()
store_turbine_data_from_oedb(threshold=1.0)
for fn in os.listdir(self.orig_path):
assert t[fn] < os.path.getmtime(os.path.join(self.orig_path, fn))
assert "The turbine library data contains too many faulty" not in caplog.text
Expand Down Expand Up @@ -151,7 +151,7 @@ def test_wrong_url_load_turbine_data(self):
ConnectionError,
match=r"Database \(oep\) connection not successful*",
):
store_turbine_data_from_oedb("wrong_schema")
store_turbine_data_from_oedb(table="wrong_table")

@pytest.mark.skip(reason="Use it to check a persistent ssl error")
def test_wrong_ssl_connection(self):
Expand Down
11 changes: 11 additions & 0 deletions tests/test_modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ def setup_class(cls):
],
)

def test_get_closest_height(self):
"""Test the _get_closest_height helper method."""
test_mc = mc.ModelChain(wt.WindTurbine(**self.test_turbine))
# Hub height is 100, so 110 is the closest height
heights = np.array([10, 80, 110, 150])
assert test_mc._get_closest_height(heights) == 110

# Test when there is an exact match
heights = np.array([10, 100, 150])
assert test_mc._get_closest_height(heights) == 100

def test_temperature_hub(self):
# Test modelchain with temperature_model='linear_gradient'
test_mc = mc.ModelChain(wt.WindTurbine(**self.test_turbine))
Expand Down
2 changes: 1 addition & 1 deletion windpowerlib/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def fetch_turbine_data_from_oedb(

"""
# url of OpenEnergy Platform that contains the oedb
oep_url = "https://oep.iks.cs.ovgu.de/"
oep_url = "https://openenergyplatform.org/"
url = oep_url + "/api/v0/schema/{}/tables/{}/rows/?".format(schema, table)

# load data
Expand Down
72 changes: 25 additions & 47 deletions windpowerlib/modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
)


class ModelChain(object):
class ModelChain:
r"""Model to determine the output of a wind turbine

The ModelChain class provides a standardized, high-level
Expand Down Expand Up @@ -163,6 +163,14 @@ def __init__(
self.hellman_exp = hellman_exp
self.power_output = None

def _get_closest_height(self, heights):
return heights[
min(
range(len(heights)),
key=lambda i: abs(heights[i] - self.power_plant.hub_height),
)
]

def temperature_hub(self, weather_df):
r"""
Calculates the temperature of air at hub height.
Expand Down Expand Up @@ -200,15 +208,9 @@ def temperature_hub(self, weather_df):
logging.debug(
"Calculating temperature using temperature " "gradient."
)
closest_height = weather_df["temperature"].columns[
min(
range(len(weather_df["temperature"].columns)),
key=lambda i: abs(
weather_df["temperature"].columns[i]
- self.power_plant.hub_height
),
)
]
closest_height = self._get_closest_height(
weather_df["temperature"].columns
)
temperature_hub = temperature.linear_gradient(
weather_df["temperature"][closest_height],
closest_height,
Expand Down Expand Up @@ -273,15 +275,9 @@ def density_hub(self, weather_df):
logging.debug(
"Calculating density using barometric height " "equation."
)
closest_height = weather_df["pressure"].columns[
min(
range(len(weather_df["pressure"].columns)),
key=lambda i: abs(
weather_df["pressure"].columns[i]
- self.power_plant.hub_height
),
)
]
closest_height = self._get_closest_height(
weather_df["pressure"].columns
)
density_hub = density.barometric(
weather_df["pressure"][closest_height],
closest_height,
Expand All @@ -290,15 +286,9 @@ def density_hub(self, weather_df):
)
elif self.density_model == "ideal_gas":
logging.debug("Calculating density using ideal gas equation.")
closest_height = weather_df["pressure"].columns[
min(
range(len(weather_df["pressure"].columns)),
key=lambda i: abs(
weather_df["pressure"].columns[i]
- self.power_plant.hub_height
),
)
]
closest_height = self._get_closest_height(
weather_df["pressure"].columns
)
density_hub = density.ideal_gas(
weather_df["pressure"][closest_height],
closest_height,
Expand Down Expand Up @@ -358,15 +348,9 @@ def wind_speed_hub(self, weather_df):
logging.debug(
"Calculating wind speed using logarithmic wind " "profile."
)
closest_height = weather_df["wind_speed"].columns[
min(
range(len(weather_df["wind_speed"].columns)),
key=lambda i: abs(
weather_df["wind_speed"].columns[i]
- self.power_plant.hub_height
),
)
]
closest_height = self._get_closest_height(
weather_df["wind_speed"].columns
)
wind_speed_hub = wind_speed.logarithmic_profile(
weather_df["wind_speed"][closest_height],
closest_height,
Expand All @@ -376,15 +360,9 @@ def wind_speed_hub(self, weather_df):
)
elif self.wind_speed_model == "hellman":
logging.debug("Calculating wind speed using hellman equation.")
closest_height = weather_df["wind_speed"].columns[
min(
range(len(weather_df["wind_speed"].columns)),
key=lambda i: abs(
weather_df["wind_speed"].columns[i]
- self.power_plant.hub_height
),
)
]
closest_height = self._get_closest_height(
weather_df["wind_speed"].columns
)
wind_speed_hub = wind_speed.hellman(
weather_df["wind_speed"][closest_height],
closest_height,
Expand Down Expand Up @@ -503,7 +481,7 @@ def run_model(self, weather_df):
>>> my_weather_df = pd.DataFrame(np.random.rand(2,6),
... index=pd.date_range('1/1/2012',
... periods=2,
... freq='H'),
... freq='h'),
... columns=[np.array(['wind_speed',
... 'wind_speed',
... 'temperature',
Expand Down
4 changes: 2 additions & 2 deletions windpowerlib/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ def linear_interpolation_extrapolation(df, target_height):
... wind_speed_80m)),
... index=pd.date_range('1/1/2012',
... periods=2,
... freq='H'),
... freq='h'),
... columns=[np.array(['wind_speed',
... 'wind_speed']),
... np.array([10, 80])])
>>> value=linear_interpolation_extrapolation(
... weather_df['wind_speed'], 100)[0]
... weather_df['wind_speed'], 100).iloc[0]

"""
# find closest heights
Expand Down
2 changes: 1 addition & 1 deletion windpowerlib/turbine_cluster_modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def run_model(self, weather_df):
>>> my_weather_df = pd.DataFrame(np.random.rand(2,6),
... index=pd.date_range('1/1/2012',
... periods=2,
... freq='H'),
... freq='h'),
... columns=[np.array(['wind_speed',
... 'wind_speed',
... 'temperature',
Expand Down
2 changes: 1 addition & 1 deletion windpowerlib/wind_farm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import warnings


class WindFarm(object):
class WindFarm:
r"""
Defines a standard set of wind farm attributes.

Expand Down
2 changes: 1 addition & 1 deletion windpowerlib/wind_turbine.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from typing import NamedTuple


class WindTurbine(object):
class WindTurbine:
r"""
Defines a standard set of wind turbine attributes.

Expand Down
2 changes: 1 addition & 1 deletion windpowerlib/wind_turbine_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import pandas as pd


class WindTurbineCluster(object):
class WindTurbineCluster:
r"""
Defines a standard set of wind turbine cluster attributes.

Expand Down