forked from argoverse/argoverse-api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_grid_interpolation.py
93 lines (77 loc) · 3.22 KB
/
test_grid_interpolation.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# <Copyright 2019, Argo AI, LLC. Released under the MIT license.>
import numpy as np
from argoverse.utils.grid_interpolation import interp_square_grid
def test_interp_square_grid_nearest_3to4():
"""
"nearest" interpolation ight make sense for something binary valued like ROI.
"""
grid_data = np.array([[1, 1, 1], [1, 2, 1], [1, 1, 1]])
in_dim = 3
out_dim = 4
interp_type = "nearest"
out_grid = interp_square_grid(grid_data, in_dim=in_dim, out_dim=out_dim, interp_type=interp_type)
gt_interp_grid = np.array([[1.0, 1.0, 1.0, 1.0], [1.0, 2.0, 2.0, 1.0], [1.0, 2.0, 2.0, 1.0], [1.0, 1.0, 1.0, 1.0]])
assert np.allclose(out_grid, gt_interp_grid)
def test_interp_square_grid_nearest_2to3():
"""
"nearest" interpolation ight make sense for something binary valued like ROI.
"""
grid_data = np.array([[1, 1], [1, 2]])
in_dim = 2
out_dim = 3
interp_type = "nearest"
out_grid = interp_square_grid(grid_data, in_dim=in_dim, out_dim=out_dim, interp_type=interp_type)
gt_interp_grid = np.array([[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 2.0]])
assert np.allclose(out_grid, gt_interp_grid)
def test_interp_square_grid_linear_3to5():
"""
"linear" interpolation ight make sense for real valued numbers, e.g. ground heights.
"""
in_grid = np.array([[1.0, 1.0, 1.0], [1.0, 2.0, 1.0], [1.0, 1.0, 1.0]])
in_dim = 3
out_dim = 5
interp_type = "linear"
out_grid = interp_square_grid(in_grid, in_dim=in_dim, out_dim=out_dim, interp_type=interp_type)
gt_interp_grid = np.array(
[
[1.0, 1.0, 1.0, 1.0, 1.0],
[1.0, 1.25, 1.5, 1.25, 1.0],
[1.0, 1.5, 2.0, 1.5, 1.0],
[1.0, 1.25, 1.5, 1.25, 1.0],
[1.0, 1.0, 1.0, 1.0, 1.0],
]
)
assert np.allclose(out_grid, gt_interp_grid)
def test_interp_square_grid_linear_2to3():
"""
"linear" interpolation ight make sense for real valued numbers, e.g. ground heights.
"""
grid_data = np.array([[1, 1], [1, 2]])
in_dim = 2
out_dim = 3
interp_type = "linear"
out_grid = interp_square_grid(grid_data, in_dim=in_dim, out_dim=out_dim, interp_type=interp_type)
gt_interp_grid = [[1.0, 1.0, 1.0], [1.0, 1.25, 1.5], [1.0, 1.5, 2.0]]
assert np.allclose(out_grid, gt_interp_grid)
def test_interp_square_grid_linear_2to3_neg():
"""
"linear" interpolation ight make sense for real valued numbers, e.g. ground heights.
"""
grid_data = np.array([[-50.0, -25.0], [-25.0, -25.0]])
in_dim = 2
out_dim = 3
interp_type = "linear"
out_grid = interp_square_grid(grid_data, in_dim=in_dim, out_dim=out_dim, interp_type=interp_type)
gt_interp_grid = np.array([[-50.0, -37.5, -25.0], [-37.5, -31.25, -25.0], [-25.0, -25.0, -25.0]])
assert np.allclose(out_grid, gt_interp_grid)
def test_interp_square_grid_linear_2to5_zero():
"""
"linear" interpolation ight make sense for real valued numbers, e.g. ground heights.
"""
grid_data = np.zeros((2, 2))
in_dim = 2
out_dim = 5
interp_type = "linear"
out_grid = interp_square_grid(grid_data, in_dim=in_dim, out_dim=out_dim, interp_type=interp_type)
gt_interp_grid = np.zeros((5, 5))
assert np.allclose(out_grid, gt_interp_grid)