|
8 | 8 |
|
9 | 9 | class TestWindSpeed: |
10 | 10 |
|
11 | | - @classmethod |
12 | | - def setup_class(self): |
13 | | - self.logarithmic = {'v_wind': pd.Series(data=[5.0, 6.5]), |
14 | | - 'z_0': pd.Series(data=[0.15, 0.15]), |
15 | | - 'hub_height': 100, |
16 | | - 'v_wind_height': 10, |
17 | | - 'obstacle_height': 0} |
18 | | - |
19 | | - self.hellman = {'v_wind': pd.Series(data=[5.0, 6.5]), |
20 | | - 'hub_height': 100, |
21 | | - 'v_wind_height': 10, |
22 | | - 'z_0': None, |
23 | | - 'hellman_exp': None} |
24 | | - |
25 | 11 | def test_logarithmic_wind_profile(self): |
| 12 | + parameters = {'v_wind': pd.Series(data=[5.0, 6.5]), |
| 13 | + 'z_0': pd.Series(data=[0.15, 0.15]), |
| 14 | + 'hub_height': 100, |
| 15 | + 'v_wind_height': 10, |
| 16 | + 'obstacle_height': 0} |
26 | 17 | # Test pandas.Series |
27 | 18 | v_wind_hub_exp = pd.Series(data=[7.74136523, 10.0637748]) |
28 | | - assert_series_equal(logarithmic_wind_profile(**self.logarithmic), |
| 19 | + assert_series_equal(logarithmic_wind_profile(**parameters), |
29 | 20 | v_wind_hub_exp) |
30 | 21 | # Test numpy array |
31 | | - self.logarithmic['z_0'] = np.array(self.logarithmic['z_0']) |
32 | | - self.logarithmic['v_wind'] = np.array(self.logarithmic['v_wind']) |
33 | | - assert_allclose(logarithmic_wind_profile(**self.logarithmic), |
34 | | - v_wind_hub_exp) |
| 22 | + parameters['z_0'] = np.array(parameters['z_0']) |
| 23 | + parameters['v_wind'] = np.array(parameters['v_wind']) |
| 24 | + assert_allclose(logarithmic_wind_profile(**parameters), v_wind_hub_exp) |
35 | 25 | # Test z_0 is float and obstacle height |
36 | 26 | v_wind_hub_exp = np.array([13.54925281, 17.61402865]) |
37 | | - self.logarithmic['z_0'] = self.logarithmic['z_0'][0] |
38 | | - self.logarithmic['obstacle_height'] = 12 |
39 | | - assert_allclose(logarithmic_wind_profile(**self.logarithmic), |
40 | | - v_wind_hub_exp) |
| 27 | + parameters['z_0'] = parameters['z_0'][0] |
| 28 | + parameters['obstacle_height'] = 12 |
| 29 | + assert_allclose(logarithmic_wind_profile(**parameters), v_wind_hub_exp) |
41 | 30 | # Raise ValueError due to 0.7 * `obstacle_height` > `v_wind_height` |
42 | 31 | with pytest.raises(ValueError): |
43 | | - logarithmic_wind_profile(v_wind=5.5, v_wind_height=10, |
44 | | - hub_height=100, z_0=0.15, |
45 | | - obstacle_height=20) |
| 32 | + parameters['obstacle_height'] = 20 |
| 33 | + logarithmic_wind_profile(**parameters) |
46 | 34 |
|
47 | 35 | def test_v_wind_hellman(self): |
| 36 | + parameters = {'v_wind': pd.Series(data=[5.0, 6.5]), |
| 37 | + 'hub_height': 100, |
| 38 | + 'v_wind_height': 10, |
| 39 | + 'z_0': None, |
| 40 | + 'hellman_exp': None} |
48 | 41 | # Test pandas.Series and z_0 is None |
49 | 42 | v_wind_hub_exp = pd.Series(data=[6.9474774, 9.03172]) |
50 | | - assert_series_equal(v_wind_hellman(**self.hellman), v_wind_hub_exp) |
| 43 | + assert_series_equal(v_wind_hellman(**parameters), v_wind_hub_exp) |
51 | 44 |
|
52 | 45 | # Test z_0 is float |
53 | 46 | v_wind_hub_exp = pd.Series(data=[7.12462437, 9.26201168]) |
54 | | - self.hellman['z_0'] = 0.15 |
55 | | - assert_series_equal(v_wind_hellman(**self.hellman), v_wind_hub_exp) |
| 47 | + parameters['z_0'] = 0.15 |
| 48 | + assert_series_equal(v_wind_hellman(**parameters), v_wind_hub_exp) |
56 | 49 |
|
57 | 50 | # Test array and z_0 is pandas.Series |
58 | | - self.hellman['v_wind'] = np.array(self.hellman['v_wind']) |
59 | | - self.hellman['z_0'] = pd.Series(data=[0.15, 0.15]) |
60 | | - assert_allclose(v_wind_hellman(**self.hellman), v_wind_hub_exp) |
| 51 | + parameters['v_wind'] = np.array(parameters['v_wind']) |
| 52 | + parameters['z_0'] = pd.Series(data=[0.15, 0.15]) |
| 53 | + assert_allclose(v_wind_hellman(**parameters), v_wind_hub_exp) |
61 | 54 |
|
62 | 55 | # Test z_0 is array |
63 | | - self.hellman['z_0'] = np.array(self.hellman['z_0']) |
64 | | - assert_allclose(v_wind_hellman(**self.hellman), v_wind_hub_exp) |
| 56 | + parameters['z_0'] = np.array(parameters['z_0']) |
| 57 | + assert_allclose(v_wind_hellman(**parameters), v_wind_hub_exp) |
65 | 58 |
|
66 | 59 | # Test hellman_exp is not None |
67 | 60 | v_wind_hub_exp = np.array([7.92446596, 10.30180575]) |
68 | | - self.hellman['hellman_exp'] = 0.2 |
69 | | - assert_allclose(v_wind_hellman(**self.hellman), v_wind_hub_exp) |
| 61 | + parameters['hellman_exp'] = 0.2 |
| 62 | + assert_allclose(v_wind_hellman(**parameters), v_wind_hub_exp) |
70 | 63 |
|
71 | 64 | # Raise TypeErrors due to wrong types of `hellman_exp`. |
| 65 | + parameters['hellman_exp'] = 8 |
72 | 66 | with pytest.raises(TypeError): |
73 | | - v_wind_hellman(v_wind=5.5, v_wind_height=10, hub_height=100, |
74 | | - hellman_exp=8) |
| 67 | + v_wind_hellman(**parameters) |
75 | 68 | with pytest.raises(TypeError): |
76 | | - v_wind_hellman(v_wind=5.5, v_wind_height=10, hub_height=100, |
77 | | - hellman_exp=False) |
| 69 | + parameters['hellman_exp'] = False |
| 70 | + v_wind_hellman(**parameters) |
0 commit comments