Debian Codegraph @

benchmark/reconstruction/evaluation/tartanair/tartanair_v2_test.py

raw
1 import json
2
3 import numpy as np
4 import pytest
5
6 from .tartanair_v2 import (
7 MANIFEST_PATH,
8 list_scenes,
9 load_manifest,
10 scene_shards,
11 select_frame_window,
12 shard_name,
13 )
14
15
16 def test_manifest_invariants():
17 manifest = load_manifest()
18 scenes = list_scenes(manifest)
19
20 assert len(scenes) == 100
21 assert len({scene.name for scene in scenes}) == 100
22 assert len({scene.environment for scene in scenes}) == 74
23 assert sum(scene.difficulty == "easy" for scene in scenes) == 50
24 assert sum(scene.difficulty == "hard" for scene in scenes) == 50
25 assert set(manifest["selections"]) == {
26 "domestic",
27 "infrastructure",
28 "nature",
29 "rural",
30 "thematic",
31 "urban",
32 }
33 assert set(manifest["frame_starts"]) == {
34 f"{scene.environment}:{scene.difficulty}:{scene.trajectory}"
35 for scene in scenes
36 }
37 assert len(scene_shards(manifest)) == 13
38 checksum_path = MANIFEST_PATH.with_name("tartanair_v2_checksums.json")
39 checksums = json.loads(checksum_path.read_text())
40 assert set(checksums) == {
41 shard_name(manifest, index)
42 for index in range(len(scene_shards(manifest)))
43 }
44
45
46 def test_select_frame_window_maximizes_extent():
47 poses = np.zeros((8, 7))
48 poses[:, 6] = 1.0
49 poses[:, 0] = [0.0, 0.1, 0.2, 0.3, 0.4, 1.3, 2.2, 3.1]
50
51 selected = select_frame_window(
52 poses,
53 num_frames=4,
54 max_adjacent_translation_m=1.0,
55 max_adjacent_rotation_deg=30.0,
56 )
57
58 assert selected == range(4, 8)
59
60
61 def test_select_frame_window_rejects_motion_gaps():
62 poses = np.zeros((4, 7))
63 poses[:, 6] = 1.0
64 poses[:, 0] = [0.0, 0.1, 2.0, 2.1]
65
66 with pytest.raises(ValueError, match="no frame window"):
67 select_frame_window(
68 poses,
69 num_frames=4,
70 max_adjacent_translation_m=1.0,
71 max_adjacent_rotation_deg=30.0,
72 )