Skip to content

Commit 99c40bf

Browse files
committed
Adapt tests to API changes
1 parent 928c153 commit 99c40bf

File tree

4 files changed

+81
-69
lines changed

4 files changed

+81
-69
lines changed

tests/test_density.py

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,13 @@
1-
from windpowerlib.density import (temperature_gradient,
2-
rho_barometric, rho_ideal_gas)
1+
from windpowerlib.density import barometric, ideal_gas
32
import pandas as pd
43
from pandas.util.testing import assert_series_equal
5-
from numpy.testing import assert_array_equal, assert_allclose
4+
from numpy.testing import assert_allclose
65
import numpy as np
76

87

9-
class TestDensityTemperature:
8+
class TestDensity:
109

11-
def test_temperature_gradient(self):
12-
parameters = {'temperature': pd.Series(data=[267, 268]),
13-
'temperature_height': 2,
14-
'hub_height': 100}
15-
16-
# Test temperature as pd.Series
17-
temp_hub_exp = pd.Series(data=[266.363, 267.36300])
18-
assert_series_equal(temperature_gradient(**parameters), temp_hub_exp)
19-
20-
# Test temperature as np.array
21-
temp_hub_exp = np.array([266.363, 267.36300])
22-
parameters['temperature'] = np.array(parameters['temperature'])
23-
assert_array_equal(temperature_gradient(**parameters), temp_hub_exp)
24-
assert isinstance(temperature_gradient(**parameters), np.ndarray)
25-
26-
def test_rho_barometric(self):
10+
def test_barometric(self):
2711
parameters = {'pressure': pd.Series(data=[101125, 101000]),
2812
'pressure_height': 0,
2913
'hub_height': 100,
@@ -32,25 +16,25 @@ def test_rho_barometric(self):
3216
# Test pressure as pd.Series and temperature_hub_height as pd.Series
3317
# and np.array
3418
rho_exp = pd.Series(data=[1.30305336, 1.29656645])
35-
assert_series_equal(rho_barometric(**parameters), rho_exp)
19+
assert_series_equal(barometric(**parameters), rho_exp)
3620
parameters['temperature_hub_height'] = np.array(
3721
parameters['temperature_hub_height'])
38-
assert_series_equal(rho_barometric(**parameters), rho_exp)
22+
assert_series_equal(barometric(**parameters), rho_exp)
3923

4024
# Test pressure as np.array and temperature_hub_height as pd.Series
4125
parameters['pressure'] = np.array(parameters['pressure'])
4226
parameters['temperature_hub_height'] = pd.Series(
4327
data=parameters['temperature_hub_height'])
44-
assert_series_equal(rho_barometric(**parameters), rho_exp)
28+
assert_series_equal(barometric(**parameters), rho_exp)
4529

4630
# Test pressure as np.array and temperature_hub_height as np.array
4731
rho_exp = np.array([1.30305336, 1.29656645])
4832
parameters['temperature_hub_height'] = np.array(
4933
parameters['temperature_hub_height'])
50-
assert_allclose(rho_barometric(**parameters), rho_exp)
51-
assert isinstance(rho_barometric(**parameters), np.ndarray)
34+
assert_allclose(barometric(**parameters), rho_exp)
35+
assert isinstance(barometric(**parameters), np.ndarray)
5236

53-
def test_rho_ideal_gas(self):
37+
def test_ideal_gas(self):
5438
parameters = {'pressure': pd.Series(data=[101125, 101000]),
5539
'pressure_height': 0,
5640
'hub_height': 100,
@@ -59,20 +43,20 @@ def test_rho_ideal_gas(self):
5943
# Test pressure as pd.Series and temperature_hub_height as pd.Series
6044
# and np.array
6145
rho_exp = pd.Series(data=[1.30309439, 1.29660728])
62-
assert_series_equal(rho_ideal_gas(**parameters), rho_exp)
46+
assert_series_equal(ideal_gas(**parameters), rho_exp)
6347
parameters['temperature_hub_height'] = np.array(
6448
parameters['temperature_hub_height'])
65-
assert_series_equal(rho_ideal_gas(**parameters), rho_exp)
49+
assert_series_equal(ideal_gas(**parameters), rho_exp)
6650

6751
# Test pressure as np.array and temperature_hub_height as pd.Series
6852
parameters['pressure'] = np.array(parameters['pressure'])
6953
parameters['temperature_hub_height'] = pd.Series(
7054
data=parameters['temperature_hub_height'])
71-
assert_allclose(rho_ideal_gas(**parameters), rho_exp)
55+
assert_allclose(ideal_gas(**parameters), rho_exp)
7256

7357
# Test pressure as np.array and temperature_hub_height as np.array
7458
rho_exp = np.array([1.30309439, 1.29660728])
7559
parameters['temperature_hub_height'] = np.array(
7660
parameters['temperature_hub_height'])
77-
assert_allclose(rho_ideal_gas(**parameters), rho_exp)
78-
assert isinstance(rho_ideal_gas(**parameters), np.ndarray)
61+
assert_allclose(ideal_gas(**parameters), rho_exp)
62+
assert isinstance(ideal_gas(**parameters), np.ndarray)

tests/test_power_output.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
from pandas.util.testing import assert_series_equal
2-
from windpowerlib.power_output import (cp_curve, cp_curve_density_corr,
3-
p_curve, p_curve_density_corr)
2+
from windpowerlib.power_output import (power_coefficient_curve,
3+
cp_curve_density_corr,
4+
power_curve, p_curve_density_corr)
45
import pandas as pd
56
import numpy as np
67
from numpy.testing import assert_allclose
78

89

910
class TestPowerOutput:
1011

11-
def test_cp_curve(self):
12+
def test_power_coefficient_curve(self):
1213
parameters = {'wind_speed': pd.Series(data=[2.0, 5.5, 7.0]),
1314
'density': pd.Series(data=[1.3, 1.3, 1.3]),
1415
'rotor_diameter': 80,
@@ -18,18 +19,22 @@ def test_cp_curve(self):
1819
# Test wind_speed as pd.Series with density as pd.Series and np.array
1920
power_output_exp = pd.Series(data=[0.0, 244615.399, 0.0],
2021
name='feedin_wind_turbine')
21-
assert_series_equal(cp_curve(**parameters), power_output_exp)
22+
assert_series_equal(power_coefficient_curve(**parameters),
23+
power_output_exp)
2224
parameters['density'] = np.array(parameters['density'])
23-
assert_series_equal(cp_curve(**parameters), power_output_exp)
25+
assert_series_equal(power_coefficient_curve(**parameters),
26+
power_output_exp)
2427

2528
# Test wind_speed as np.array with density as np.array and pd.Series
2629
power_output_exp = np.array([0.0, 244615.399, 0.0])
2730
parameters['wind_speed'] = np.array(parameters['wind_speed'])
28-
assert_allclose(cp_curve(**parameters), power_output_exp)
29-
assert isinstance(cp_curve(**parameters), np.ndarray)
31+
assert_allclose(power_coefficient_curve(**parameters),
32+
power_output_exp)
33+
assert isinstance(power_coefficient_curve(**parameters), np.ndarray)
3034
parameters['density'] = pd.Series(data=parameters['density'])
31-
assert_allclose(cp_curve(**parameters), power_output_exp)
32-
assert isinstance(cp_curve(**parameters), np.ndarray)
35+
assert_allclose(power_coefficient_curve(**parameters),
36+
power_output_exp)
37+
assert isinstance(power_coefficient_curve(**parameters), np.ndarray)
3338

3439
def test_cp_curve_density_corrected(self):
3540
parameters = {'wind_speed': pd.Series(data=[2.0, 5.5, 7.0]),
@@ -58,21 +63,21 @@ def test_cp_curve_density_corrected(self):
5863
power_output_exp)
5964
assert isinstance(cp_curve_density_corr(**parameters), np.ndarray)
6065

61-
def test_p_curve(self):
66+
def test_power_curve(self):
6267
parameters = {'wind_speed': pd.Series(data=[2.0, 5.5, 7.0]),
6368
'p_values': pd.DataFrame(data={'p': [300, 400, 500]},
6469
index=[4.0, 5.0, 6.0])}
6570

6671
# Test wind_speed as pd.Series
6772
power_output_exp = pd.Series(data=[0.0, 450.0, 0.0],
6873
name='feedin_wind_turbine')
69-
assert_series_equal(p_curve(**parameters), power_output_exp)
74+
assert_series_equal(power_curve(**parameters), power_output_exp)
7075

7176
# Test wind_speed as np.array
7277
power_output_exp = np.array([0.0, 450.0, 0.0])
7378
parameters['wind_speed'] = np.array(parameters['wind_speed'])
74-
assert_allclose(p_curve(**parameters), power_output_exp)
75-
assert isinstance(p_curve(**parameters), np.ndarray)
79+
assert_allclose(power_curve(**parameters), power_output_exp)
80+
assert isinstance(power_curve(**parameters), np.ndarray)
7681

7782
def test_p_curve_density_corrected(self):
7883
parameters = {'wind_speed': pd.Series(data=[2.0, 5.5, 7.0]),

tests/test_temperature.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from windpowerlib.temperature import linear_gradient
2+
import pandas as pd
3+
from pandas.util.testing import assert_series_equal
4+
from numpy.testing import assert_array_equal
5+
import numpy as np
6+
7+
8+
class TestTemperature:
9+
10+
def test_linear_gradient(self):
11+
parameters = {'temperature': pd.Series(data=[267, 268]),
12+
'temperature_height': 2,
13+
'hub_height': 100}
14+
15+
# Test temperature as pd.Series
16+
temp_hub_exp = pd.Series(data=[266.363, 267.36300])
17+
assert_series_equal(linear_gradient(**parameters), temp_hub_exp)
18+
19+
# Test temperature as np.array
20+
temp_hub_exp = np.array([266.363, 267.36300])
21+
parameters['temperature'] = np.array(parameters['temperature'])
22+
assert_array_equal(linear_gradient(**parameters), temp_hub_exp)
23+
assert isinstance(linear_gradient(**parameters), np.ndarray)

tests/test_wind_speed.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from windpowerlib.wind_speed import logarithmic_wind_profile, v_wind_hellman
1+
from windpowerlib.wind_speed import logarithmic_profile, hellman
22
import pandas as pd
33
from pandas.util.testing import assert_series_equal
44
import numpy as np
@@ -8,7 +8,7 @@
88

99
class TestWindSpeed:
1010

11-
def test_logarithmic_wind_profile(self):
11+
def test_logarithmic_profile(self):
1212
parameters = {'wind_speed': pd.Series(data=[5.0, 6.5]),
1313
'wind_speed_height': 10,
1414
'hub_height': 100,
@@ -18,43 +18,43 @@ def test_logarithmic_wind_profile(self):
1818
# Test wind_speed as pd.Series with roughness_length as pd.Series,
1919
# np.array and float
2020
v_wind_hub_exp = pd.Series(data=[7.74136523, 10.0637748])
21-
assert_series_equal(logarithmic_wind_profile(**parameters),
21+
assert_series_equal(logarithmic_profile(**parameters),
2222
v_wind_hub_exp)
2323
parameters['roughness_length'] = np.array(
2424
parameters['roughness_length'])
25-
assert_series_equal(logarithmic_wind_profile(**parameters),
25+
assert_series_equal(logarithmic_profile(**parameters),
2626
v_wind_hub_exp)
2727
parameters['roughness_length'] = parameters['roughness_length'][0]
28-
assert_series_equal(logarithmic_wind_profile(**parameters),
28+
assert_series_equal(logarithmic_profile(**parameters),
2929
v_wind_hub_exp)
3030

3131
# Test wind_speed as np.array with roughness_length as float, pd.Series
3232
# and np.array
3333
v_wind_hub_exp = np.array([7.74136523, 10.0637748])
3434
parameters['wind_speed'] = np.array(parameters['wind_speed'])
35-
assert_allclose(logarithmic_wind_profile(**parameters), v_wind_hub_exp)
36-
assert isinstance(logarithmic_wind_profile(**parameters), np.ndarray)
35+
assert_allclose(logarithmic_profile(**parameters), v_wind_hub_exp)
36+
assert isinstance(logarithmic_profile(**parameters), np.ndarray)
3737
parameters['roughness_length'] = pd.Series(
3838
data=[parameters['roughness_length'],
3939
parameters['roughness_length']])
40-
assert_allclose(logarithmic_wind_profile(**parameters), v_wind_hub_exp)
41-
assert isinstance(logarithmic_wind_profile(**parameters), np.ndarray)
40+
assert_allclose(logarithmic_profile(**parameters), v_wind_hub_exp)
41+
assert isinstance(logarithmic_profile(**parameters), np.ndarray)
4242
parameters['roughness_length'] = np.array(
4343
parameters['roughness_length'])
44-
assert_allclose(logarithmic_wind_profile(**parameters), v_wind_hub_exp)
45-
assert isinstance(logarithmic_wind_profile(**parameters), np.ndarray)
44+
assert_allclose(logarithmic_profile(**parameters), v_wind_hub_exp)
45+
assert isinstance(logarithmic_profile(**parameters), np.ndarray)
4646

4747
# Test obstacle_height is not zero
4848
v_wind_hub_exp = np.array([13.54925281, 17.61402865])
4949
parameters['obstacle_height'] = 12
50-
assert_allclose(logarithmic_wind_profile(**parameters), v_wind_hub_exp)
50+
assert_allclose(logarithmic_profile(**parameters), v_wind_hub_exp)
5151

5252
# Raise ValueError due to 0.7 * `obstacle_height` > `wind_speed_height`
5353
with pytest.raises(ValueError):
5454
parameters['obstacle_height'] = 20
55-
logarithmic_wind_profile(**parameters)
55+
logarithmic_profile(**parameters)
5656

57-
def test_v_wind_hellman(self):
57+
def test_hellman(self):
5858
parameters = {'wind_speed': pd.Series(data=[5.0, 6.5]),
5959
'wind_speed_height': 10,
6060
'hub_height': 100,
@@ -64,37 +64,37 @@ def test_v_wind_hellman(self):
6464
# Test wind_speed is pd.Series with roughness_length is pd.Series,
6565
# np.array and float
6666
v_wind_hub_exp = pd.Series(data=[7.12462437, 9.26201168])
67-
assert_series_equal(v_wind_hellman(**parameters), v_wind_hub_exp)
67+
assert_series_equal(hellman(**parameters), v_wind_hub_exp)
6868
parameters['roughness_length'] = np.array(
6969
parameters['roughness_length'])
70-
assert_series_equal(v_wind_hellman(**parameters), v_wind_hub_exp)
70+
assert_series_equal(hellman(**parameters), v_wind_hub_exp)
7171
parameters['roughness_length'] = parameters['roughness_length'][0]
72-
assert_series_equal(v_wind_hellman(**parameters), v_wind_hub_exp)
72+
assert_series_equal(hellman(**parameters), v_wind_hub_exp)
7373

7474
# Test wind_speed as np.array with roughness_length is float, pd.Series
7575
# and np.array
7676
v_wind_hub_exp = np.array([7.12462437, 9.26201168])
7777
parameters['wind_speed'] = np.array(parameters['wind_speed'])
78-
assert_allclose(v_wind_hellman(**parameters), v_wind_hub_exp)
79-
assert isinstance(v_wind_hellman(**parameters), np.ndarray)
78+
assert_allclose(hellman(**parameters), v_wind_hub_exp)
79+
assert isinstance(hellman(**parameters), np.ndarray)
8080
parameters['roughness_length'] = pd.Series(
8181
data=(parameters['roughness_length'],
8282
parameters['roughness_length']))
83-
assert_allclose(v_wind_hellman(**parameters), v_wind_hub_exp)
84-
assert isinstance(v_wind_hellman(**parameters), np.ndarray)
83+
assert_allclose(hellman(**parameters), v_wind_hub_exp)
84+
assert isinstance(hellman(**parameters), np.ndarray)
8585
parameters['roughness_length'] = np.array(
8686
parameters['roughness_length'])
87-
assert_allclose(v_wind_hellman(**parameters), v_wind_hub_exp)
88-
assert isinstance(v_wind_hellman(**parameters), np.ndarray)
87+
assert_allclose(hellman(**parameters), v_wind_hub_exp)
88+
assert isinstance(hellman(**parameters), np.ndarray)
8989

9090
# Test roughness_length is None and hellman_exponent is None
9191
v_wind_hub_exp = pd.Series(data=[6.9474774, 9.03172])
9292
parameters['wind_speed'] = pd.Series(data=parameters['wind_speed'])
9393
parameters['roughness_length'] = None
94-
assert_series_equal(v_wind_hellman(**parameters), v_wind_hub_exp)
94+
assert_series_equal(hellman(**parameters), v_wind_hub_exp)
9595

9696
# Test hellman_exponent is not None
9797
v_wind_hub_exp = pd.Series(data=[7.92446596, 10.30180575])
9898
parameters['roughness_length'] = 0.15
9999
parameters['hellman_exponent'] = 0.2
100-
assert_series_equal(v_wind_hellman(**parameters), v_wind_hub_exp)
100+
assert_series_equal(hellman(**parameters), v_wind_hub_exp)

0 commit comments

Comments
 (0)