Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions RELEASE_NOTES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ Upcoming Release

**Bug fixes**

* Fix ``get_oedb_windturbineconfig`` applying the documented ``turbine_type``
search parameter to the value of ``name``. Searching by ``turbine_type``
alone raised ``KeyError: 'name'``, and combining it with ``name`` silently
ignored the requested turbine type.

* Fix ``Cutout.line_rating`` passing line azimuth in radians while
``convert_line_rating`` interpreted ``psi`` as degrees. Azimuths are now
computed in degrees, matching the documented unit.
Expand Down
4 changes: 3 additions & 1 deletion atlite/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,9 @@ def get_oedb_windturbineconfig(
if "name" in search_params:
selector &= df.name.str.contains(search_params["name"], case=False)
if "turbine_type" in search_params:
selector &= df.turbine_type.str.contains(search_params["name"], case=False)
selector &= df.turbine_type.str.contains(
search_params["turbine_type"], case=False
)
if "manufacturer" in search_params:
selector &= df.manufacturer.str.contains(
search_params["manufacturer"], case=False
Expand Down
43 changes: 43 additions & 0 deletions test/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,54 @@
@author: fabian
"""

import json

import pandas as pd
import pytest

from atlite import resource
from atlite.resource import get_oedb_windturbineconfig, get_windturbineconfig


@pytest.fixture
def oedb_turbines(monkeypatch):
"""Two-row stand-in for the OEDB library, with 'name' != 'turbine_type'.

In the live OEDB wind turbine library the two columns hold different
strings for most entries, so a filter has to be applied to the column it
names. Patching the module-level cache keeps the test offline.
"""
df = pd.DataFrame({
"id": [0, 1],
"manufacturer": ["Enercon", "Nordex"],
"name": ["E-101/3500 E2", "Gamma Series"],
"turbine_type": ["E-101/3500", "N131/3600"],
"has_power_curve": [True, True],
"power_curve_wind_speeds": [json.dumps([0.0, 25.0])] * 2,
"power_curve_values": [json.dumps([0.0, 3500.0]), json.dumps([0.0, 3600.0])],
"hub_height": [149.0, 134.0],
"source": ["test", "test"],
})
monkeypatch.setattr(resource, "_oedb_turbines", df)


def test_oedb_windturbineconfig_turbine_type_alone(oedb_turbines):
# 'turbine_type' is a documented search parameter and has to work on its own.
assert get_oedb_windturbineconfig(turbine_type="N131/3600")["name"] == "N131/3600"


def test_oedb_windturbineconfig_turbine_type_narrows(oedb_turbines):
# A 'turbine_type' matching no turbine must narrow the result to nothing,
# even when a 'name' that does match is given alongside it.
with pytest.raises(RuntimeError, match="No turbine found"):
get_oedb_windturbineconfig(name="E-101/3500", turbine_type="N131/3600")


def test_oedb_windturbineconfig_manufacturer_search(oedb_turbines):
# Control: the neighbouring search parameters keep working.
assert get_oedb_windturbineconfig(manufacturer="Nordex")["name"] == "N131/3600"


def test_oedb_windturbineconfig():
# test int search
assert get_oedb_windturbineconfig(1)
Expand Down