Skip to content

Commit db82cd3

Browse files
committed
add python example
1 parent 1082d43 commit db82cd3

File tree

5 files changed

+431
-331
lines changed

5 files changed

+431
-331
lines changed
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
This example will query for the first 10 rows of data in your recording of choice,
2+
and display the results as a table in your terminal.
3+
4+
You can use one of your recordings, or grab one from our hosted examples, e.g.:
5+
```bash
6+
curl 'https://app.rerun.io/version/latest/examples/dna.rrd' -o - > /tmp/dna.rrd
7+
```
8+
9+
The results can be filtered further by specifying an entity filter expression:
10+
```bash
11+
python dataframe_query.py my_recording.rrd /skeleton/left_shoulder/**\
12+
```
13+
14+
```bash
15+
python dataframe_query.py <path_to_rrd> [entity_path_filter]
16+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python3
2+
"""Demonstrates basic usage of the dataframe APIs."""
3+
4+
from __future__ import annotations
5+
6+
import argparse
7+
8+
import pyarrow as pa
9+
import rerun as rr
10+
11+
DESCRIPTION = """
12+
Usage: python dataframe_query.py <path_to_rrd> [entity_path_filter]
13+
14+
This example will query for the first 10 rows of data in your recording of choice,
15+
and display the results as a table in your terminal.
16+
17+
You can use one of your recordings, or grab one from our hosted examples, e.g.:
18+
curl 'https://app.rerun.io/version/latest/examples/dna.rrd' -o - > /tmp/dna.rrd
19+
20+
The results can be filtered further by specifying an entity filter expression:
21+
{bin_name} my_recording.rrd /skeleton/left_shoulder/**
22+
""".strip()
23+
24+
25+
def query(path_to_rrd: str, entity_path_filter: str) -> None:
26+
recording = rr.dataframe.load_recording(path_to_rrd)
27+
view = recording.view(index="log_time", contents=entity_path_filter)
28+
batches = view.select()
29+
30+
table = pa.Table.from_batches(batches, batches.schema)
31+
table = table.slice(0, 10)
32+
print(table.to_pandas())
33+
34+
35+
def main() -> None:
36+
parser = argparse.ArgumentParser(description=DESCRIPTION)
37+
parser.add_argument("path_to_rrd", type=str, help="Path to the .rrd file")
38+
parser.add_argument(
39+
"entity_path_filter", type=str, nargs="?", default="/**", help="Optional entity path filter expression"
40+
)
41+
args = parser.parse_args()
42+
43+
query(args.path_to_rrd, args.entity_path_filter)
44+
45+
46+
if __name__ == "__main__":
47+
main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[project]
2+
name = "dataframe_query"
3+
version = "0.1.0"
4+
# requires-python = "<3.12"
5+
readme = "README.md"
6+
dependencies = ["rerun-sdk"]
7+
8+
[project.scripts]
9+
dataframe_query = "dataframe_query:main"
10+
11+
[build-system]
12+
requires = ["hatchling"]
13+
build-backend = "hatchling.build"

0 commit comments

Comments
 (0)