|
1 | 1 | 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 | + power_curve, _p_curve_density_corr) |
4 | 4 | import pandas as pd |
5 | 5 | import numpy as np |
6 | 6 | from numpy.testing import assert_allclose |
| 7 | +import pytest |
7 | 8 |
|
8 | 9 |
|
9 | 10 | class TestPowerOutput: |
10 | 11 |
|
11 | | - def test_cp_curve(self): |
| 12 | + def test_power_coefficient_curve(self): |
12 | 13 | parameters = {'wind_speed': pd.Series(data=[2.0, 5.5, 7.0]), |
13 | 14 | 'density': pd.Series(data=[1.3, 1.3, 1.3]), |
14 | 15 | 'rotor_diameter': 80, |
15 | | - 'cp_values': pd.DataFrame(data={'cp': [0.3, 0.4, 0.5]}, |
16 | | - index=[4.0, 5.0, 6.0])} |
| 16 | + 'cp_values': pd.Series([0.3, 0.4, 0.5], |
| 17 | + index=[4.0, 5.0, 6.0])} |
17 | 18 |
|
| 19 | + # Tests without density correction: |
18 | 20 | # Test wind_speed as pd.Series with density as pd.Series and np.array |
19 | 21 | power_output_exp = pd.Series(data=[0.0, 244615.399, 0.0], |
20 | 22 | name='feedin_wind_turbine') |
21 | | - assert_series_equal(cp_curve(**parameters), power_output_exp) |
| 23 | + assert_series_equal(power_coefficient_curve(**parameters), |
| 24 | + power_output_exp) |
22 | 25 | parameters['density'] = np.array(parameters['density']) |
23 | | - assert_series_equal(cp_curve(**parameters), power_output_exp) |
24 | | - |
| 26 | + assert_series_equal(power_coefficient_curve(**parameters), |
| 27 | + power_output_exp) |
25 | 28 | # Test wind_speed as np.array with density as np.array and pd.Series |
26 | 29 | power_output_exp = np.array([0.0, 244615.399, 0.0]) |
27 | 30 | 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) |
30 | 34 | parameters['density'] = pd.Series(data=parameters['density']) |
31 | | - assert_allclose(cp_curve(**parameters), power_output_exp) |
32 | | - assert isinstance(cp_curve(**parameters), np.ndarray) |
33 | | - |
34 | | - def test_cp_curve_density_corrected(self): |
35 | | - parameters = {'wind_speed': pd.Series(data=[2.0, 5.5, 7.0]), |
36 | | - 'density': pd.Series(data=[1.3, 1.3, 1.3]), |
37 | | - 'rotor_diameter': 80, |
38 | | - 'cp_values': pd.DataFrame(data={'cp': [0.3, 0.4, 0.5]}, |
39 | | - index=[4.0, 5.0, 6.0])} |
| 35 | + assert_allclose(power_coefficient_curve(**parameters), |
| 36 | + power_output_exp) |
| 37 | + assert isinstance(power_coefficient_curve(**parameters), np.ndarray) |
40 | 38 |
|
41 | | - # Test wind_speed as pd.Series with density as pd.Series and np.array |
| 39 | + # Tests with density correction: |
| 40 | + # Test wind_speed as np.array with density as pd.Series and np.array |
| 41 | + power_output_exp = np.array([0.0, 262869.785, 0.0]) |
| 42 | + parameters['density_corr'] = True |
| 43 | + assert_allclose(power_coefficient_curve(**parameters), |
| 44 | + power_output_exp) |
| 45 | + assert isinstance(power_coefficient_curve(**parameters), np.ndarray) |
| 46 | + parameters['density'] = np.array(parameters['density']) |
| 47 | + assert_allclose(power_coefficient_curve(**parameters), |
| 48 | + power_output_exp) |
| 49 | + assert isinstance(power_coefficient_curve(**parameters), np.ndarray) |
| 50 | + # Test wind_speed as pd.Series with density as np. array and pd.Series |
42 | 51 | power_output_exp = pd.Series(data=[0.0, 262869.785, 0.0], |
43 | 52 | name='feedin_wind_turbine') |
44 | | - assert_series_equal(cp_curve_density_corr(**parameters), |
| 53 | + parameters['wind_speed'] = pd.Series(data=parameters['wind_speed']) |
| 54 | + assert_series_equal(power_coefficient_curve(**parameters), |
45 | 55 | power_output_exp) |
46 | | - parameters['density'] = np.array(parameters['density']) |
47 | | - assert_series_equal(cp_curve_density_corr(**parameters), |
| 56 | + parameters['density'] = pd.Series(data=parameters['density']) |
| 57 | + assert_series_equal(power_coefficient_curve(**parameters), |
48 | 58 | power_output_exp) |
49 | 59 |
|
50 | | - # Test wind_speed as np.array with density as np.array and pd.Series |
51 | | - power_output_exp = np.array([0.0, 262869.785, 0.0]) |
52 | | - parameters['wind_speed'] = np.array(parameters['wind_speed']) |
53 | | - assert_allclose(cp_curve_density_corr(**parameters), |
54 | | - power_output_exp) |
55 | | - assert isinstance(cp_curve_density_corr(**parameters), np.ndarray) |
56 | | - parameters['density'] = pd.Series(data=parameters['density']) |
57 | | - assert_allclose(cp_curve_density_corr(**parameters), |
58 | | - power_output_exp) |
59 | | - assert isinstance(cp_curve_density_corr(**parameters), np.ndarray) |
| 60 | + # Raise TypeErrors due to wrong type of `density_corr` |
| 61 | + with pytest.raises(TypeError): |
| 62 | + parameters['density'] = 'wrong_type' |
| 63 | + power_coefficient_curve(**parameters) |
60 | 64 |
|
61 | | - def test_p_curve(self): |
| 65 | + def test_power_curve(self): |
62 | 66 | parameters = {'wind_speed': pd.Series(data=[2.0, 5.5, 7.0]), |
63 | | - 'p_values': pd.DataFrame(data={'p': [300, 400, 500]}, |
64 | | - index=[4.0, 5.0, 6.0])} |
| 67 | + 'p_values': pd.Series([300, 400, 500], |
| 68 | + index=[4.0, 5.0, 6.0]), |
| 69 | + 'density': pd.Series(data=[1.3, 1.3, 1.3]), |
| 70 | + 'density_corr': False} |
65 | 71 |
|
| 72 | + # Tests without density correction: |
66 | 73 | # Test wind_speed as pd.Series |
67 | 74 | power_output_exp = pd.Series(data=[0.0, 450.0, 0.0], |
68 | 75 | name='feedin_wind_turbine') |
69 | | - assert_series_equal(p_curve(**parameters), power_output_exp) |
70 | | - |
| 76 | + assert_series_equal(power_curve(**parameters), power_output_exp) |
71 | 77 | # Test wind_speed as np.array |
72 | 78 | power_output_exp = np.array([0.0, 450.0, 0.0]) |
73 | 79 | 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) |
| 80 | + assert_allclose(power_curve(**parameters), power_output_exp) |
| 81 | + assert isinstance(power_curve(**parameters), np.ndarray) |
| 82 | + |
| 83 | + # Tests with density correction: |
| 84 | + # Test wind_speed as np.array with density as pd.Series and np.array |
| 85 | + power_output_exp = np.array([0.0, 461.00290572, 0.0]) |
| 86 | + parameters['density_corr'] = True |
| 87 | + assert_allclose(power_curve(**parameters), power_output_exp) |
| 88 | + assert isinstance(power_curve(**parameters), np.ndarray) |
| 89 | + parameters['density'] = np.array(parameters['density']) |
| 90 | + assert_allclose(power_curve(**parameters), power_output_exp) |
| 91 | + assert isinstance(power_curve(**parameters), np.ndarray) |
| 92 | + # Test wind_speed as pd.Series with density as np. array and pd.Series |
| 93 | + power_output_exp = pd.Series(data=[0.0, 461.00290572, 0.0], |
| 94 | + name='feedin_wind_turbine') |
| 95 | + parameters['wind_speed'] = pd.Series(data=parameters['wind_speed']) |
| 96 | + assert_series_equal(power_curve(**parameters), power_output_exp) |
| 97 | + parameters['density'] = pd.Series(data=parameters['density']) |
| 98 | + assert_series_equal(power_curve(**parameters), |
| 99 | + power_output_exp) |
| 100 | + |
| 101 | + # Raise TypeErrors due to wrong type of `density_corr` |
| 102 | + with pytest.raises(TypeError): |
| 103 | + parameters['density'] = 'wrong_type' |
| 104 | + power_curve(**parameters) |
76 | 105 |
|
77 | 106 | def test_p_curve_density_corrected(self): |
78 | 107 | parameters = {'wind_speed': pd.Series(data=[2.0, 5.5, 7.0]), |
79 | 108 | 'density': pd.Series(data=[1.3, 1.3, 1.3]), |
80 | | - 'p_values': pd.DataFrame(data={'p': [300, 400, 500]}, |
81 | | - index=[4.0, 5.0, 6.0])} |
| 109 | + 'p_values': pd.Series([300, 400, 500], |
| 110 | + index=[4.0, 5.0, 6.0])} |
82 | 111 |
|
83 | 112 | # Test wind_speed as pd.Series with density as pd.Series and np.array |
84 | | - power_output_exp = pd.Series(data=[0.0, 461.00290572, 0.0], |
85 | | - name='feedin_wind_turbine') |
86 | | - assert_series_equal(p_curve_density_corr(**parameters), |
87 | | - power_output_exp) |
| 113 | + power_output_exp = [0.0, 461.00290572240806, 0.0] |
| 114 | + assert _p_curve_density_corr(**parameters) == power_output_exp |
88 | 115 | parameters['density'] = np.array(parameters['density']) |
89 | | - assert_series_equal(p_curve_density_corr(**parameters), |
90 | | - power_output_exp) |
| 116 | + assert _p_curve_density_corr(**parameters) == power_output_exp |
91 | 117 |
|
92 | 118 | # Test wind_speed as np.array with density as np.array and pd.Series |
93 | | - power_output_exp = np.array([0.0, 461.00290572, 0.0]) |
94 | | - parameters['wind_speed'] = np.array(parameters['wind_speed']) |
95 | | - assert_allclose(p_curve_density_corr(**parameters), |
96 | | - power_output_exp) |
97 | | - assert isinstance(p_curve_density_corr(**parameters), np.ndarray) |
| 119 | + assert _p_curve_density_corr(**parameters) == power_output_exp |
98 | 120 | parameters['density'] = pd.Series(data=parameters['density']) |
99 | | - assert_allclose(p_curve_density_corr(**parameters), |
100 | | - power_output_exp) |
101 | | - assert isinstance(p_curve_density_corr(**parameters), np.ndarray) |
| 121 | + assert _p_curve_density_corr(**parameters) == power_output_exp |
| 122 | + |
| 123 | + # Raise TypeError due to density is None |
| 124 | + with pytest.raises(TypeError): |
| 125 | + parameters['density'] = None |
| 126 | + _p_curve_density_corr(**parameters) |
0 commit comments