Datasets:
Formats:
csv
Languages:
English
Size:
< 1K
Tags:
robotics
embodied-ai
human-demonstration
egocentric-video
bimanual-manipulation
tactile-sensing
License:
File size: 4,440 Bytes
9ff4bea | 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 | """
Helper functions for Rerun scripts.
These helper functions can be used to wire up common Rerun features to your script CLi arguments.
Example
-------
```python
import argparse
import rerun as rr
parser = argparse.ArgumentParser()
rr.script_add_args(parser)
args = parser.parse_args()
rr.script_setup(args, "rerun_example_application")
# … Run your logging code here …
rr.script_teardown(args)
```
"""
from __future__ import annotations
from typing import TYPE_CHECKING
import rerun as rr
if TYPE_CHECKING:
from argparse import ArgumentParser, Namespace
from uuid import UUID
from rerun.recording_stream import RecordingStream
def script_add_args(parser: ArgumentParser) -> None:
"""
Add common Rerun script arguments to `parser`.
Parameters
----------
parser:
The parser to add arguments to.
"""
parser.add_argument("--headless", action="store_true", help="Don't show GUI")
parser.add_argument(
"--connect",
dest="connect",
action="store_true",
help="Connect to an external viewer",
)
parser.add_argument(
"--serve",
dest="serve",
action="store_true",
help="Host a GRPC & web server and open a web viewer connecting to it.",
)
parser.add_argument("--url", type=str, default=None, help="Connect to this Rerun URL")
parser.add_argument("--save", type=str, default=None, help="Save data to a .rrd file at this path")
parser.add_argument(
"--stdout",
dest="stdout",
action="store_true",
help="Log data to standard output, to be piped into a Rerun Viewer",
)
def script_setup(
args: Namespace,
application_id: str,
*,
recording_id: str | UUID | None = None,
default_blueprint: rr.blueprint.BlueprintLike | None = None,
) -> RecordingStream:
"""
Run common Rerun script setup actions. Connect to the viewer if necessary.
Parameters
----------
args:
The parsed arguments from `parser.parse_args()`.
application_id:
The application ID to use for the viewer.
recording_id:
Set the recording ID that this process is logging to, as a UUIDv4.
The default recording_id is based on `multiprocessing.current_process().authkey`
which means that all processes spawned with `multiprocessing`
will have the same default recording_id.
If you are not using `multiprocessing` and still want several different Python
processes to log to the same Rerun instance (and be part of the same recording),
you will need to manually assign them all the same recording_id.
Any random UUIDv4 will work, or copy the recording id for the parent process.
default_blueprint:
Optionally set a default blueprint to use for this application. If the application
already has an active blueprint, the new blueprint won't become active until the user
clicks the "reset blueprint" button. If you want to activate the new blueprint
immediately, instead use the [`rerun.send_blueprint`][] API.
"""
rr.init(
application_id=application_id,
recording_id=recording_id,
default_enabled=True,
strict=True,
)
rec = rr.get_global_data_recording()
assert rec is not None, "`rr.init` sets a global recording"
if args.stdout:
rec.stdout(default_blueprint=default_blueprint)
elif args.serve:
connect_to = rec.serve_grpc(default_blueprint=default_blueprint)
rr.serve_web_viewer(open_browser=True, connect_to=connect_to)
elif args.connect:
# Send logging data to separate `rerun` process.
# You can omit the argument to connect to the default URL.
rec.connect_grpc(args.url, default_blueprint=default_blueprint)
elif args.save is not None:
rec.save(args.save, default_blueprint=default_blueprint)
elif not args.headless:
rec.spawn(default_blueprint=default_blueprint)
return rec
def script_teardown(args: Namespace) -> None:
"""
Run common post-actions. Sleep if serving the web viewer.
Parameters
----------
args:
The parsed arguments from `parser.parse_args()`.
"""
if args.serve:
import time
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
print("Ctrl-C received. Exiting.")
|