-
Notifications
You must be signed in to change notification settings - Fork 44
/
mpsPyBindTest.py
178 lines (137 loc) · 6.18 KB
/
mpsPyBindTest.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import unittest
from projectaria_tools.core import mps
TEST_FOLDER = os.getenv("TEST_FOLDER")
closed_loop_trajectory_file = os.path.join(
TEST_FOLDER, "mps_sample/trajectory/closed_loop_trajectory.csv"
)
open_loop_trajectory_file = os.path.join(
TEST_FOLDER, "mps_sample/trajectory/open_loop_trajectory.csv"
)
class MPSTrajectory(unittest.TestCase):
"""
Tests for reading trajectory files
"""
def test_open_loop(self) -> None:
mps_trajectory = mps.read_open_loop_trajectory(open_loop_trajectory_file)
assert len(mps_trajectory) > 0
def test_open_loop_invalid_file(self) -> None:
mps_trajectory = mps.read_open_loop_trajectory("")
assert len(mps_trajectory) == 0
def test_closed_loop(self) -> None:
mps_trajectory = mps.read_closed_loop_trajectory(closed_loop_trajectory_file)
assert len(mps_trajectory) > 0
def test_closed_loop_invalid_file(self) -> None:
mps_trajectory = mps.read_closed_loop_trajectory("")
assert len(mps_trajectory) == 0
global_points_file = os.path.join(
TEST_FOLDER, "mps_sample/trajectory/global_points.csv.gz"
)
semidense_observations_file = os.path.join(
TEST_FOLDER, "mps_sample/trajectory/semidense_observations.csv.gz"
)
class MPSPointCloudAndObservations(unittest.TestCase):
"""
Tests for reading point cloud and observations from csv.gz files
"""
def test_global_points(self) -> None:
mps_global_points = mps.read_global_point_cloud(
global_points_file, mps.StreamCompressionMode.GZIP
)
assert len(mps_global_points) > 0
mps_global_points2 = mps.read_global_point_cloud(global_points_file)
assert len(mps_global_points2) > 0
def test_global_points_invalid_file(self) -> None:
mps_global_points = mps.read_global_point_cloud("")
assert len(mps_global_points) == 0
def test_semidense_observations(self) -> None:
mps_semidense_observations = mps.read_point_observations(
semidense_observations_file, mps.StreamCompressionMode.GZIP
)
assert len(mps_semidense_observations) > 0
mps_semidense_observations2 = mps.read_point_observations(
semidense_observations_file
)
assert len(mps_semidense_observations2) > 0
def test_semidense_observations_invalid_file(self) -> None:
mps_semidense_observations = mps.read_point_observations("")
assert len(mps_semidense_observations) == 0
online_calibration_file = os.path.join(
TEST_FOLDER, "mps_sample/trajectory/online_calibration.jsonl"
)
class MPSOnlineCalibration(unittest.TestCase):
"""
Tests for reading online calibration from jsonl files
"""
def test_online_calibration(self) -> None:
mps_online_calibration = mps.read_online_calibration(online_calibration_file)
assert len(mps_online_calibration) > 0
def test_online_calibration_invalid_file(self) -> None:
mps_online_calibration = mps.read_online_calibration("")
assert len(mps_online_calibration) == 0
class MPSEyeGaze(unittest.TestCase):
"""
Tests for reading eye gaze data from csv files
"""
def test_eyegaze_valid_file(self) -> None:
eye_gaze_file = os.path.join(TEST_FOLDER, "mps_sample/eye_gaze/eyegaze.csv")
mps_eye_gazes = mps.read_eyegaze(eye_gaze_file)
self.assertGreater(len(mps_eye_gazes), 0)
self.assertEqual(mps_eye_gazes[0].session_uid, "")
def test_eyegaze_valid_file_with_session_id(self) -> None:
eye_gaze_file = os.path.join(
TEST_FOLDER, "mps_sample/eye_gaze/generalized_eye_gaze.csv"
)
mps_eye_gazes = mps.read_eyegaze(eye_gaze_file)
self.assertGreater(len(mps_eye_gazes), 0)
self.assertNotEqual(mps_eye_gazes[0].session_uid, "")
def test_eyegaze_invalid_file(self) -> None:
eye_gaze_file = ""
mps_eye_gazes = mps.read_eyegaze(eye_gaze_file)
self.assertEqual(len(mps_eye_gazes), 0)
mps_root_path = os.path.join(TEST_FOLDER, "mps_sample")
class MPSDataProvider(unittest.TestCase):
"""
Tests for loading and querying data with MpsDataProvider
"""
def test_data_paths_provider(self) -> None:
data_paths_provider = mps.MpsDataPathsProvider(mps_root_path)
data_paths = data_paths_provider.get_data_paths()
assert os.path.exists(data_paths.eyegaze.general_eyegaze)
assert os.path.exists(data_paths.eyegaze.summary)
assert os.path.exists(data_paths.slam.closed_loop_trajectory)
assert os.path.exists(data_paths.slam.open_loop_trajectory)
assert os.path.exists(data_paths.slam.semidense_points)
assert os.path.exists(data_paths.slam.semidense_observations)
assert os.path.exists(data_paths.slam.online_calibrations)
assert os.path.exists(data_paths.slam.summary)
def test_data_provider(self) -> None:
data_paths_provider = mps.MpsDataPathsProvider(mps_root_path)
data_paths = data_paths_provider.get_data_paths()
dp = mps.MpsDataProvider(data_paths)
assert dp.has_general_eyegaze()
assert not dp.has_personalized_eyegaze()
assert dp.has_open_loop_poses()
assert dp.has_closed_loop_poses()
assert dp.has_online_calibrations()
assert dp.has_semidense_point_cloud()
assert dp.has_semidense_observations()
assert len(dp.get_semidense_point_cloud()) > 0
assert len(dp.get_semidense_observations()) > 0
assert dp.get_open_loop_pose(0)
assert dp.get_closed_loop_pose(0)
assert dp.get_general_eyegaze(0)
assert dp.get_online_calibration(0)