|
1 | 1 | import pandas as pd |
2 | 2 | from pandas.util.testing import assert_series_equal |
3 | 3 |
|
4 | | -from windpowerlib.tools import linear_interpolation_extrapolation |
| 4 | +from windpowerlib.tools import (linear_interpolation_extrapolation, |
| 5 | + logarithmic_interpolation_extrapolation) |
5 | 6 |
|
6 | 7 |
|
7 | 8 | class TestTools: |
@@ -39,3 +40,38 @@ def test_linear_interpolation_extrapolation(self): |
39 | 40 | assert_series_equal(linear_interpolation_extrapolation( |
40 | 41 | df, **parameters), exp_output) |
41 | 42 |
|
| 43 | + def test_logarithmic_interpolation_extrapolation(self): |
| 44 | + parameters = {'target_height': 80} |
| 45 | + df = pd.DataFrame(data={10: [2.0, 2.0, 3.0], |
| 46 | + 80: [4.0, 5.0, 6.0], |
| 47 | + 200: [5.0, 8.0, 10.0]}, |
| 48 | + index=[0, 1, 2]) |
| 49 | + # target_height is equal to height given in a column of the DataFrame |
| 50 | + exp_output = pd.Series(data=[4.0, 5.0, 6.0]) |
| 51 | + assert_series_equal(logarithmic_interpolation_extrapolation( |
| 52 | + df, **parameters), exp_output) |
| 53 | + # target_height is between heights given in the columns of the |
| 54 | + # DataFrame |
| 55 | + exp_output = pd.Series( |
| 56 | + data=[4.61074042165, 6.83222126494, 8.44296168659]) |
| 57 | + parameters['target_height'] = 140 |
| 58 | + assert_series_equal(logarithmic_interpolation_extrapolation( |
| 59 | + df, **parameters), exp_output) |
| 60 | + exp_output = pd.Series( |
| 61 | + data=[4.11328333429, 5.16992500144, 6.16992500144]) |
| 62 | + parameters['target_height'] = 90 |
| 63 | + assert_series_equal(logarithmic_interpolation_extrapolation( |
| 64 | + df, **parameters), exp_output) |
| 65 | + # target_height is greater than the heights given in the columns of the |
| 66 | + # DataFrame |
| 67 | + exp_output = pd.Series( |
| 68 | + data=[5.19897784672, 8.59693354015, 10.7959113869]) |
| 69 | + parameters['target_height'] = 240 |
| 70 | + assert_series_equal(logarithmic_interpolation_extrapolation( |
| 71 | + df, **parameters), exp_output) |
| 72 | + # target_height is smaller than the heights given in the columns of the |
| 73 | + # DataFrame |
| 74 | + exp_output = pd.Series(data=[1.33333333333, 1.0, 2.0]) |
| 75 | + parameters['target_height'] = 5 |
| 76 | + assert_series_equal(logarithmic_interpolation_extrapolation( |
| 77 | + df, **parameters), exp_output) |
0 commit comments