Skip to content

Commit be439d2

Browse files
committed
Merge dev into new_data_structure_with_check
2 parents 0d9e027 + af19aca commit be439d2

File tree

5 files changed

+57
-25
lines changed

5 files changed

+57
-25
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ you have basic knowledge of pandas it is easy to use any kind of data file.
151151
),
152152
}
153153
154-
my_turbine = WindTurbine(**my_turbine2)
154+
my_turbine = WindTurbine(**my_turbine_data)
155155
156156
See the `modelchain_example` for more information.
157157

tests/test_power_output.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
SPDX-FileCopyrightText: 2019 oemof developer group <[email protected]>
33
SPDX-License-Identifier: MIT
44
"""
5+
from typing import Dict
56

6-
import pandas as pd
77
import numpy as np
8+
import pandas as pd
89
import pytest
910
from numpy.testing import assert_allclose
1011
from pandas.util.testing import assert_series_equal
11-
1212
from windpowerlib.power_output import (
1313
power_coefficient_curve,
1414
power_curve,
@@ -17,27 +17,31 @@
1717

1818

1919
class TestPowerOutput:
20-
def test_power_coefficient_curve(self):
21-
parameters = {
20+
def setup_class(self):
21+
self.parameters: Dict = {
2222
"wind_speed": pd.Series(data=[2.0, 5.5, 7.0]),
2323
"density": pd.Series(data=[1.3, 1.3, 1.3]),
2424
"rotor_diameter": 80,
2525
"power_coefficient_curve_wind_speeds": pd.Series([4.0, 5.0, 6.0]),
2626
"power_coefficient_curve_values": pd.Series([0.3, 0.4, 0.5]),
2727
}
2828

29+
def test_power_coefficient_curve_1(self):
2930
# Test wind_speed as pd.Series with density and power_coefficient_curve
3031
# as pd.Series and np.array
3132
power_output_exp = pd.Series(
3233
data=[0.0, 244615.399, 0.0], name="feedin_power_plant"
3334
)
3435
assert_series_equal(
35-
power_coefficient_curve(**parameters), power_output_exp
36+
power_coefficient_curve(**self.parameters), power_output_exp
3637
)
37-
parameters["density"] = np.array(parameters["density"])
38+
39+
parameters = self.parameters
40+
parameters["density"].to_numpy()
3841
assert_series_equal(
3942
power_coefficient_curve(**parameters), power_output_exp
4043
)
44+
4145
parameters["power_coefficient_curve_values"] = np.array(
4246
parameters["power_coefficient_curve_values"]
4347
)
@@ -47,14 +51,22 @@ def test_power_coefficient_curve(self):
4751
assert_series_equal(
4852
power_coefficient_curve(**parameters), power_output_exp
4953
)
54+
55+
def test_power_coefficient_curve_output_types(self):
56+
parameters = self.parameters
5057
# Test wind_speed as np.array with density and power_coefficient_curve
5158
# as np.array and pd.Series
59+
assert isinstance(power_coefficient_curve(**parameters), pd.Series)
60+
parameters["wind_speed"] = np.array(parameters["wind_speed"])
61+
assert isinstance(power_coefficient_curve(**parameters), np.ndarray)
62+
63+
def test_power_coefficient_curve_2(self):
64+
parameters = self.parameters
5265
power_output_exp = np.array([0.0, 244615.399, 0.0])
5366
parameters["wind_speed"] = np.array(parameters["wind_speed"])
5467
assert_allclose(
5568
power_coefficient_curve(**parameters), power_output_exp
5669
)
57-
assert isinstance(power_coefficient_curve(**parameters), np.ndarray)
5870
parameters["density"] = pd.Series(data=parameters["density"])
5971
assert_allclose(
6072
power_coefficient_curve(**parameters), power_output_exp

tests/test_wind_turbine.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,23 @@ def test_get_turbine_data_from_file(self):
3838
with pytest.raises(FileNotFoundError):
3939
get_turbine_data_from_file(turbine_type="...", path="not_existent")
4040

41+
def test_get_turbine_types(self, capsys):
42+
get_turbine_types()
43+
captured = capsys.readouterr()
44+
assert "Enercon" in captured.out
45+
get_turbine_types("oedb", print_out=False, filter_=False)
46+
msg = "`turbine_library` is 'wrong' but must be 'local' or 'oedb'."
47+
with pytest.raises(ValueError, match=msg):
48+
get_turbine_types("wrong")
49+
50+
def test_wrong_url_load_turbine_data(self):
51+
"""Load turbine data from oedb."""
52+
53+
with pytest.raises(
54+
ConnectionError, match="Database connection not successful"
55+
):
56+
load_turbine_data_from_oedb("wrong_schema")
57+
4158
@pytest.mark.filterwarnings("ignore:The WindTurbine")
4259
def test_string_representation_of_wind_turbine(self):
4360
assert "Wind turbine: ['hub height=120 m'" in repr(WindTurbine(120))

windpowerlib/power_output.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,8 @@ def power_curve_density_correction(
176176
):
177177
r"""
178178
Calculates the turbine power output using a density corrected power curve.
179-
180179
This function is carried out when the parameter `density_correction` of an
181180
instance of the :class:`~.modelchain.ModelChain` class is True.
182-
183181
Parameters
184182
----------
185183
wind_speed : :pandas:`pandas.Series<series>` or numpy.array
@@ -192,41 +190,33 @@ def power_curve_density_correction(
192190
`power_curve_wind_speeds`.
193191
density : :pandas:`pandas.Series<series>` or numpy.array
194192
Density of air at hub height in kg/m³.
195-
196193
Returns
197194
-------
198195
:pandas:`pandas.Series<series>` or numpy.array
199196
Electrical power output of the wind turbine in W.
200197
Data type depends on type of `wind_speed`.
201-
202198
Notes
203199
-----
204200
The following equation is used for the site specific power curve wind
205201
speeds [1]_ [2]_ [3]_:
206-
207202
.. math:: v_{site}=v_{std}\cdot\left(\frac{\rho_0}
208203
{\rho_{site}}\right)^{p(v)}
209-
210204
with:
211205
.. math:: p=\begin{cases}
212206
\frac{1}{3} & v_{std} \leq 7.5\text{ m/s}\\
213207
\frac{1}{15}\cdot v_{std}-\frac{1}{6} & 7.5
214208
\text{ m/s}<v_{std}<12.5\text{ m/s}\\
215209
\frac{2}{3} & \geq 12.5 \text{ m/s}
216210
\end{cases},
217-
218211
v: wind speed [m/s], :math:`\rho`: density [kg/m³]
219-
220212
:math:`v_{std}` is the standard wind speed in the power curve
221213
(:math:`v_{std}`, :math:`P_{std}`),
222214
:math:`v_{site}` is the density corrected wind speed for the power curve
223215
(:math:`v_{site}`, :math:`P_{std}`),
224216
:math:`\rho_0` is the ambient density (1.225 kg/m³)
225217
and :math:`\rho_{site}` the density at site conditions (and hub height).
226-
227218
It is assumed that the power output for wind speeds above the maximum
228219
and below the minimum wind speed given in the power curve is zero.
229-
230220
References
231221
----------
232222
.. [1] Svenningsen, L.: "Power Curve Air Density Correction And Other
@@ -238,14 +228,25 @@ def power_curve_density_correction(
238228
Variable Scale Simulation Model for Windpower based on the
239229
Georeferenced Installation Register of Germany". Master's Thesis
240230
at Reiner Lemoine Institute, 2014, p. 13
241-
242231
"""
243232
if density is None:
244233
raise TypeError(
245234
"`density` is None. For the calculation with a "
246235
+ "density corrected power curve density at hub "
247236
+ "height is needed."
248237
)
238+
239+
# Convert pd.Series to a numpy array to speed up the interpolation below.
240+
if isinstance(wind_speed, pd.Series):
241+
# save the indexes for later conversion to pd.Series
242+
wind_speed_indexes = wind_speed.index
243+
# change the wind speed Series to numpy array
244+
wind_speed = wind_speed.values
245+
# Set the panda series flag True
246+
panda_series = True
247+
else:
248+
panda_series = False
249+
249250
power_output = [
250251
(
251252
np.interp(
@@ -265,11 +266,11 @@ def power_curve_density_correction(
265266
for i in range(len(wind_speed))
266267
]
267268

268-
# Power_output as pd.Series if wind_speed is pd.Series (else: np.array)
269-
if isinstance(wind_speed, pd.Series):
269+
# Convert results to the data type of the input data
270+
if panda_series:
270271
power_output = pd.Series(
271272
data=power_output,
272-
index=wind_speed.index,
273+
index=wind_speed_indexes, # Use previously saved wind speed index
273274
name="feedin_power_plant",
274275
)
275276
else:

windpowerlib/wind_turbine.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,9 @@ def get_turbine_data_from_file(turbine_type, path):
351351
r"""
352352
Fetches turbine data from a csv file.
353353
354-
Make sure to provide wind speeds in m/s and power in W or
354+
See `example_power_curves.csv', `example_power_coefficient_curves.csv` and
355+
`example_turbine_data.csv` in example/data for the required format of
356+
a csv file. Make sure to provide wind speeds in m/s and power in W or
355357
convert units after loading the data.
356358
357359
Parameters
@@ -375,9 +377,9 @@ def get_turbine_data_from_file(turbine_type, path):
375377
--------
376378
>>> from windpowerlib import wind_turbine
377379
>>> import os
378-
>>> path=os.path.join(os.path.dirname(__file__), '../tests/data',
380+
>>> my_path = os.path.join(os.path.dirname(__file__), '../tests/data',
379381
... 'power_curves.csv')
380-
>>> d3=get_turbine_data_from_file('DUMMY 3', path)
382+
>>> d3 = get_turbine_data_from_file('DUMMY 3', my_path)
381383
>>> print(d3['value'][7])
382384
18000.0
383385
>>> print(d3['value'].max())

0 commit comments

Comments
 (0)