Datasets:
Formats:
csv
Languages:
English
Size:
< 1K
Tags:
robotics
embodied-ai
human-demonstration
egocentric-video
bimanual-manipulation
tactile-sensing
License:
File size: 6,894 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 148 149 150 151 152 153 154 155 156 157 | from __future__ import annotations
from ._baseclasses import ComponentColumn, ComponentColumnList, DescribedComponentBatch
from ._log import AsComponents
from .any_batch_value import AnyBatchValue, ComponentValueLike
from .dynamic_archetype import DynamicArchetype
from .error_utils import catch_and_log_exceptions
class AnyValues(AsComponents):
"""
Helper to log arbitrary values as a bundle of components.
Example
-------
```python
rr.log(
"any_values", rr.AnyValues(
confidence=[1.2, 3.4, 5.6],
description="Bla bla bla…",
# URIs will become clickable links
homepage="https://www.rerun.io",
repository="https://github.com/rerun-io/rerun",
),
)
```
"""
def __init__(self, drop_untyped_nones: bool = True, **kwargs: ComponentValueLike | None) -> None:
"""
Construct a new AnyValues bundle.
Each kwarg will be logged as a separate component batch using the provided data.
- The key will be used as the name of the component
- The value must be able to be converted to an array of arrow types. In
general, if you can pass it to [pyarrow.array][] you can log it as a
extension component.
Note: rerun requires that a given component only take on a single type.
The first type logged will be the type that is used for all future logs
of that component. The API will make a best effort to do type conversion
if supported by numpy and arrow. Any components that can't be converted
will result in a warning (or an exception in strict mode).
`None` values provide a particular challenge as they have no type
information until after the component has been logged with a particular
type. By default, these values are dropped. This should generally be
fine as logging `None` to clear the value before it has been logged is
meaningless unless you are logging out-of-order data. In such cases,
consider introducing your own typed component via
[rerun.ComponentBatchLike][].
You can change this behavior by setting `drop_untyped_nones` to `False`,
but be aware that this will result in potential warnings (or exceptions
in strict mode).
If you are want to inspect how your component will be converted to the
underlying arrow code, the following snippet is what is happening
internally:
```
np_value = np.atleast_1d(np.array(value, copy=False))
pa_value = pa.array(value)
```
Parameters
----------
drop_untyped_nones:
If True, any components that are either None or empty will be dropped unless they
have been previously logged with a type.
kwargs:
The components to be logged.
"""
self._builder = DynamicArchetype._default_without_archetype(drop_untyped_nones, **kwargs)
self._builder._with_name(self.__class__.__name__)
def with_component_from_data(
self, descriptor: str, value: ComponentValueLike | None, *, drop_untyped_nones: bool = True
) -> AnyValues:
"""Adds an `AnyValueBatch` to this `AnyValues` bundle."""
self._builder.with_component_from_data(descriptor, value, drop_untyped_nones=drop_untyped_nones)
return self
def with_component_override(
self, field: str, component_type: str, value: ComponentValueLike | None, *, drop_untyped_nones: bool = True
) -> AnyValues:
"""Adds an `AnyValueBatch` to this `AnyValues` bundle with name and component type."""
self._builder.with_component_override(field, component_type, value, drop_untyped_nones=drop_untyped_nones)
return self
def as_component_batches(self) -> list[DescribedComponentBatch]:
return self._builder.as_component_batches()
@classmethod
def columns(cls, drop_untyped_nones: bool = True, **kwargs: ComponentValueLike | None) -> ComponentColumnList:
"""
Construct a new column-oriented AnyValues bundle.
This makes it possible to use `rr.send_columns` to send columnar data directly into Rerun.
The returned columns will be partitioned into unit-length sub-batches by default.
Use `ComponentColumnList.partition` to repartition the data as needed.
Each kwarg will be logged as a separate component column using the provided data.
- The key will be used as the name of the component
- The value must be able to be converted to an array of arrow types. In
general, if you can pass it to [pyarrow.array][] you can log it as a
extension component.
Note: rerun requires that a given component only take on a single type.
The first type logged will be the type that is used for all future logs
of that component. The API will make a best effort to do type conversion
if supported by numpy and arrow. Any components that can't be converted
will result in a warning (or an exception in strict mode).
`None` values provide a particular challenge as they have no type
information until after the component has been logged with a particular
type. By default, these values are dropped. This should generally be
fine as logging `None` to clear the value before it has been logged is
meaningless unless you are logging out-of-order data. In such cases,
consider introducing your own typed component via
[rerun.ComponentBatchLike][].
You can change this behavior by setting `drop_untyped_nones` to `False`,
but be aware that this will result in potential warnings (or exceptions
in strict mode).
If you are want to inspect how your component will be converted to the
underlying arrow code, the following snippet is what is happening
internally:
```
np_value = np.atleast_1d(np.array(value, copy=False))
pa_value = pa.array(value)
```
Parameters
----------
drop_untyped_nones:
If True, any components that are either None or empty will be dropped unless they
have been previously logged with a type.
kwargs:
The components to be logged.
"""
columns: list[ComponentColumn] = []
with catch_and_log_exceptions("AnyValues.columns"):
for name, value in kwargs.items():
col = AnyBatchValue.column(name, value, drop_untyped_nones=drop_untyped_nones)
if col is not None:
columns.append(col)
return ComponentColumnList(columns)
@property
def component_batches(self) -> list[DescribedComponentBatch]:
return self._builder.as_component_batches()
|