-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextrap_util_tests.py
More file actions
49 lines (44 loc) · 1.71 KB
/
extrap_util_tests.py
File metadata and controls
49 lines (44 loc) · 1.71 KB
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
"""test extrap_utils module"""
#pylint: disable=W0621
from __future__ import absolute_import,division,print_function
from builtins import range
import numpy as np
import pytest
from extrap_utils import power_law_extend
pow_test_list = [[0.03,3.02],[0.02,-1.05],[-0.05,0.2],[-1.6,-3.92]]
@pytest.fixture(params=pow_test_list)
def power_law_low(request):
"""iterate over low end power law parameters"""
return request.param
@pytest.fixture(params=pow_test_list)
def power_law_high(request):
"""iterate over high end parameters"""
return request.param
def test_power_extend_same(power_law_low):
"""test power law extend"""
mult = power_law_low[0]
exp = power_law_low[1]
x_in = np.arange(0.05,1.07,0.0011)
x_out = np.arange(0.02,1.9,0.0013)
f_in = mult*x_in**exp
f_out1 = mult*x_out**exp
f_out2 = power_law_extend(x_in,f_in,x_out,k=3)
assert np.allclose(f_out1,f_out2)
def test_power_extend2(power_law_low,power_law_high):
"""test power law extend different power laws"""
x_in = np.arange(0.05,1.07,0.00011)
x_out = np.arange(0.02,1.9,0.00013)
mult_low = power_law_low[0]
exp_low = power_law_low[1]
mult_high = power_law_high[0]
exp_high = power_law_high[1]
f_in = mult_low*x_in**exp_low
f_in[x_in>0.5] = mult_high*x_in[x_in>0.5]**exp_high
f_out1 = mult_low*x_out**exp_low
f_out1[x_out>0.5] = mult_high*x_out[x_out>0.5]**exp_high
f_out2 = power_law_extend(x_in,f_in,x_out,k=3)
#cut out the break where spline may misbehave
assert np.allclose(f_out1[x_out>0.5+0.005],f_out2[x_out>0.5+0.005])
assert np.allclose(f_out1[x_out<0.5-0.005],f_out2[x_out<0.5-0.005])
if __name__=='__main__':
pytest.cmdline.main(['extrap_util_tests.py'])