-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathtest_density.py
77 lines (66 loc) · 2.94 KB
/
test_density.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
SPDX-FileCopyrightText: 2019 oemof developer group <contact@oemof.org>
SPDX-License-Identifier: MIT
"""
import pandas as pd
import numpy as np
from pandas.util.testing import assert_series_equal
from numpy.testing import assert_allclose
from windpowerlib.density import barometric, ideal_gas
class TestDensity:
def test_barometric(self):
parameters = {
"pressure": pd.Series(data=[101125, 101000]),
"pressure_height": 0,
"hub_height": 100,
"temperature_hub_height": pd.Series(data=[267, 268]),
}
# Test pressure as pd.Series and temperature_hub_height as pd.Series
# and np.array
rho_exp = pd.Series(data=[1.30305336, 1.29656645])
assert_series_equal(barometric(**parameters), rho_exp)
parameters["temperature_hub_height"] = np.array(
parameters["temperature_hub_height"]
)
assert_series_equal(barometric(**parameters), rho_exp)
# Test pressure as np.array and temperature_hub_height as pd.Series
parameters["pressure"] = np.array(parameters["pressure"])
parameters["temperature_hub_height"] = pd.Series(
data=parameters["temperature_hub_height"]
)
assert_series_equal(barometric(**parameters), rho_exp)
# Test pressure as np.array and temperature_hub_height as np.array
rho_exp = np.array([1.30305336, 1.29656645])
parameters["temperature_hub_height"] = np.array(
parameters["temperature_hub_height"]
)
assert_allclose(barometric(**parameters), rho_exp)
assert isinstance(barometric(**parameters), np.ndarray)
def test_ideal_gas(self):
parameters = {
"pressure": pd.Series(data=[101125, 101000]),
"pressure_height": 0,
"hub_height": 100,
"temperature_hub_height": pd.Series(data=[267, 268]),
}
# Test pressure as pd.Series and temperature_hub_height as pd.Series
# and np.array
rho_exp = pd.Series(data=[1.30309439, 1.29660728])
assert_series_equal(ideal_gas(**parameters), rho_exp)
parameters["temperature_hub_height"] = np.array(
parameters["temperature_hub_height"]
)
assert_series_equal(ideal_gas(**parameters), rho_exp)
# Test pressure as np.array and temperature_hub_height as pd.Series
parameters["pressure"] = np.array(parameters["pressure"])
parameters["temperature_hub_height"] = pd.Series(
data=parameters["temperature_hub_height"]
)
assert_allclose(ideal_gas(**parameters), rho_exp)
# Test pressure as np.array and temperature_hub_height as np.array
rho_exp = np.array([1.30309439, 1.29660728])
parameters["temperature_hub_height"] = np.array(
parameters["temperature_hub_height"]
)
assert_allclose(ideal_gas(**parameters), rho_exp)
assert isinstance(ideal_gas(**parameters), np.ndarray)