|
| 1 | +from windpowerlib.density import (temperature_gradient, |
| 2 | + rho_barometric, rho_ideal_gas) |
| 3 | +import pandas as pd |
| 4 | +from pandas.util.testing import assert_series_equal |
| 5 | +from numpy.testing import assert_array_equal, assert_allclose |
| 6 | +import numpy as np |
| 7 | + |
| 8 | + |
| 9 | +class TestDensityTemperature: |
| 10 | + |
| 11 | + def test_temperature_gradient(self): |
| 12 | + parameters = {'temp_air': pd.Series(data=[267, 268]), |
| 13 | + 'temp_height': 2, |
| 14 | + 'hub_height': 100} |
| 15 | + |
| 16 | + # Test temp_air 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 temp_air as np.array |
| 21 | + temp_hub_exp = np.array([266.363, 267.36300]) |
| 22 | + parameters['temp_air'] = np.array(parameters['temp_air']) |
| 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): |
| 27 | + parameters = {'pressure': pd.Series(data=[101125, 101000]), |
| 28 | + 'pressure_height': 0, |
| 29 | + 'hub_height': 100, |
| 30 | + 'temp_hub': pd.Series(data=[267, 268])} |
| 31 | + |
| 32 | + # Test pressure as pd.Series and temp_hub as pd.Series and np.array |
| 33 | + rho_exp = pd.Series(data=[1.30305336, 1.29656645]) |
| 34 | + assert_series_equal(rho_barometric(**parameters), rho_exp) |
| 35 | + parameters['temp_hub'] = np.array(parameters['temp_hub']) |
| 36 | + assert_series_equal(rho_barometric(**parameters), rho_exp) |
| 37 | + |
| 38 | + # Test pressure as np.array and temp_hub as pd.Series |
| 39 | + parameters['pressure'] = np.array(parameters['pressure']) |
| 40 | + parameters['temp_hub'] = pd.Series(data=parameters['temp_hub']) |
| 41 | + assert_series_equal(rho_barometric(**parameters), rho_exp) |
| 42 | + |
| 43 | + # Test pressure as np.array and temp_hub as np.array |
| 44 | + rho_exp = np.array([1.30305336, 1.29656645]) |
| 45 | + parameters['temp_hub'] = np.array(parameters['temp_hub']) |
| 46 | + assert_allclose(rho_barometric(**parameters), rho_exp) |
| 47 | + assert isinstance(rho_barometric(**parameters), np.ndarray) |
| 48 | + |
| 49 | + def test_rho_ideal_gas(self): |
| 50 | + parameters = {'pressure': pd.Series(data=[101125, 101000]), |
| 51 | + 'pressure_height': 0, |
| 52 | + 'hub_height': 100, |
| 53 | + 'temp_hub': pd.Series(data=[267, 268])} |
| 54 | + |
| 55 | + # Test pressure as pd.Series and temp_hub as pd.Series and np.array |
| 56 | + rho_exp = pd.Series(data=[1.30309439, 1.29660728]) |
| 57 | + assert_series_equal(rho_ideal_gas(**parameters), rho_exp) |
| 58 | + parameters['temp_hub'] = np.array(parameters['temp_hub']) |
| 59 | + assert_series_equal(rho_ideal_gas(**parameters), rho_exp) |
| 60 | + |
| 61 | + # Test pressure as np.array and temp_hub as pd.Series |
| 62 | + parameters['pressure'] = np.array(parameters['pressure']) |
| 63 | + parameters['temp_hub'] = pd.Series(data=parameters['temp_hub']) |
| 64 | + assert_allclose(rho_ideal_gas(**parameters), rho_exp) |
| 65 | + |
| 66 | + # Test pressure as np.array and temp_hub as np.array |
| 67 | + rho_exp = np.array([1.30309439, 1.29660728]) |
| 68 | + parameters['temp_hub'] = np.array(parameters['temp_hub']) |
| 69 | + assert_allclose(rho_ideal_gas(**parameters), rho_exp) |
| 70 | + assert isinstance(rho_ideal_gas(**parameters), np.ndarray) |
0 commit comments