File Writers#
Genesis provides file writers for exporting simulation data to various formats.
Available Writers#
Writer |
Format |
Description |
|---|---|---|
|
|
Tabular data export |
|
|
NumPy compressed arrays |
|
|
Video from camera/viewer |
CSVFile#
Export data as comma-separated values:
import genesis as gs
gs.init()
scene = gs.Scene()
robot = scene.add_entity(gs.morphs.URDF(file="robot.urdf"))
scene.build()
# Record joint positions to CSV
scene.start_recording(
data_func=lambda: {
"q0": robot.get_qpos()[0],
"q1": robot.get_qpos()[1],
"q2": robot.get_qpos()[2],
},
rec_options=gs.recorders.CSVFile(
filename="joint_data.csv",
hz=100,
),
)
for i in range(1000):
scene.step()
scene.stop_recording()
NPZFile#
Export data as NumPy compressed archive:
scene.start_recording(
data_func=lambda: {
"pos": robot.get_pos(),
"qpos": robot.get_qpos(),
"qvel": robot.get_qvel(),
},
rec_options=gs.recorders.NPZFile(
filename="trajectory.npz",
hz=50,
),
)
# ... simulation ...
scene.stop_recording()
# Load recorded data
import numpy as np
data = np.load("trajectory.npz")
positions = data["pos"]
VideoFile#
Record video from cameras or viewer:
cam = scene.add_camera(
res=(1280, 720),
pos=(3, 0, 2),
lookat=(0, 0, 0.5),
)
scene.start_recording(
data_func=lambda: cam.render(rgb=True)[0],
rec_options=gs.recorders.VideoFile(
filename="simulation.mp4",
),
)
for i in range(300):
scene.step()
scene.stop_recording()
Configuration Options#
Common Options#
Option |
Type |
Default |
Description |
|---|---|---|---|
|
str |
Required |
Output file path |
|
float |
None |
Recording frequency |
|
bool |
False |
Background processing |
VideoFileWriter Options#
Option |
Type |
Default |
Description |
|---|---|---|---|
|
int |
30 |
Video frame rate |
|
str |
“libx264” |
Video codec |
API Reference#
- class genesis.recorders.file_writers.BaseFileWriter(manager: RecorderManager, options: RecorderOptions, data_func: Callable[[], T])[source]#
Bases:
RecorderBase class for file writers.
Handles filename counter when save_on_reset is True.
- class genesis.recorders.file_writers.VideoFileWriter(manager: RecorderManager, options: RecorderOptions, data_func: Callable[[], T])[source]#
Bases:
BaseFileWriter- video_container: av.container.OutputContainer | None#
- video_stream: av.video.stream.VideoStream | None#
- video_frame: av.video.frame.VideoFrame | None#
- video_buffer: np.ndarray | None#
- build()[source]#
Build the recorder, e.g. by initializing variables and creating widgets or file handles.
- process(data, cur_time)[source]#
Process each incoming data sample.
- Parameters:
data (Any) – The data to be processed.
cur_time (float) – The current time of the simulation.
- cleanup()[source]#
Cleanup all resources, e.g. by closing widgets or files.
This method is called when recording is stopped by scene.stop_recording().
- property run_in_thread: bool#
Whether to run the recorder in a background thread.
Running in a background thread allows for processing data without blocking the main thread, so this is encouraged for most recorders (simply return True), but implementers should check that the recorder is thread-safe on all devices (threading on macOS tends to be less supported).
- class genesis.recorders.file_writers.CSVFileWriter(manager: RecorderManager, options: RecorderOptions, data_func: Callable[[], T])[source]#
Bases:
BaseFileWriter- process(data, cur_time)[source]#
Process each incoming data sample.
- Parameters:
data (Any) – The data to be processed.
cur_time (float) – The current time of the simulation.
- cleanup()[source]#
Cleanup all resources, e.g. by closing widgets or files.
This method is called when recording is stopped by scene.stop_recording().
- property run_in_thread: bool#
Whether to run the recorder in a background thread.
Running in a background thread allows for processing data without blocking the main thread, so this is encouraged for most recorders (simply return True), but implementers should check that the recorder is thread-safe on all devices (threading on macOS tends to be less supported).
- class genesis.recorders.file_writers.NPZFileWriter(manager: RecorderManager, options: RecorderOptions, data_func: Callable[[], T])[source]#
Bases:
BaseFileWriter- build()[source]#
Build the recorder, e.g. by initializing variables and creating widgets or file handles.
- process(data, cur_time)[source]#
Process each incoming data sample.
- Parameters:
data (Any) – The data to be processed.
cur_time (float) – The current time of the simulation.
- cleanup()[source]#
Cleanup all resources, e.g. by closing widgets or files.
This method is called when recording is stopped by scene.stop_recording().
- property run_in_thread: bool#
Whether to run the recorder in a background thread.
Running in a background thread allows for processing data without blocking the main thread, so this is encouraged for most recorders (simply return True), but implementers should check that the recorder is thread-safe on all devices (threading on macOS tends to be less supported).
See Also#
Recording & Playback - Recording overview
Plotters - Real-time visualization