Skip to content
esc
Start typing to search the docs
Navigate Open

Send user-defined data

Rerun comes with many pre-built Types that you can use out of the box. As long as your own data can be decomposed into Rerun components or can be serialized with Apache Arrow, you can log it directly without needing to recompile Rerun.

For Python and Rust we have helpers for this, called AnyValues, allowing you to easily attach custom values to any entity. For C++ a similar thing can be accomplished without the helpers. You find the documentation for these helpers here:

"""Log arbitrary data."""

import rerun as rr

rr.init("rerun_example_any_values", spawn=True)

rr.log(
    "any_values",
    rr
    .AnyValues(
        # Using arbitrary Arrow data.
        homepage="https://www.rerun.io",
        repository="https://github.com/rerun-io/rerun",
    )
    # Using Rerun's builtin components.
    .with_component_override(
        "confidence", rr.components.ScalarBatch._COMPONENT_TYPE, [1.2, 3.4, 5.6]
    )
    .with_component_override(
        "description", rr.components.TextBatch._COMPONENT_TYPE, "Bla bla bla…"
    ),
)

If your values should be grouped together and that grouping isn't referred to from many places that need to stay aligned we have a helper for this called DynamicArchetype, which adds some structural grouping to multiple values. DynamicArchetype stores the values under an archetype name of your choice. The confidence field of MyArchetype becomes the column MyArchetype:confidence. AnyValues stores no archetype name, so the same field becomes the column confidence.

You find the documentation for these helpers here:

"""Log arbitrary archetype data."""

import rerun as rr

rr.init("rerun_example_dynamic_archetype", spawn=True)

rr.log(
    "new_archetype",
    rr
    .DynamicArchetype(
        archetype="MyArchetype",
        components={
            # Using arbitrary Arrow data.
            "homepage": "https://www.rerun.io",
            "repository": "https://github.com/rerun-io/rerun",
        },
    )
    # Using Rerun's builtin components.
    .with_component_override(
        "confidence", rr.components.ScalarBatch._COMPONENT_TYPE, [1.2, 3.4, 5.6]
    )
    .with_component_override(
        "description", rr.components.TextBatch._COMPONENT_TYPE, "Bla bla bla…"
    ),
)

You can also make your own type loggable by implementing the AsComponents Python protocol or Rust trait, which means implementing the function, as_component_batches().

Logging custom data

Use DynamicArchetype to send data with custom component names alongside regular Rerun data. Flat arrays and Arrow StructArrays are both supported.

The example below logs scalar and nested data to an entity named /plot. This is how its components appear in the Viewer:

Data overview for the /plot entity showing scalar, custom, and nested components
# Custom scalar batch with a cos using a custom component name.
*rr.DynamicArchetype.columns(
    archetype="custom",
    components={"my_custom_scalar": np.cos(times / 10.0)},
),
# Nested custom scalar batch with a sigmoid inside a struct.
*rr.DynamicArchetype.columns(
    archetype="custom",
    components={"my_nested_scalar": make_sigmoid_struct_array(64)},
),

Remapping to a Rerun archetype

Let's start with a simple example where you have your own point cloud class that is perfectly representable as a Rerun archetype.

@dataclass
class LabeledPoints:
    points: np.ndarray
    labels: list[str]

If you implement as_component_batches() on LabeledPoints, you can pass it directly to rr.log. The simplest possible way is to use the matching Rerun archetype’s as_component_batches method.

import rerun as rr  # pip install rerun-sdk


@dataclass
class LabeledPoints:
    points: np.ndarray
    labels: list[str]

    def as_component_batches(self) -> list[rr.DescribedComponentBatch]:
        return rr.Points3D(
            positions=self.points, labels=self.labels
        ).as_component_batches()

Then pass it to rr.log like any archetype:

# Somewhere deep in your code
classified = my_points_classifier()
rr.log("points/classified", classified)

Custom archetypes and components

You can also define and log your own custom archetypes and components completely from user code, without rebuilding Rerun.

In this example we extend the Rerun Points3D archetype with a custom confidence component and user-defined archetype.

This is what it looks like in the dataframe view:

"""Shows how to implement custom archetypes and components."""

from __future__ import annotations

import argparse
from typing import Any

import numpy as np
import numpy.typing as npt
import pyarrow as pa

import rerun as rr


class ConfidenceBatch(rr.ComponentBatchMixin):  # type: ignore[misc]
    """A batch of confidence data."""

    def __init__(self: Any, confidence: npt.ArrayLike) -> None:
        self.confidence = confidence

    def as_arrow_array(self) -> pa.Array:
        """The arrow batch representing the custom component."""
        return pa.array(self.confidence, type=pa.float32())


class CustomPoints3D(rr.AsComponents):  # type: ignore[misc]
    """A custom archetype extending the builtin `Points3D` with extra data."""

    def __init__(
        self: Any, positions: npt.ArrayLike, confidences: npt.ArrayLike
    ) -> None:
        self.points3d = rr.Points3D(positions)
        self.confidences = ConfidenceBatch(confidences).described(
            rr.ComponentDescriptor(
                "user.CustomPoints3D:confidences",
                archetype="user.CustomPoints3D",
                component_type="user.Confidence",
            )
        )

    def as_component_batches(self) -> list[rr.DescribedComponentBatch]:
        return [
            # The components from Points3D
            *self.points3d.as_component_batches(),
            # Custom confidence data
            self.confidences,
        ]


def log_custom_data() -> None:
    lin = np.linspace(-5, 5, 3)
    z, y, x = np.meshgrid(lin, lin, lin, indexing="ij")
    point_grid = np.vstack([x.flatten(), y.flatten(), z.flatten()]).T

    rr.log(
        "left/my_confident_point_cloud",
        CustomPoints3D(
            positions=point_grid,
            confidences=[42],
        ),
    )

    rr.log(
        "right/my_polarized_point_cloud",
        CustomPoints3D(
            positions=point_grid, confidences=np.arange(0, len(point_grid))
        ),
    )


def main() -> None:
    parser = argparse.ArgumentParser(
        description="Logs rich data using the Rerun SDK."
    )
    rr.script_add_args(parser)
    args = parser.parse_args()

    rr.script_setup(args, "rerun_example_custom_data")
    log_custom_data()
    rr.script_teardown(args)


if __name__ == "__main__":
    main()
Dataframe view with Points3D positions and user.CustomPoints3D confidences columns for two custom point cloud entities

The point clouds still show up in a 3D view, because CustomPoints3D also logs the components of the built-in Points3D.

Creating/augmenting visualizations from custom data

All components can be mapped to arbitrary slots of visualizers. For general information on component mapping see component mappings, for the common case of plotting see plot any scalar