simview 6.4.0__tar.gz → 7.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {simview-6.4.0/simview.egg-info → simview-7.0.0}/PKG-INFO +1 -1
- {simview-6.4.0 → simview-7.0.0}/pyproject.toml +2 -2
- {simview-6.4.0 → simview-7.0.0}/simview/__main__.py +399 -48
- {simview-6.4.0 → simview-7.0.0}/simview/columnar.py +3 -2
- {simview-6.4.0 → simview-7.0.0}/simview/diff.py +31 -2
- {simview-6.4.0 → simview-7.0.0}/simview/info.py +175 -11
- {simview-6.4.0 → simview-7.0.0}/simview/launcher.py +1 -0
- {simview-6.4.0 → simview-7.0.0}/simview/merge.py +22 -19
- {simview-6.4.0 → simview-7.0.0}/simview/remote.py +1 -1
- {simview-6.4.0 → simview-7.0.0}/simview/render.py +38 -13
- simview-7.0.0/simview/sample.py +230 -0
- {simview-6.4.0 → simview-7.0.0}/simview/scene.py +14 -12
- {simview-6.4.0 → simview-7.0.0}/simview/server.py +58 -11
- {simview-6.4.0 → simview-7.0.0}/simview/static/css/controls.css +7 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/SimView.js +56 -21
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/components/AnimationController.js +17 -6
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/components/WindowedField.js +12 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/objects/Body.js +34 -17
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/objects/StaticObject.js +21 -4
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/objects/Terrain.js +88 -19
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/objects/utils.js +8 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/ui/PlaybackControls.js +45 -10
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/ui/ScalarPlotter.js +4 -4
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/ui/TerrainProfile.js +6 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/utils/csv.js +4 -1
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/utils/liveFollow.js +10 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/utils/terrainSample.js +4 -4
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/utils/viewerDefaults.js +3 -2
- {simview-6.4.0 → simview-7.0.0}/simview/terrain.py +257 -57
- {simview-6.4.0 → simview-7.0.0}/simview/utils.py +96 -2
- {simview-6.4.0 → simview-7.0.0/simview.egg-info}/PKG-INFO +1 -1
- {simview-6.4.0 → simview-7.0.0}/simview.egg-info/SOURCES.txt +3 -0
- simview-7.0.0/simview.egg-info/entry_points.txt +2 -0
- simview-7.0.0/tests/test_agent_cli.py +374 -0
- {simview-6.4.0 → simview-7.0.0}/tests/test_cli.py +20 -7
- {simview-6.4.0 → simview-7.0.0}/tests/test_launcher.py +19 -0
- {simview-6.4.0 → simview-7.0.0}/tests/test_merge.py +44 -0
- {simview-6.4.0 → simview-7.0.0}/tests/test_remote.py +2 -0
- {simview-6.4.0 → simview-7.0.0}/tests/test_server.py +20 -0
- {simview-6.4.0 → simview-7.0.0}/tests/test_show.py +11 -0
- simview-7.0.0/tests/test_strict_json.py +100 -0
- {simview-6.4.0 → simview-7.0.0}/tests/test_terrain_query.py +21 -0
- simview-6.4.0/simview.egg-info/entry_points.txt +0 -2
- {simview-6.4.0 → simview-7.0.0}/LICENSE +0 -0
- {simview-6.4.0 → simview-7.0.0}/MANIFEST.in +0 -0
- {simview-6.4.0 → simview-7.0.0}/README.md +0 -0
- {simview-6.4.0 → simview-7.0.0}/setup.cfg +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/__init__.py +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/live.py +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/model.py +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/preload.py +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/py.typed +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/state.py +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/components/BatchManager.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/components/InteractionController.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/components/Scene.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/components/StateStore.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/config.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/main.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/objects/Polyline.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/objects/colormap.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/objects/similarity.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/ui/AnalysisPanel.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/ui/BatchLegend.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/ui/BodyStateWindow.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/ui/Controls.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/ui/ErrorMetrics.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/ui/Legend.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/ui/chartControls.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/utils/batchPresets.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/utils/batchVisibility.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/utils/blobCodec.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/utils/blobWindow.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/utils/bodyTransforms.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/utils/cameraRange.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/utils/episodes.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/utils/errorMath.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/utils/html.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/utils/interpolate.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/utils/keyboard.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/utils/scalarSeries.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/utils/uplot.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/utils/viewState.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/utils/visibleRanges.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/js/vendor/js-colormaps.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/lib/three-0.174.0/addons/controls/OrbitControls.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/lib/three-0.174.0/addons/libs/lil-gui.module.min.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/lib/three-0.174.0/three.core.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/lib/three-0.174.0/three.module.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/lib/uPlot-1.6.32/uPlot.esm.js +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/lib/uPlot-1.6.32/uPlot.min.css +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/textures/contacts/red-cross0.png +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/static/textures/points/ball1.png +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/templates/index.html +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview/view.py +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview.egg-info/dependency_links.txt +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview.egg-info/requires.txt +0 -0
- {simview-6.4.0 → simview-7.0.0}/simview.egg-info/top_level.txt +0 -0
- {simview-6.4.0 → simview-7.0.0}/tests/test_batch_selection.py +0 -0
- {simview-6.4.0 → simview-7.0.0}/tests/test_columnar_ondisk.py +0 -0
- {simview-6.4.0 → simview-7.0.0}/tests/test_columnar_states.py +0 -0
- {simview-6.4.0 → simview-7.0.0}/tests/test_contacts.py +0 -0
- {simview-6.4.0 → simview-7.0.0}/tests/test_diff.py +0 -0
- {simview-6.4.0 → simview-7.0.0}/tests/test_embed_defaults.py +0 -0
- {simview-6.4.0 → simview-7.0.0}/tests/test_episodes.py +0 -0
- {simview-6.4.0 → simview-7.0.0}/tests/test_info.py +0 -0
- {simview-6.4.0 → simview-7.0.0}/tests/test_live.py +0 -0
- {simview-6.4.0 → simview-7.0.0}/tests/test_pointcloud_features.py +0 -0
- {simview-6.4.0 → simview-7.0.0}/tests/test_preload.py +0 -0
- {simview-6.4.0 → simview-7.0.0}/tests/test_roundtrip.py +0 -0
- {simview-6.4.0 → simview-7.0.0}/tests/test_scene.py +0 -0
- {simview-6.4.0 → simview-7.0.0}/tests/test_terrain.py +0 -0
- {simview-6.4.0 → simview-7.0.0}/tests/test_trajectory.py +0 -0
- {simview-6.4.0 → simview-7.0.0}/tests/test_utils.py +0 -0
- {simview-6.4.0 → simview-7.0.0}/tests/test_view.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: simview
|
|
3
|
-
Version:
|
|
3
|
+
Version: 7.0.0
|
|
4
4
|
Summary: THREE.js-based simulation visualization tool
|
|
5
5
|
Author-email: Jan Vlk <vlkjan6@fel.cvut.cz>, Ales Kucera <kuceral4@fel.cvut.cz>, David Korcak <david.korcak@gmail.com>
|
|
6
6
|
License-Expression: BSD-3-Clause
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "simview"
|
|
7
|
-
version = "
|
|
7
|
+
version = "7.0.0"
|
|
8
8
|
readme = "README.md"
|
|
9
9
|
requires-python = ">=3.12"
|
|
10
10
|
license = "BSD-3-Clause"
|
|
@@ -47,7 +47,7 @@ authoring = ["torch", "numpy"]
|
|
|
47
47
|
render = ["playwright>=1.40"]
|
|
48
48
|
|
|
49
49
|
[project.scripts]
|
|
50
|
-
simview = "simview.__main__:
|
|
50
|
+
simview = "simview.__main__:cli"
|
|
51
51
|
|
|
52
52
|
[tool.setuptools.package-dir]
|
|
53
53
|
simview = "simview"
|
|
@@ -4,13 +4,21 @@ import argparse
|
|
|
4
4
|
import gzip
|
|
5
5
|
import json
|
|
6
6
|
import logging
|
|
7
|
+
import math
|
|
8
|
+
import os
|
|
7
9
|
import shutil
|
|
8
10
|
import sys
|
|
9
11
|
from pathlib import Path
|
|
10
12
|
|
|
11
13
|
from simview import CACHE_DIR, __version__, remote
|
|
12
14
|
from simview.server import SimViewServer
|
|
13
|
-
from simview.utils import
|
|
15
|
+
from simview.utils import (
|
|
16
|
+
dumps_json,
|
|
17
|
+
human_bytes,
|
|
18
|
+
load_scene,
|
|
19
|
+
load_scene_model,
|
|
20
|
+
resolve_batch,
|
|
21
|
+
)
|
|
14
22
|
|
|
15
23
|
logger = logging.getLogger("simview.cli")
|
|
16
24
|
|
|
@@ -18,7 +26,16 @@ _logging_configured = False
|
|
|
18
26
|
|
|
19
27
|
# Subcommands with their own scoped flags. "view" also works bare
|
|
20
28
|
# (`simview <file>...`) -- see main()'s routing.
|
|
21
|
-
_SUBCOMMANDS = (
|
|
29
|
+
_SUBCOMMANDS = (
|
|
30
|
+
"view",
|
|
31
|
+
"info",
|
|
32
|
+
"diff",
|
|
33
|
+
"terrain",
|
|
34
|
+
"sample",
|
|
35
|
+
"render",
|
|
36
|
+
"clear",
|
|
37
|
+
"static-viewer",
|
|
38
|
+
)
|
|
22
39
|
|
|
23
40
|
|
|
24
41
|
def _configure_logging() -> None:
|
|
@@ -93,18 +110,31 @@ def export_static_viewer(directory: Path) -> None:
|
|
|
93
110
|
logger.info("Static viewer written to %s", directory)
|
|
94
111
|
|
|
95
112
|
|
|
96
|
-
def
|
|
113
|
+
def _print_result(result: dict, args: argparse.Namespace, text_fn, csv_fn=None):
|
|
114
|
+
"""Print `result` as CSV, JSON (`--json`; single-line with `--full`, whose
|
|
115
|
+
grids would otherwise print one number per line) or text."""
|
|
116
|
+
if csv_fn is not None and getattr(args, "csv", False):
|
|
117
|
+
print(csv_fn(result), end="")
|
|
118
|
+
elif args.json:
|
|
119
|
+
# sample is all short vectors: indented, each number gets its own line.
|
|
120
|
+
compact = getattr(args, "full", False) or args.command == "sample"
|
|
121
|
+
print(dumps_json(result, indent=None if compact else 2))
|
|
122
|
+
else:
|
|
123
|
+
print(text_fn(result))
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def run_info(path: Path, as_json: bool, full: bool = False) -> None:
|
|
97
127
|
"""Print a structural summary of the scene JSON at `path` to stdout."""
|
|
98
128
|
from simview.info import format_text, summarize_scene
|
|
99
129
|
|
|
100
130
|
try:
|
|
101
|
-
summary = summarize_scene(path)
|
|
131
|
+
summary = summarize_scene(path, full=full)
|
|
102
132
|
except (json.JSONDecodeError, ValueError, KeyError) as e:
|
|
103
133
|
logger.error("Error: Could not parse '%s' as a scene file: %s", path, e)
|
|
104
134
|
sys.exit(1)
|
|
105
135
|
|
|
106
136
|
if as_json:
|
|
107
|
-
print(
|
|
137
|
+
print(dumps_json(summary, indent=2))
|
|
108
138
|
else:
|
|
109
139
|
print(format_text(summary))
|
|
110
140
|
|
|
@@ -128,10 +158,12 @@ def run_terrain(path: Path, args: argparse.Namespace) -> None:
|
|
|
128
158
|
diff_mode = args.batches is not None
|
|
129
159
|
|
|
130
160
|
try:
|
|
161
|
+
mask = terrain_mod.parse_mask(args.mask) if args.mask else None
|
|
131
162
|
if args.along_body is not None:
|
|
132
163
|
model_data, states_data = load_scene(path)
|
|
164
|
+
batch = resolve_batch(model_data, args.batch, "--batch")
|
|
133
165
|
if diff_mode:
|
|
134
|
-
batch_a, batch_b = args.batches
|
|
166
|
+
batch_a, batch_b = _resolve_batch_pair(model_data, args.batches)
|
|
135
167
|
result = terrain_mod.query_along_body_diff(
|
|
136
168
|
model_data,
|
|
137
169
|
states_data,
|
|
@@ -140,6 +172,8 @@ def run_terrain(path: Path, args: argparse.Namespace) -> None:
|
|
|
140
172
|
batch_b,
|
|
141
173
|
args.layer,
|
|
142
174
|
args.every,
|
|
175
|
+
args.t0,
|
|
176
|
+
args.t1,
|
|
143
177
|
)
|
|
144
178
|
text_fn = terrain_mod.format_along_diff_text
|
|
145
179
|
csv_fn = terrain_mod.format_along_diff_csv
|
|
@@ -149,15 +183,18 @@ def run_terrain(path: Path, args: argparse.Namespace) -> None:
|
|
|
149
183
|
states_data,
|
|
150
184
|
args.along_body,
|
|
151
185
|
args.layer,
|
|
152
|
-
|
|
186
|
+
batch,
|
|
153
187
|
args.every,
|
|
188
|
+
args.t0,
|
|
189
|
+
args.t1,
|
|
154
190
|
)
|
|
155
191
|
text_fn = terrain_mod.format_along_text
|
|
156
192
|
csv_fn = terrain_mod.format_along_csv
|
|
157
193
|
else:
|
|
158
194
|
model_data = load_scene_model(path)
|
|
195
|
+
batch = resolve_batch(model_data, args.batch, "--batch")
|
|
159
196
|
if diff_mode:
|
|
160
|
-
batch_a, batch_b = args.batches
|
|
197
|
+
batch_a, batch_b = _resolve_batch_pair(model_data, args.batches)
|
|
161
198
|
if args.point is not None:
|
|
162
199
|
result = terrain_mod.query_point_diff(
|
|
163
200
|
model_data,
|
|
@@ -172,36 +209,86 @@ def run_terrain(path: Path, args: argparse.Namespace) -> None:
|
|
|
172
209
|
else:
|
|
173
210
|
bounds = tuple(args.area) if args.area else None
|
|
174
211
|
result = terrain_mod.query_area_diff(
|
|
175
|
-
model_data,
|
|
212
|
+
model_data,
|
|
213
|
+
bounds,
|
|
214
|
+
batch_a,
|
|
215
|
+
batch_b,
|
|
216
|
+
args.layer,
|
|
217
|
+
args.stride,
|
|
218
|
+
mask,
|
|
176
219
|
)
|
|
220
|
+
if not args.full:
|
|
221
|
+
result = terrain_mod.area_summary(result)
|
|
177
222
|
text_fn = terrain_mod.format_area_diff_text
|
|
178
223
|
csv_fn = terrain_mod.format_area_diff_csv
|
|
179
224
|
elif args.point is not None:
|
|
180
225
|
result = terrain_mod.query_point(
|
|
181
|
-
model_data, args.point[0], args.point[1], args.layer,
|
|
226
|
+
model_data, args.point[0], args.point[1], args.layer, batch
|
|
182
227
|
)
|
|
183
228
|
text_fn = terrain_mod.format_point_text
|
|
184
229
|
csv_fn = terrain_mod.format_point_csv
|
|
185
230
|
else:
|
|
186
231
|
bounds = tuple(args.area) if args.area else None
|
|
187
232
|
result = terrain_mod.query_area(
|
|
188
|
-
model_data, bounds, args.layer,
|
|
233
|
+
model_data, bounds, args.layer, batch, args.stride, mask
|
|
189
234
|
)
|
|
235
|
+
if not args.full:
|
|
236
|
+
result = terrain_mod.area_summary(result)
|
|
190
237
|
text_fn = terrain_mod.format_area_text
|
|
191
238
|
csv_fn = terrain_mod.format_area_csv
|
|
192
239
|
except (json.JSONDecodeError, ValueError, KeyError) as e:
|
|
193
240
|
logger.error("Error: %s", e)
|
|
194
241
|
sys.exit(1)
|
|
195
242
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
243
|
+
_print_result(result, args, text_fn, csv_fn)
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def _resolve_batch_pair(model_data: dict, specs) -> tuple[int, int]:
|
|
247
|
+
return (
|
|
248
|
+
resolve_batch(model_data, specs[0], "--batches A"),
|
|
249
|
+
resolve_batch(model_data, specs[1], "--batches B"),
|
|
250
|
+
)
|
|
202
251
|
|
|
203
252
|
|
|
204
|
-
def
|
|
253
|
+
def _load_inputs(specs: list[str], args: argparse.Namespace) -> tuple[dict, list]:
|
|
254
|
+
"""`(model, states)` for one scene file, or for several files (or one
|
|
255
|
+
with a '#<batches>' selection) merged into one scene, as `view` does."""
|
|
256
|
+
from simview.merge import merge_simulation_files, split_batch_spec
|
|
257
|
+
|
|
258
|
+
split = [split_batch_spec(spec) for spec in specs]
|
|
259
|
+
paths = [_resolve_input(spec, args) for spec, _ in split]
|
|
260
|
+
selections = [selector for _, selector in split]
|
|
261
|
+
if len(paths) == 1 and selections[0] is None:
|
|
262
|
+
return load_scene(paths[0])
|
|
263
|
+
merged = merge_simulation_files(paths, selections)
|
|
264
|
+
return merged["model"], merged["states"]
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
def run_sample(args: argparse.Namespace) -> None:
|
|
268
|
+
"""Print poses/velocities/contacts/scalars at chosen frames or times."""
|
|
269
|
+
from simview import sample as sample_mod
|
|
270
|
+
|
|
271
|
+
try:
|
|
272
|
+
model_data, states_data = _load_inputs(args.files, args)
|
|
273
|
+
batches = (
|
|
274
|
+
[resolve_batch(model_data, b, "--batch") for b in args.batch]
|
|
275
|
+
if args.batch
|
|
276
|
+
else None
|
|
277
|
+
)
|
|
278
|
+
frames = sample_mod.select_frames(states_data, args.frames, args.t, args.count)
|
|
279
|
+
result = sample_mod.sample_states(
|
|
280
|
+
model_data, states_data, frames, body=args.body, batches=batches
|
|
281
|
+
)
|
|
282
|
+
except (json.JSONDecodeError, ValueError, KeyError) as e:
|
|
283
|
+
logger.error("Error: %s", e)
|
|
284
|
+
sys.exit(1)
|
|
285
|
+
|
|
286
|
+
_print_result(
|
|
287
|
+
result, args, sample_mod.format_sample_text, sample_mod.format_sample_csv
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
def run_diff(args: argparse.Namespace) -> None:
|
|
205
292
|
"""Print a trajectory divergence report between two batches of the scene
|
|
206
293
|
JSON at `path`, to stdout. With `--fail-on-exceed`, additionally exits
|
|
207
294
|
with a non-zero code once printing is done: 0 = within thresholds, 1 =
|
|
@@ -209,12 +296,6 @@ def run_diff(path: Path, args: argparse.Namespace) -> None:
|
|
|
209
296
|
help text)."""
|
|
210
297
|
from simview import diff as diff_mod
|
|
211
298
|
|
|
212
|
-
if args.batches is None:
|
|
213
|
-
logger.error(
|
|
214
|
-
"Error: 'simview diff' requires --batches A B, e.g. 'simview diff "
|
|
215
|
-
"scene.json --batches 0 1'."
|
|
216
|
-
)
|
|
217
|
-
sys.exit(1)
|
|
218
299
|
if (
|
|
219
300
|
args.fail_on_exceed
|
|
220
301
|
and args.pos_threshold is None
|
|
@@ -227,28 +308,36 @@ def run_diff(path: Path, args: argparse.Namespace) -> None:
|
|
|
227
308
|
sys.exit(1)
|
|
228
309
|
|
|
229
310
|
try:
|
|
230
|
-
model_data, states_data =
|
|
311
|
+
model_data, states_data = _load_inputs(args.files, args)
|
|
312
|
+
if args.batches is not None:
|
|
313
|
+
batch_a, batch_b = _resolve_batch_pair(model_data, args.batches)
|
|
314
|
+
elif int(model_data.get("simBatches") or 1) == 2:
|
|
315
|
+
batch_a, batch_b = 0, 1
|
|
316
|
+
else:
|
|
317
|
+
raise ValueError(
|
|
318
|
+
"--batches A B is required unless the scene (or the merged "
|
|
319
|
+
"inputs) has exactly 2 batches, e.g. 'simview diff scene.json "
|
|
320
|
+
"--batches GT 1' or 'simview diff gt.json#0 pred.json#0'"
|
|
321
|
+
)
|
|
231
322
|
result = diff_mod.compute_trajectory_diff(
|
|
232
323
|
model_data,
|
|
233
324
|
states_data,
|
|
234
|
-
|
|
235
|
-
|
|
325
|
+
batch_a,
|
|
326
|
+
batch_b,
|
|
236
327
|
body=args.body,
|
|
237
328
|
every=args.every,
|
|
238
329
|
pos_threshold=args.pos_threshold,
|
|
239
330
|
rot_threshold_deg=args.rot_threshold_deg,
|
|
240
331
|
per_axis=args.per_axis,
|
|
332
|
+
t0=args.t0,
|
|
333
|
+
t1=args.t1,
|
|
334
|
+
align_first_frame=args.align_first_frame,
|
|
241
335
|
)
|
|
242
336
|
except (json.JSONDecodeError, ValueError, KeyError) as e:
|
|
243
337
|
logger.error("Error: %s", e)
|
|
244
338
|
sys.exit(1)
|
|
245
339
|
|
|
246
|
-
|
|
247
|
-
print(diff_mod.format_diff_csv(result), end="")
|
|
248
|
-
elif args.json:
|
|
249
|
-
print(json.dumps(result, indent=2))
|
|
250
|
-
else:
|
|
251
|
-
print(diff_mod.format_diff_text(result))
|
|
340
|
+
_print_result(result, args, diff_mod.format_diff_text, diff_mod.format_diff_csv)
|
|
252
341
|
|
|
253
342
|
if args.fail_on_exceed:
|
|
254
343
|
exceeded = any(
|
|
@@ -260,10 +349,71 @@ def run_diff(path: Path, args: argparse.Namespace) -> None:
|
|
|
260
349
|
sys.exit(2)
|
|
261
350
|
|
|
262
351
|
|
|
352
|
+
# Mirrors BatchManager.js: batches sit on a ceil(sqrt(B))-wide grid of
|
|
353
|
+
# terrain-sized cells, 0.5 m apart, batch 0 at the origin cell.
|
|
354
|
+
_BATCH_SPACING = 0.5
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
def _top_camera(model: dict, batch: int | None):
|
|
358
|
+
"""`(cam, tgt)` looking straight down on one batch's terrain cell, or on
|
|
359
|
+
the whole batch grid when `batch` is None."""
|
|
360
|
+
terrain = model.get("terrain") or {}
|
|
361
|
+
bounds, dims = terrain.get("bounds"), terrain.get("dimensions")
|
|
362
|
+
if not bounds or not dims:
|
|
363
|
+
raise ValueError("--camera top needs a scene with terrain")
|
|
364
|
+
batches = int(model.get("simBatches") or 1)
|
|
365
|
+
side = math.ceil(math.sqrt(batches))
|
|
366
|
+
step_x = dims["sizeX"] + _BATCH_SPACING
|
|
367
|
+
step_y = dims["sizeY"] + _BATCH_SPACING
|
|
368
|
+
if batch is None:
|
|
369
|
+
cols, rows = min(side, batches), math.ceil(batches / side)
|
|
370
|
+
off_x, off_y = (cols - 1) * step_x / 2, (rows - 1) * step_y / 2
|
|
371
|
+
size_x, size_y = cols * step_x, rows * step_y
|
|
372
|
+
else:
|
|
373
|
+
off_x, off_y = (batch % side) * step_x, (batch // side) * step_y
|
|
374
|
+
size_x, size_y = dims["sizeX"], dims["sizeY"]
|
|
375
|
+
cx = (bounds["minX"] + bounds["maxX"]) / 2 + off_x
|
|
376
|
+
cy = (bounds["minY"] + bounds["maxY"]) / 2 + off_y
|
|
377
|
+
extent = max(size_x, size_y)
|
|
378
|
+
# Nudged off-vertical: z is up, and an exactly vertical view leaves the
|
|
379
|
+
# orbit camera's up vector undefined.
|
|
380
|
+
cam = (cx, cy - 1e-3 * extent, (bounds.get("maxZ") or 0.0) + 1.5 * extent)
|
|
381
|
+
return cam, (cx, cy, bounds.get("minZ") or 0.0)
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
def _render_view_hash(path: Path, args: argparse.Namespace, t: float | None) -> str:
|
|
385
|
+
"""View hash for one `simview render` shot from its shortcut flags."""
|
|
386
|
+
from simview.view import view_hash
|
|
387
|
+
|
|
388
|
+
cam = tgt = None
|
|
389
|
+
batch = None
|
|
390
|
+
if args.camera == "top" or args.batch is not None:
|
|
391
|
+
model = load_scene_model(path)
|
|
392
|
+
if args.batch is not None:
|
|
393
|
+
batch = resolve_batch(model, args.batch, "--batch")
|
|
394
|
+
if args.camera == "top":
|
|
395
|
+
cam, tgt = _top_camera(model, batch)
|
|
396
|
+
return view_hash(
|
|
397
|
+
t=t,
|
|
398
|
+
cam=cam,
|
|
399
|
+
tgt=tgt,
|
|
400
|
+
batch=batch,
|
|
401
|
+
track=args.track,
|
|
402
|
+
terrain_color_mode=args.terrain_color,
|
|
403
|
+
ui=False if args.hide_ui else None,
|
|
404
|
+
)
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
def _shot_path(output: Path, t: float, count: int) -> Path:
|
|
408
|
+
if count == 1:
|
|
409
|
+
return output
|
|
410
|
+
return output.with_name(f"{output.stem}_t{t}{output.suffix}")
|
|
411
|
+
|
|
412
|
+
|
|
263
413
|
def run_render(path: Path, args: argparse.Namespace) -> None:
|
|
264
|
-
"""Headlessly render
|
|
414
|
+
"""Headlessly render PNG screenshot(s) of the scene JSON at `path`, for
|
|
265
415
|
generating figures from a display-less environment (e.g. a SLURM job)."""
|
|
266
|
-
from simview.render import
|
|
416
|
+
from simview.render import render_screenshots
|
|
267
417
|
|
|
268
418
|
if args.output is None:
|
|
269
419
|
logger.error(
|
|
@@ -271,20 +421,48 @@ def run_render(path: Path, args: argparse.Namespace) -> None:
|
|
|
271
421
|
"scene.json --output frame.png'."
|
|
272
422
|
)
|
|
273
423
|
sys.exit(1)
|
|
424
|
+
shortcuts = (
|
|
425
|
+
args.t,
|
|
426
|
+
args.camera,
|
|
427
|
+
args.track,
|
|
428
|
+
args.batch,
|
|
429
|
+
args.terrain_color,
|
|
430
|
+
args.hide_ui or None,
|
|
431
|
+
)
|
|
432
|
+
if args.view is not None and any(v is not None for v in shortcuts):
|
|
433
|
+
logger.error(
|
|
434
|
+
"Error: --view can't be combined with --t/--camera/--track/--batch/"
|
|
435
|
+
"--terrain-color/--hide-ui; put everything in the hash, or use the "
|
|
436
|
+
"flags only."
|
|
437
|
+
)
|
|
438
|
+
sys.exit(1)
|
|
274
439
|
|
|
440
|
+
output = Path(args.output)
|
|
275
441
|
try:
|
|
276
|
-
|
|
442
|
+
if args.view is not None:
|
|
443
|
+
shots = [(args.view, output)]
|
|
444
|
+
elif any(v is not None for v in shortcuts):
|
|
445
|
+
times = list(dict.fromkeys(args.t or [None]))
|
|
446
|
+
shots = [
|
|
447
|
+
(_render_view_hash(path, args, t), _shot_path(output, t, len(times)))
|
|
448
|
+
for t in times
|
|
449
|
+
]
|
|
450
|
+
else:
|
|
451
|
+
shots = [(None, output)]
|
|
452
|
+
render_screenshots(
|
|
277
453
|
path,
|
|
278
|
-
|
|
454
|
+
shots,
|
|
279
455
|
host=args.host,
|
|
280
456
|
port=args.port,
|
|
281
|
-
view=args.view,
|
|
282
457
|
width=args.width,
|
|
283
458
|
height=args.height,
|
|
284
459
|
)
|
|
285
460
|
except ImportError as e:
|
|
286
461
|
logger.error("Error: %s", e)
|
|
287
462
|
sys.exit(1)
|
|
463
|
+
except ValueError as e:
|
|
464
|
+
logger.error("Error: %s", e)
|
|
465
|
+
sys.exit(1)
|
|
288
466
|
except (RuntimeError, TimeoutError) as e:
|
|
289
467
|
logger.error("Error: 'simview render' failed: %s", e)
|
|
290
468
|
sys.exit(1)
|
|
@@ -315,7 +493,7 @@ def save_merged(
|
|
|
315
493
|
columnar_states = columnarize_states(merged["states"], merged["model"], inline_blob)
|
|
316
494
|
if columnar_states is not None:
|
|
317
495
|
merged["states"] = columnar_states
|
|
318
|
-
payload =
|
|
496
|
+
payload = dumps_json(merged).encode("utf-8")
|
|
319
497
|
if out_path.suffix == ".gz":
|
|
320
498
|
payload = gzip.compress(payload, compresslevel=1)
|
|
321
499
|
try:
|
|
@@ -405,6 +583,36 @@ def _add_host_port_flags(sp: argparse.ArgumentParser) -> None:
|
|
|
405
583
|
)
|
|
406
584
|
|
|
407
585
|
|
|
586
|
+
def _add_files_arg(sp: argparse.ArgumentParser) -> None:
|
|
587
|
+
sp.add_argument(
|
|
588
|
+
"files",
|
|
589
|
+
nargs="+",
|
|
590
|
+
metavar="file",
|
|
591
|
+
help=(
|
|
592
|
+
"Scene file(s) or 'host:path' specs. Several files -- or one with a "
|
|
593
|
+
"'#<batches>' selection, e.g. 'gt.json#0 pred.json#GT' -- are "
|
|
594
|
+
"merged into one scene first, as 'simview view' does."
|
|
595
|
+
),
|
|
596
|
+
)
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
def _add_time_window_flags(sp: argparse.ArgumentParser, prefix: str) -> None:
|
|
600
|
+
sp.add_argument(
|
|
601
|
+
"--t0",
|
|
602
|
+
type=float,
|
|
603
|
+
default=None,
|
|
604
|
+
metavar="SECONDS",
|
|
605
|
+
help=f"{prefix} use states at or after this time.",
|
|
606
|
+
)
|
|
607
|
+
sp.add_argument(
|
|
608
|
+
"--t1",
|
|
609
|
+
type=float,
|
|
610
|
+
default=None,
|
|
611
|
+
metavar="SECONDS",
|
|
612
|
+
help=f"{prefix} use states at or before this time.",
|
|
613
|
+
)
|
|
614
|
+
|
|
615
|
+
|
|
408
616
|
def _add_file_arg(sp: argparse.ArgumentParser) -> None:
|
|
409
617
|
sp.add_argument(
|
|
410
618
|
"file",
|
|
@@ -471,6 +679,11 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
471
679
|
action="store_true",
|
|
472
680
|
help="Print machine-readable JSON instead of text.",
|
|
473
681
|
)
|
|
682
|
+
info.add_argument(
|
|
683
|
+
"--full",
|
|
684
|
+
action="store_true",
|
|
685
|
+
help="Don't cap lists (bodies, static objects, missing frames) at 20 entries.",
|
|
686
|
+
)
|
|
474
687
|
_add_remote_flags(info)
|
|
475
688
|
|
|
476
689
|
terrain = sub.add_parser(
|
|
@@ -521,7 +734,10 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
521
734
|
),
|
|
522
735
|
)
|
|
523
736
|
terrain.add_argument(
|
|
524
|
-
"--batch",
|
|
737
|
+
"--batch",
|
|
738
|
+
default="0",
|
|
739
|
+
help="Batch to query: an index (negative counts from the end) or a batch "
|
|
740
|
+
"name (default: 0).",
|
|
525
741
|
)
|
|
526
742
|
terrain.add_argument(
|
|
527
743
|
"--stride",
|
|
@@ -532,10 +748,9 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
532
748
|
terrain.add_argument(
|
|
533
749
|
"--batches",
|
|
534
750
|
nargs=2,
|
|
535
|
-
type=int,
|
|
536
751
|
metavar=("A", "B"),
|
|
537
752
|
help=(
|
|
538
|
-
"Two
|
|
753
|
+
"Two batches (indices or names) to compare. Switches into cross-batch diff mode "
|
|
539
754
|
"(value_a/value_b/delta per layer) instead of a single-batch query, "
|
|
540
755
|
"and takes precedence over --batch if both are given. For "
|
|
541
756
|
"--along-body, both batches' terrains are sampled along batch A's "
|
|
@@ -548,17 +763,38 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
548
763
|
default=1,
|
|
549
764
|
help="With --along-body, sample every Nth frame (default: 1).",
|
|
550
765
|
)
|
|
766
|
+
_add_time_window_flags(terrain, "With --along-body, only")
|
|
767
|
+
terrain.add_argument(
|
|
768
|
+
"--mask",
|
|
769
|
+
default=None,
|
|
770
|
+
metavar="EXPR",
|
|
771
|
+
help=(
|
|
772
|
+
"With --area, restrict the statistics to cells passing 'LAYER OP "
|
|
773
|
+
"VALUE' (OP: > >= < <= == !=), e.g. 'known>0.5'. Evaluated on "
|
|
774
|
+
"--batch, or on batch A with --batches."
|
|
775
|
+
),
|
|
776
|
+
)
|
|
777
|
+
terrain.add_argument(
|
|
778
|
+
"--full",
|
|
779
|
+
action="store_true",
|
|
780
|
+
help=(
|
|
781
|
+
"With --area, also print every grid cell (and x/y coordinates). "
|
|
782
|
+
"Default: only the sampled extent and per-layer statistics."
|
|
783
|
+
),
|
|
784
|
+
)
|
|
551
785
|
_add_json_csv_flags(terrain)
|
|
552
786
|
_add_remote_flags(terrain)
|
|
553
787
|
|
|
554
788
|
diff = sub.add_parser("diff", help="Compare two batches' trajectories.")
|
|
555
|
-
|
|
789
|
+
_add_files_arg(diff)
|
|
556
790
|
diff.add_argument(
|
|
557
791
|
"--batches",
|
|
558
792
|
nargs=2,
|
|
559
|
-
type=int,
|
|
560
793
|
metavar=("A", "B"),
|
|
561
|
-
help=
|
|
794
|
+
help=(
|
|
795
|
+
"Two batches (indices or names) to compare. Optional when the scene "
|
|
796
|
+
"-- or the merged inputs -- has exactly 2 batches."
|
|
797
|
+
),
|
|
562
798
|
)
|
|
563
799
|
diff.add_argument(
|
|
564
800
|
"--body",
|
|
@@ -617,9 +853,63 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
617
853
|
"tell divergence apart from a broken invocation."
|
|
618
854
|
),
|
|
619
855
|
)
|
|
856
|
+
_add_time_window_flags(diff, "Only")
|
|
857
|
+
diff.add_argument(
|
|
858
|
+
"--align-first-frame",
|
|
859
|
+
action="store_true",
|
|
860
|
+
help=(
|
|
861
|
+
"Express each batch's trajectory relative to its own pose at the "
|
|
862
|
+
"first compared frame (R0^-1 (p - p0), R0^-1 R), so a constant "
|
|
863
|
+
"start offset isn't counted as error."
|
|
864
|
+
),
|
|
865
|
+
)
|
|
620
866
|
_add_json_csv_flags(diff)
|
|
621
867
|
_add_remote_flags(diff)
|
|
622
868
|
|
|
869
|
+
sample = sub.add_parser(
|
|
870
|
+
"sample",
|
|
871
|
+
help="Print body poses, velocities, contacts and scalars at chosen frames.",
|
|
872
|
+
)
|
|
873
|
+
_add_files_arg(sample)
|
|
874
|
+
sample.add_argument(
|
|
875
|
+
"--frames",
|
|
876
|
+
default=None,
|
|
877
|
+
metavar="SPEC",
|
|
878
|
+
help="A frame index ('-1') or Python slice ('0:2000:100', '::50').",
|
|
879
|
+
)
|
|
880
|
+
sample.add_argument(
|
|
881
|
+
"--t",
|
|
882
|
+
type=float,
|
|
883
|
+
action="append",
|
|
884
|
+
default=None,
|
|
885
|
+
metavar="SECONDS",
|
|
886
|
+
help="Sample the frame nearest this time; repeatable.",
|
|
887
|
+
)
|
|
888
|
+
sample.add_argument(
|
|
889
|
+
"--count",
|
|
890
|
+
type=int,
|
|
891
|
+
default=11,
|
|
892
|
+
help=(
|
|
893
|
+
"Without --frames/--t, sample this many evenly spaced frames, first "
|
|
894
|
+
"and last included (default: 11)."
|
|
895
|
+
),
|
|
896
|
+
)
|
|
897
|
+
sample.add_argument(
|
|
898
|
+
"--body",
|
|
899
|
+
default=None,
|
|
900
|
+
metavar="NAME",
|
|
901
|
+
help="Only this body (matched like 'simview diff --body'). Default: all.",
|
|
902
|
+
)
|
|
903
|
+
sample.add_argument(
|
|
904
|
+
"--batch",
|
|
905
|
+
action="append",
|
|
906
|
+
default=None,
|
|
907
|
+
metavar="BATCH",
|
|
908
|
+
help="Only this batch (index or name); repeatable. Default: all.",
|
|
909
|
+
)
|
|
910
|
+
_add_json_csv_flags(sample)
|
|
911
|
+
_add_remote_flags(sample)
|
|
912
|
+
|
|
623
913
|
render = sub.add_parser(
|
|
624
914
|
"render", help="Headlessly save a PNG screenshot (needs the 'render' extra)."
|
|
625
915
|
)
|
|
@@ -644,6 +934,45 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
644
934
|
"viewer's startup state."
|
|
645
935
|
),
|
|
646
936
|
)
|
|
937
|
+
render.add_argument(
|
|
938
|
+
"--t",
|
|
939
|
+
type=float,
|
|
940
|
+
action="append",
|
|
941
|
+
default=None,
|
|
942
|
+
metavar="SECONDS",
|
|
943
|
+
help=(
|
|
944
|
+
"Playback time to capture; repeatable -- several times are captured "
|
|
945
|
+
"in one browser session, saved as <output stem>_t<T>.png."
|
|
946
|
+
),
|
|
947
|
+
)
|
|
948
|
+
render.add_argument(
|
|
949
|
+
"--camera",
|
|
950
|
+
choices=["top"],
|
|
951
|
+
default=None,
|
|
952
|
+
help="Camera preset: 'top' looks straight down on the whole terrain.",
|
|
953
|
+
)
|
|
954
|
+
render.add_argument(
|
|
955
|
+
"--track",
|
|
956
|
+
default=None,
|
|
957
|
+
metavar="BODY",
|
|
958
|
+
help="Have the camera follow this body.",
|
|
959
|
+
)
|
|
960
|
+
render.add_argument(
|
|
961
|
+
"--batch",
|
|
962
|
+
default=None,
|
|
963
|
+
help="Focus this batch (index or name).",
|
|
964
|
+
)
|
|
965
|
+
render.add_argument(
|
|
966
|
+
"--terrain-color",
|
|
967
|
+
default=None,
|
|
968
|
+
metavar="MODE",
|
|
969
|
+
help="Color the terrain by 'height' or a property name (e.g. 'friction').",
|
|
970
|
+
)
|
|
971
|
+
render.add_argument(
|
|
972
|
+
"--hide-ui",
|
|
973
|
+
action="store_true",
|
|
974
|
+
help="Hide every panel, leaving only the 3D view.",
|
|
975
|
+
)
|
|
647
976
|
render.add_argument(
|
|
648
977
|
"--width",
|
|
649
978
|
type=int,
|
|
@@ -719,11 +1048,16 @@ def main():
|
|
|
719
1048
|
return
|
|
720
1049
|
|
|
721
1050
|
single_file_commands = {
|
|
722
|
-
"info": lambda path, args: run_info(path, as_json=args.json),
|
|
1051
|
+
"info": lambda path, args: run_info(path, as_json=args.json, full=args.full),
|
|
723
1052
|
"terrain": run_terrain,
|
|
724
|
-
"diff": run_diff,
|
|
725
1053
|
"render": run_render,
|
|
726
1054
|
}
|
|
1055
|
+
if args.command == "diff":
|
|
1056
|
+
run_diff(args)
|
|
1057
|
+
return
|
|
1058
|
+
if args.command == "sample":
|
|
1059
|
+
run_sample(args)
|
|
1060
|
+
return
|
|
727
1061
|
if args.command in single_file_commands:
|
|
728
1062
|
single_file_commands[args.command](_resolve_input(args.file, args), args)
|
|
729
1063
|
return
|
|
@@ -764,5 +1098,22 @@ def main():
|
|
|
764
1098
|
sys.exit(1)
|
|
765
1099
|
|
|
766
1100
|
|
|
1101
|
+
def cli() -> None:
|
|
1102
|
+
"""Console-script entry point: `main()`, quiet when stdout is closed early
|
|
1103
|
+
(e.g. `simview terrain ... | head`)."""
|
|
1104
|
+
try:
|
|
1105
|
+
try:
|
|
1106
|
+
main()
|
|
1107
|
+
finally:
|
|
1108
|
+
# Also on sys.exit (e.g. diff --fail-on-exceed), so a closed pipe
|
|
1109
|
+
# surfaces here rather than in the interpreter's exit-time flush.
|
|
1110
|
+
sys.stdout.flush()
|
|
1111
|
+
except BrokenPipeError:
|
|
1112
|
+
# Point stdout at devnull so the interpreter's own exit-time flush
|
|
1113
|
+
# doesn't raise a second time.
|
|
1114
|
+
os.dup2(os.open(os.devnull, os.O_WRONLY), sys.stdout.fileno())
|
|
1115
|
+
sys.exit(1)
|
|
1116
|
+
|
|
1117
|
+
|
|
767
1118
|
if __name__ == "__main__":
|
|
768
|
-
|
|
1119
|
+
cli()
|