YangLiu1021 commited on
Commit
1f89812
·
0 Parent(s):

initialize odometry rosbag storage dataset

Browse files
.gitattributes ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.bag filter=lfs diff=lfs merge=lfs -text
2
+ *.mcap filter=lfs diff=lfs merge=lfs -text
3
+ *.db3 filter=lfs diff=lfs merge=lfs -text
4
+ *.parquet filter=lfs diff=lfs merge=lfs -text
5
+ *.arrow filter=lfs diff=lfs merge=lfs -text
6
+ *.jpg filter=lfs diff=lfs merge=lfs -text
7
+ *.jpeg filter=lfs diff=lfs merge=lfs -text
8
+ *.png filter=lfs diff=lfs merge=lfs -text
9
+ *.tiff filter=lfs diff=lfs merge=lfs -text
10
+ *.mp4 filter=lfs diff=lfs merge=lfs -text
11
+ *.npz filter=lfs diff=lfs merge=lfs -text
12
+ *.npy filter=lfs diff=lfs merge=lfs -text
13
+ *.pcd filter=lfs diff=lfs merge=lfs -text
14
+ *.ply filter=lfs diff=lfs merge=lfs -text
15
+ *.zst filter=lfs diff=lfs merge=lfs -text
16
+ *.tar filter=lfs diff=lfs merge=lfs -text
17
+ *.tar.gz filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.bag.active
2
+ *.active
3
+ *.tmp
4
+ *.partial
5
+ .cache/
6
+ tmp/
7
+ scratch/
8
+ outputs_tmp/
9
+ __pycache__/
10
+ *.pyc
11
+ .ipynb_checkpoints/
12
+ .DS_Store
13
+ *.log
14
+
15
+ # Local source bags before import. Imported bags live under raw/sessions/.
16
+ dataset/
Makefile ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .PHONY: init-lfs build-index validate scan-all
2
+
3
+ init-lfs:
4
+ bash scripts/init_git_lfs.sh
5
+
6
+ build-index:
7
+ python scripts/build_sessions_parquet.py --repo-root .
8
+ python scripts/build_topics_parquet.py --repo-root .
9
+
10
+ validate:
11
+ python scripts/validate_dataset.py --repo-root .
12
+
13
+ scan-all:
14
+ @for session_dir in raw/sessions/*; do \
15
+ if [ -d "$$session_dir" ]; then \
16
+ python scripts/scan_bag_topics.py --session-dir "$$session_dir" --write-metadata; \
17
+ fi; \
18
+ done
README.md ADDED
@@ -0,0 +1,210 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ pretty_name: Odometry ROSBag Dataset
3
+ license: other
4
+ task_categories:
5
+ - robotics
6
+ tags:
7
+ - rosbag
8
+ - odometry
9
+ - robotics
10
+ - imu
11
+ - lidar
12
+ - camera
13
+ configs:
14
+ sessions:
15
+ - metadata/sessions.parquet
16
+ topics:
17
+ - metadata/topics.parquet
18
+ ---
19
+
20
+ # Odometry ROSBag Dataset
21
+
22
+ ## 1. Dataset Overview
23
+
24
+ This is the first version of a simple ROSBag storage dataset. It stores immutable raw ROSBag files and builds small Parquet index tables for fast discovery.
25
+
26
+ Version 1 does not create `train`, `val`, or `test` splits. It does not export RGB images, depth images, infrared images, lidar point clouds, or training-ready frame folders.
27
+
28
+ ## 2. Repository Structure
29
+
30
+ ```text
31
+ raw/sessions/<session_id>/bag.bag
32
+ raw/sessions/<session_id>/bag.bag.sha256
33
+ raw/sessions/<session_id>/metadata.yaml
34
+ raw/sessions/<session_id>/topic_summary.yaml
35
+ metadata/sessions.parquet
36
+ metadata/topics.parquet
37
+ calibration/robot_v1_template/
38
+ quality/reports/
39
+ scripts/
40
+ examples/
41
+ tests/
42
+ ```
43
+
44
+ ## 3. Raw ROSBag Policy
45
+
46
+ Raw rosbag files are the source of truth. Treat them as immutable original data.
47
+
48
+ Do not overwrite old bags. Do not edit old bags in place. Every new collection must become a new session under `raw/sessions/<session_id>/`.
49
+
50
+ ## 4. ROS Topics
51
+
52
+ IMU:
53
+
54
+ - `/mavros/imu/data`
55
+ - `/mavros/imu/data_raw`
56
+ - `/livox/imu`
57
+
58
+ ToF:
59
+
60
+ - `/nlink_tofsensem_cascade`
61
+
62
+ LiDAR:
63
+
64
+ - `/livox/lidar`
65
+
66
+ Odometry:
67
+
68
+ - `/fusion_odometry/current_point_odom`
69
+ - `/fusion_odometry/lazy_point_odom`
70
+ - `/ekf_quat/ekf_odom`
71
+
72
+ Camera:
73
+
74
+ - `/camera/color/image_raw`
75
+ - `/camera/color/camera_info`
76
+ - `/camera/depth/image_rect_raw`
77
+ - `/camera/depth/camera_info`
78
+ - `/camera/infra1/image_rect_raw`
79
+ - `/camera/infra1/camera_info`
80
+ - `/camera/infra2/image_rect_raw`
81
+ - `/camera/infra2/camera_info`
82
+
83
+ TF:
84
+
85
+ - `/tf`
86
+ - `/tf_static`
87
+
88
+ ## 5. Session Naming
89
+
90
+ Input bags use:
91
+
92
+ ```text
93
+ odom_dataset_YYYYMMDD_HHMMSS.bag
94
+ ```
95
+
96
+ Session IDs use:
97
+
98
+ ```text
99
+ YYYY-MM-DD_HHMMSS_odom_runXXX
100
+ ```
101
+
102
+ Example:
103
+
104
+ ```text
105
+ odom_dataset_20260513_024746.bag -> 2026-05-13_024746_odom_run001
106
+ ```
107
+
108
+ ## 6. Time Convention
109
+
110
+ All timestamps in metadata and Parquet indexes use nanoseconds (`ns`).
111
+
112
+ ## 7. Calibration
113
+
114
+ Calibration templates live under `calibration/robot_v1_template/`. They are placeholders for robot frame transforms and sensor intrinsics. Replace template values with measured calibration before using the data for quantitative work.
115
+
116
+ ## 8. Metadata Schema
117
+
118
+ The schema is documented in `metadata/schema.md`. Per-session metadata lives in each session directory as `metadata.yaml`.
119
+
120
+ ## 9. Parquet Tables
121
+
122
+ `metadata/sessions.parquet` indexes sessions.
123
+
124
+ `metadata/topics.parquet` indexes per-topic statistics.
125
+
126
+ Parquet is an index and fast lookup entry point. It is not a replacement for the raw ROSBag data.
127
+
128
+ ## 10. How to Import Existing Bags
129
+
130
+ ```bash
131
+ python scripts/import_raw_bags.py --input-dir /path/to/my/bags --mode hardlink --repo-root .
132
+ ```
133
+
134
+ Use `--dry-run` first to inspect the plan.
135
+
136
+ ## 11. How to Add a New Bag
137
+
138
+ ```bash
139
+ python scripts/add_session.py \
140
+ --bag /path/to/odom_dataset_20260513_024746.bag \
141
+ --session-id 2026-05-13_024746_odom_run001 \
142
+ --calibration-id robot_v1_template \
143
+ --quality-status unchecked \
144
+ --mode hardlink \
145
+ --repo-root .
146
+ ```
147
+
148
+ ## 12. How to Scan Topics
149
+
150
+ ```bash
151
+ python scripts/scan_bag_topics.py \
152
+ --session-dir raw/sessions/2026-05-13_024746_odom_run001 \
153
+ --write-metadata
154
+ ```
155
+
156
+ To scan all sessions:
157
+
158
+ ```bash
159
+ make scan-all
160
+ ```
161
+
162
+ ## 13. How to Validate the Dataset
163
+
164
+ ```bash
165
+ python scripts/validate_dataset.py --repo-root .
166
+ ```
167
+
168
+ ## 14. How to Use with Git LFS
169
+
170
+ ```bash
171
+ bash scripts/init_git_lfs.sh
172
+ git add .gitattributes
173
+ git commit -m "configure git lfs"
174
+ ```
175
+
176
+ Large binary data such as `.bag` and `.parquet` files are tracked by Git LFS. YAML, Markdown, Python, shell scripts, and JSON stay as normal Git text files.
177
+
178
+ ## 15. How to Push to Hugging Face
179
+
180
+ After import, scan, index build, and validation:
181
+
182
+ ```bash
183
+ git add .
184
+ git commit -m "initialize odometry rosbag storage dataset"
185
+ git lfs ls-files
186
+ git remote add origin <your-hugging-face-dataset-git-url>
187
+ git push origin main
188
+ ```
189
+
190
+ This repository never pushes automatically.
191
+
192
+ ## 16. Future Work
193
+
194
+ Later versions may add `train/val/test`, `frames.parquet`, `odometry.parquet`, image export, and point cloud export.
195
+
196
+ If images or point clouds are exported later, do not put hundreds of thousands of files into one directory. Shard them by session and by time or frame range.
197
+
198
+ ## 17. Known Limitations
199
+
200
+ Version 1 only stores raw bags and metadata indexes. It does not decode sensor payloads into training data. Topic statistics require a sourced ROS environment because `rosbag` comes from ROS, not from `requirements.txt`.
201
+
202
+ ## 18. Citation
203
+
204
+ ```bibtex
205
+ @dataset{odometry_rosbag_dataset,
206
+ title = {Odometry ROSBag Dataset},
207
+ year = {2026},
208
+ note = {Raw ROSBag storage dataset with metadata indexes}
209
+ }
210
+ ```
calibration/robot_v1_template/README.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # robot_v1_template Calibration
2
+
3
+ This directory is a calibration placeholder. Replace template values with measured robot calibration before quantitative use.
4
+
5
+ Files:
6
+
7
+ - `tf_static.yaml`: static frame tree template
8
+ - `camera_color.yaml`: color camera intrinsics template
9
+ - `camera_depth.yaml`: depth camera intrinsics template
10
+ - `livox_to_base.yaml`: Livox lidar extrinsic template
11
+ - `tof_to_base.yaml`: ToF sensor extrinsic template
12
+ - `imu_to_base.yaml`: IMU extrinsic template
calibration/robot_v1_template/camera_color.yaml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ camera_name: camera_color
2
+ frame_id: camera_color_optical_frame
3
+ image_width: null
4
+ image_height: null
5
+ distortion_model: plumb_bob
6
+ intrinsics:
7
+ fx: null
8
+ fy: null
9
+ cx: null
10
+ cy: null
11
+ distortion_coefficients: []
calibration/robot_v1_template/camera_depth.yaml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ camera_name: camera_depth
2
+ frame_id: camera_depth_optical_frame
3
+ image_width: null
4
+ image_height: null
5
+ distortion_model: plumb_bob
6
+ intrinsics:
7
+ fx: null
8
+ fy: null
9
+ cx: null
10
+ cy: null
11
+ distortion_coefficients: []
calibration/robot_v1_template/imu_to_base.yaml ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ sensor: imu
2
+ parent_frame: base_link
3
+ child_frame: imu_frame
4
+ translation_xyz_m: [0.0, 0.0, 0.0]
5
+ rotation_xyzw: [0.0, 0.0, 0.0, 1.0]
calibration/robot_v1_template/livox_to_base.yaml ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ sensor: livox_lidar
2
+ parent_frame: base_link
3
+ child_frame: livox_frame
4
+ translation_xyz_m: [0.0, 0.0, 0.0]
5
+ rotation_xyzw: [0.0, 0.0, 0.0, 1.0]
calibration/robot_v1_template/tf_static.yaml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ calibration_id: robot_v1_template
2
+ frames:
3
+ base_link:
4
+ parent: world
5
+ translation_xyz_m: [0.0, 0.0, 0.0]
6
+ rotation_xyzw: [0.0, 0.0, 0.0, 1.0]
calibration/robot_v1_template/tof_to_base.yaml ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ sensor: tof
2
+ parent_frame: base_link
3
+ child_frame: tof_frame
4
+ translation_xyz_m: [0.0, 0.0, 0.0]
5
+ rotation_xyzw: [0.0, 0.0, 0.0, 1.0]
dataset.yaml ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ dataset_name: odometry-rosbag-dataset
2
+ schema_version: 0.1.0
3
+ canonical_raw_format: rosbag1
4
+ timestamp_unit: ns
5
+
6
+ raw_layout:
7
+ sessions_dir: raw/sessions
8
+ session_bag_name: bag.bag
9
+ checksum_name: bag.bag.sha256
10
+ metadata_name: metadata.yaml
11
+ topic_summary_name: topic_summary.yaml
12
+
13
+ default_topics:
14
+ rgb: /camera/color/image_raw
15
+ rgb_info: /camera/color/camera_info
16
+ depth: /camera/depth/image_rect_raw
17
+ depth_info: /camera/depth/camera_info
18
+ infra1: /camera/infra1/image_rect_raw
19
+ infra1_info: /camera/infra1/camera_info
20
+ infra2: /camera/infra2/image_rect_raw
21
+ infra2_info: /camera/infra2/camera_info
22
+ lidar: /livox/lidar
23
+ livox_imu: /livox/imu
24
+ mavros_imu: /mavros/imu/data
25
+ mavros_imu_raw: /mavros/imu/data_raw
26
+ tof: /nlink_tofsensem_cascade
27
+ odom_primary: /fusion_odometry/current_point_odom
28
+ odom_secondary: /fusion_odometry/lazy_point_odom
29
+ odom_ekf: /ekf_quat/ekf_odom
30
+ tf: /tf
31
+ tf_static: /tf_static
32
+
33
+ quality_status:
34
+ - unchecked
35
+ - good
36
+ - usable
37
+ - bad
examples/import_all_bags.sh ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ RAW_BAG_DIR="/path/to/folder/containing/bags"
5
+
6
+ python scripts/import_raw_bags.py \
7
+ --input-dir "$RAW_BAG_DIR" \
8
+ --mode hardlink \
9
+ --repo-root .
10
+
11
+ make scan-all
12
+ make build-index
13
+ make validate
examples/load_metadata.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+
3
+ sessions = pd.read_parquet("metadata/sessions.parquet")
4
+ topics = pd.read_parquet("metadata/topics.parquet")
5
+
6
+ print(sessions.head())
7
+ print(topics.head())
metadata/schema.md ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Metadata Schema
2
+
3
+ All timestamps use nanoseconds (`ns`). The first version stores indexes only. Raw ROSBag files remain the source of truth.
4
+
5
+ ## `metadata/sessions.parquet`
6
+
7
+ | Column | Type | Description |
8
+ | --- | --- | --- |
9
+ | `session_id` | `string` | Session directory name. |
10
+ | `bag_path` | `string` | Relative path to `bag.bag`. |
11
+ | `sha256_path` | `string` | Relative path to `bag.bag.sha256`. |
12
+ | `metadata_path` | `string` | Relative path to `metadata.yaml`. |
13
+ | `duration_sec` | `float64` | Bag duration in seconds. |
14
+ | `start_time_ns` | `int64` | Earliest message timestamp. |
15
+ | `end_time_ns` | `int64` | Latest message timestamp. |
16
+ | `num_messages` | `int64` | Total message count. |
17
+ | `has_lidar` | `bool` | Session contains lidar data. |
18
+ | `has_rgb` | `bool` | Session contains RGB camera data. |
19
+ | `has_depth` | `bool` | Session contains depth camera data. |
20
+ | `has_infra` | `bool` | Session contains infrared camera data. |
21
+ | `has_tof` | `bool` | Session contains ToF data. |
22
+ | `has_imu` | `bool` | Session contains IMU data. |
23
+ | `has_odom` | `bool` | Session contains odometry data. |
24
+ | `has_tf` | `bool` | Session contains TF data. |
25
+ | `calibration_id` | `string` | Calibration directory ID. |
26
+ | `quality_status` | `string` | One of `unchecked`, `good`, `usable`, `bad`. |
27
+ | `source_filename` | `string` | Original bag filename. |
28
+ | `import_mode` | `string` | Import mode: `hardlink`, `copy`, `symlink`, or `move`. |
29
+
30
+ ## `metadata/topics.parquet`
31
+
32
+ | Column | Type | Description |
33
+ | --- | --- | --- |
34
+ | `session_id` | `string` | Session directory name. |
35
+ | `bag_path` | `string` | Relative path to `bag.bag`. |
36
+ | `topic` | `string` | ROS topic name. |
37
+ | `msg_type` | `string` | ROS message type. |
38
+ | `count` | `int64` | Message count for this topic. |
39
+ | `hz_mean` | `float64` | Mean frequency estimated from timestamps. |
40
+ | `timestamp_min_ns` | `int64` | Earliest topic timestamp. |
41
+ | `timestamp_max_ns` | `int64` | Latest topic timestamp. |
42
+ | `category` | `string` | Topic category. |
metadata/sensors.yaml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ topic_categories:
2
+ IMU:
3
+ - /mavros/imu/data
4
+ - /mavros/imu/data_raw
5
+ - /livox/imu
6
+ ToF:
7
+ - /nlink_tofsensem_cascade
8
+ LiDAR:
9
+ - /livox/lidar
10
+ Odometry:
11
+ - /fusion_odometry/current_point_odom
12
+ - /fusion_odometry/lazy_point_odom
13
+ - /ekf_quat/ekf_odom
14
+ Camera:
15
+ - /camera/color/image_raw
16
+ - /camera/color/camera_info
17
+ - /camera/depth/image_rect_raw
18
+ - /camera/depth/camera_info
19
+ - /camera/infra1/image_rect_raw
20
+ - /camera/infra1/camera_info
21
+ - /camera/infra2/image_rect_raw
22
+ - /camera/infra2/camera_info
23
+ TF:
24
+ - /tf
25
+ - /tf_static
metadata/sessions.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cbed37286b3393a4c540949151ae99c4d9abdffc22f879e272d5d08c53b15fd0
3
+ size 3026
metadata/topics.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:edaa10f8b0e39c023ccd0a56708f6e3e272bb668894e77702b8ac47b8cf4d451
3
+ size 1592
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ pyyaml
2
+ pandas
3
+ pyarrow
4
+ tqdm
scripts/add_session.py ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ from __future__ import annotations
3
+
4
+ import argparse
5
+ import hashlib
6
+ import os
7
+ import shutil
8
+ from pathlib import Path
9
+ from typing import Literal
10
+
11
+ import yaml
12
+
13
+ ImportMode = Literal["hardlink", "copy", "symlink", "move"]
14
+
15
+
16
+ def sha256_file(path: Path) -> str:
17
+ digest = hashlib.sha256()
18
+ with path.open("rb") as handle:
19
+ for chunk in iter(lambda: handle.read(1024 * 1024), b""):
20
+ digest.update(chunk)
21
+ return digest.hexdigest()
22
+
23
+
24
+ def import_bag(source: Path, target: Path, mode: ImportMode) -> None:
25
+ target.parent.mkdir(parents=True, exist_ok=True)
26
+ if target.exists() or target.is_symlink():
27
+ raise FileExistsError(f"Target bag already exists: {target}")
28
+
29
+ if mode == "hardlink":
30
+ try:
31
+ os.link(source, target)
32
+ except OSError as exc:
33
+ raise RuntimeError(
34
+ f"Failed to create hardlink from {source} to {target}. "
35
+ "Use --mode copy, --mode symlink, or --mode move explicitly."
36
+ ) from exc
37
+ elif mode == "copy":
38
+ shutil.copy2(source, target)
39
+ elif mode == "symlink":
40
+ target.symlink_to(source.resolve())
41
+ elif mode == "move":
42
+ shutil.move(str(source), str(target))
43
+ else:
44
+ raise ValueError(f"Unsupported import mode: {mode}")
45
+
46
+
47
+ def write_text_atomic(path: Path, text: str) -> None:
48
+ path.parent.mkdir(parents=True, exist_ok=True)
49
+ if path.exists():
50
+ raise FileExistsError(f"Refusing to overwrite existing file: {path}")
51
+ path.write_text(text, encoding="utf-8")
52
+
53
+
54
+ def add_session(
55
+ bag: Path,
56
+ session_id: str,
57
+ calibration_id: str,
58
+ quality_status: str,
59
+ mode: ImportMode,
60
+ repo_root: Path,
61
+ ) -> Path:
62
+ if not bag.exists():
63
+ raise FileNotFoundError(f"Bag does not exist: {bag}")
64
+ if not bag.is_file():
65
+ raise ValueError(f"Bag path is not a file: {bag}")
66
+
67
+ session_dir = repo_root / "raw" / "sessions" / session_id
68
+ if session_dir.exists():
69
+ raise FileExistsError(f"Session already exists, refusing to overwrite: {session_dir}")
70
+
71
+ target_bag = session_dir / "bag.bag"
72
+ import_bag(bag, target_bag, mode)
73
+
74
+ digest = sha256_file(target_bag)
75
+ sha_path = session_dir / "bag.bag.sha256"
76
+ write_text_atomic(sha_path, f"{digest} bag.bag\n")
77
+
78
+ metadata = {
79
+ "session_id": session_id,
80
+ "raw": {
81
+ "format": "rosbag1",
82
+ "file": "bag.bag",
83
+ "sha256_file": "bag.bag.sha256",
84
+ "ros_distro": os.environ.get("ROS_DISTRO"),
85
+ },
86
+ "source": {
87
+ "filename": bag.name,
88
+ "path": str(bag),
89
+ "import_mode": mode,
90
+ },
91
+ "platform": {},
92
+ "time": {
93
+ "duration_sec": None,
94
+ "start_time_ns": None,
95
+ "end_time_ns": None,
96
+ "num_messages": None,
97
+ },
98
+ "topics": [],
99
+ "calibration_id": calibration_id,
100
+ "quality": {
101
+ "status": quality_status,
102
+ "notes": "",
103
+ },
104
+ }
105
+ metadata_path = session_dir / "metadata.yaml"
106
+ write_text_atomic(metadata_path, yaml.safe_dump(metadata, sort_keys=False, allow_unicode=False))
107
+ return session_dir
108
+
109
+
110
+ def parse_args() -> argparse.Namespace:
111
+ parser = argparse.ArgumentParser(description="Add one ROSBag as an immutable raw session.")
112
+ parser.add_argument("--bag", required=True, type=Path)
113
+ parser.add_argument("--session-id", required=True)
114
+ parser.add_argument("--calibration-id", required=True)
115
+ parser.add_argument("--quality-status", required=True)
116
+ parser.add_argument("--mode", choices=["hardlink", "copy", "symlink", "move"], required=True)
117
+ parser.add_argument("--repo-root", default=Path("."), type=Path)
118
+ return parser.parse_args()
119
+
120
+
121
+ def main() -> None:
122
+ args = parse_args()
123
+ session_dir = add_session(
124
+ bag=args.bag,
125
+ session_id=args.session_id,
126
+ calibration_id=args.calibration_id,
127
+ quality_status=args.quality_status,
128
+ mode=args.mode,
129
+ repo_root=args.repo_root,
130
+ )
131
+ print(f"Added session: {session_dir}")
132
+
133
+
134
+ if __name__ == "__main__":
135
+ main()
scripts/build_sessions_parquet.py ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ from __future__ import annotations
3
+
4
+ import argparse
5
+ from pathlib import Path
6
+ from typing import Any
7
+
8
+ import pyarrow as pa
9
+ import pyarrow.parquet as pq
10
+ import yaml
11
+
12
+ SCHEMA = pa.schema(
13
+ [
14
+ ("session_id", pa.string()),
15
+ ("bag_path", pa.string()),
16
+ ("sha256_path", pa.string()),
17
+ ("metadata_path", pa.string()),
18
+ ("duration_sec", pa.float64()),
19
+ ("start_time_ns", pa.int64()),
20
+ ("end_time_ns", pa.int64()),
21
+ ("num_messages", pa.int64()),
22
+ ("has_lidar", pa.bool_()),
23
+ ("has_rgb", pa.bool_()),
24
+ ("has_depth", pa.bool_()),
25
+ ("has_infra", pa.bool_()),
26
+ ("has_tof", pa.bool_()),
27
+ ("has_imu", pa.bool_()),
28
+ ("has_odom", pa.bool_()),
29
+ ("has_tf", pa.bool_()),
30
+ ("calibration_id", pa.string()),
31
+ ("quality_status", pa.string()),
32
+ ("source_filename", pa.string()),
33
+ ("import_mode", pa.string()),
34
+ ]
35
+ )
36
+
37
+
38
+ def rel(path: Path, root: Path) -> str:
39
+ return path.relative_to(root).as_posix()
40
+
41
+
42
+ def read_yaml(path: Path) -> dict[str, Any]:
43
+ return yaml.safe_load(path.read_text(encoding="utf-8")) or {}
44
+
45
+
46
+ def topics_from(session_dir: Path, metadata: dict[str, Any]) -> list[dict[str, Any]]:
47
+ summary_path = session_dir / "topic_summary.yaml"
48
+ if summary_path.exists():
49
+ summary = read_yaml(summary_path)
50
+ return list(summary.get("topics") or [])
51
+ return list(metadata.get("topics") or [])
52
+
53
+
54
+ def has_topic(topics: list[dict[str, Any]], needle: str) -> bool:
55
+ return any(needle in str(item.get("topic", "")) for item in topics)
56
+
57
+
58
+ def has_category(topics: list[dict[str, Any]], category: str) -> bool:
59
+ return any(str(item.get("category", "")).lower() == category for item in topics)
60
+
61
+
62
+ def build_rows(repo_root: Path) -> list[dict[str, Any]]:
63
+ sessions_dir = repo_root / "raw" / "sessions"
64
+ rows: list[dict[str, Any]] = []
65
+ if not sessions_dir.exists():
66
+ return rows
67
+
68
+ for session_dir in sorted(path for path in sessions_dir.iterdir() if path.is_dir()):
69
+ metadata_path = session_dir / "metadata.yaml"
70
+ metadata = read_yaml(metadata_path) if metadata_path.exists() else {}
71
+ time = metadata.get("time") or {}
72
+ source = metadata.get("source") or {}
73
+ quality = metadata.get("quality") or {}
74
+ topics = topics_from(session_dir, metadata)
75
+ row = {
76
+ "session_id": session_dir.name,
77
+ "bag_path": rel(session_dir / "bag.bag", repo_root),
78
+ "sha256_path": rel(session_dir / "bag.bag.sha256", repo_root),
79
+ "metadata_path": rel(metadata_path, repo_root),
80
+ "duration_sec": time.get("duration_sec"),
81
+ "start_time_ns": time.get("start_time_ns"),
82
+ "end_time_ns": time.get("end_time_ns"),
83
+ "num_messages": time.get("num_messages"),
84
+ "has_lidar": has_category(topics, "lidar") or has_topic(topics, "/livox/lidar"),
85
+ "has_rgb": has_topic(topics, "/camera/color/image_raw"),
86
+ "has_depth": has_topic(topics, "/camera/depth/"),
87
+ "has_infra": has_topic(topics, "/camera/infra"),
88
+ "has_tof": has_category(topics, "tof") or has_topic(topics, "nlink"),
89
+ "has_imu": has_category(topics, "imu") or has_topic(topics, "imu"),
90
+ "has_odom": has_category(topics, "odometry") or has_topic(topics, "odom"),
91
+ "has_tf": has_category(topics, "tf") or has_topic(topics, "/tf"),
92
+ "calibration_id": metadata.get("calibration_id"),
93
+ "quality_status": quality.get("status"),
94
+ "source_filename": source.get("filename"),
95
+ "import_mode": source.get("import_mode"),
96
+ }
97
+ rows.append(row)
98
+ return rows
99
+
100
+
101
+ def write_parquet(rows: list[dict[str, Any]], output: Path) -> None:
102
+ output.parent.mkdir(parents=True, exist_ok=True)
103
+ table = pa.Table.from_pylist(rows, schema=SCHEMA)
104
+ pq.write_table(table, output)
105
+
106
+
107
+ def parse_args() -> argparse.Namespace:
108
+ parser = argparse.ArgumentParser(description="Build metadata/sessions.parquet.")
109
+ parser.add_argument("--repo-root", default=Path("."), type=Path)
110
+ return parser.parse_args()
111
+
112
+
113
+ def main() -> None:
114
+ args = parse_args()
115
+ repo_root = args.repo_root.resolve()
116
+ output = repo_root / "metadata" / "sessions.parquet"
117
+ rows = build_rows(repo_root)
118
+ write_parquet(rows, output)
119
+ print(f"Wrote {output} with {len(rows)} rows")
120
+
121
+
122
+ if __name__ == "__main__":
123
+ main()
scripts/build_topics_parquet.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ from __future__ import annotations
3
+
4
+ import argparse
5
+ import warnings
6
+ from pathlib import Path
7
+ from typing import Any
8
+
9
+ import pyarrow as pa
10
+ import pyarrow.parquet as pq
11
+ import yaml
12
+
13
+ SCHEMA = pa.schema(
14
+ [
15
+ ("session_id", pa.string()),
16
+ ("bag_path", pa.string()),
17
+ ("topic", pa.string()),
18
+ ("msg_type", pa.string()),
19
+ ("count", pa.int64()),
20
+ ("hz_mean", pa.float64()),
21
+ ("timestamp_min_ns", pa.int64()),
22
+ ("timestamp_max_ns", pa.int64()),
23
+ ("category", pa.string()),
24
+ ]
25
+ )
26
+
27
+
28
+ def rel(path: Path, root: Path) -> str:
29
+ return path.relative_to(root).as_posix()
30
+
31
+
32
+ def read_yaml(path: Path) -> dict[str, Any]:
33
+ return yaml.safe_load(path.read_text(encoding="utf-8")) or {}
34
+
35
+
36
+ def build_rows(repo_root: Path) -> list[dict[str, Any]]:
37
+ sessions_dir = repo_root / "raw" / "sessions"
38
+ rows: list[dict[str, Any]] = []
39
+ if not sessions_dir.exists():
40
+ return rows
41
+
42
+ for session_dir in sorted(path for path in sessions_dir.iterdir() if path.is_dir()):
43
+ summary_path = session_dir / "topic_summary.yaml"
44
+ if not summary_path.exists():
45
+ warnings.warn(f"Missing topic summary, skipping: {summary_path}", stacklevel=2)
46
+ continue
47
+ summary = read_yaml(summary_path)
48
+ for item in summary.get("topics") or []:
49
+ rows.append(
50
+ {
51
+ "session_id": session_dir.name,
52
+ "bag_path": rel(session_dir / "bag.bag", repo_root),
53
+ "topic": item.get("topic"),
54
+ "msg_type": item.get("msg_type"),
55
+ "count": item.get("count"),
56
+ "hz_mean": item.get("hz_mean"),
57
+ "timestamp_min_ns": item.get("timestamp_min_ns"),
58
+ "timestamp_max_ns": item.get("timestamp_max_ns"),
59
+ "category": item.get("category"),
60
+ }
61
+ )
62
+ return rows
63
+
64
+
65
+ def write_parquet(rows: list[dict[str, Any]], output: Path) -> None:
66
+ output.parent.mkdir(parents=True, exist_ok=True)
67
+ table = pa.Table.from_pylist(rows, schema=SCHEMA)
68
+ pq.write_table(table, output)
69
+
70
+
71
+ def parse_args() -> argparse.Namespace:
72
+ parser = argparse.ArgumentParser(description="Build metadata/topics.parquet.")
73
+ parser.add_argument("--repo-root", default=Path("."), type=Path)
74
+ return parser.parse_args()
75
+
76
+
77
+ def main() -> None:
78
+ args = parse_args()
79
+ repo_root = args.repo_root.resolve()
80
+ output = repo_root / "metadata" / "topics.parquet"
81
+ rows = build_rows(repo_root)
82
+ write_parquet(rows, output)
83
+ print(f"Wrote {output} with {len(rows)} rows")
84
+
85
+
86
+ if __name__ == "__main__":
87
+ main()
scripts/import_raw_bags.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ from __future__ import annotations
3
+
4
+ import argparse
5
+ import re
6
+ from datetime import datetime
7
+ from pathlib import Path
8
+
9
+ from add_session import add_session
10
+
11
+ BAG_RE = re.compile(r"^odom_dataset_(\d{8})_(\d{6})\.bag$")
12
+
13
+
14
+ def session_id_from_name(path: Path, run_index: int) -> str:
15
+ match = BAG_RE.match(path.name)
16
+ if not match:
17
+ raise ValueError(f"Unsupported bag filename: {path.name}")
18
+ day, clock = match.groups()
19
+ dt = datetime.strptime(day + clock, "%Y%m%d%H%M%S")
20
+ return f"{dt:%Y-%m-%d}_{clock}_odom_run{run_index:03d}"
21
+
22
+
23
+ def find_bags(input_dir: Path) -> list[Path]:
24
+ if not input_dir.exists():
25
+ raise FileNotFoundError(f"Input directory does not exist: {input_dir}")
26
+ if not input_dir.is_dir():
27
+ raise ValueError(f"Input path is not a directory: {input_dir}")
28
+ return sorted(
29
+ [path for path in input_dir.iterdir() if path.is_file() and BAG_RE.match(path.name)],
30
+ key=lambda path: path.name,
31
+ )
32
+
33
+
34
+ def print_plan(rows: list[tuple[Path, str, Path, str]]) -> None:
35
+ headers = ("source_path", "session_id", "target_path", "mode")
36
+ widths = [len(item) for item in headers]
37
+ for row in rows:
38
+ values = [str(row[0]), row[1], str(row[2]), row[3]]
39
+ widths = [max(width, len(value)) for width, value in zip(widths, values)]
40
+ print(" ".join(header.ljust(width) for header, width in zip(headers, widths)))
41
+ print(" ".join("-" * width for width in widths))
42
+ for row in rows:
43
+ values = [str(row[0]), row[1], str(row[2]), row[3]]
44
+ print(" ".join(value.ljust(width) for value, width in zip(values, widths)))
45
+
46
+
47
+ def parse_args() -> argparse.Namespace:
48
+ parser = argparse.ArgumentParser(description="Batch import odometry ROSBag files as raw sessions.")
49
+ parser.add_argument("--input-dir", required=True, type=Path)
50
+ parser.add_argument("--mode", default="hardlink", choices=["hardlink", "copy", "symlink", "move"])
51
+ parser.add_argument("--repo-root", default=Path("."), type=Path)
52
+ parser.add_argument("--calibration-id", default="robot_v1_template")
53
+ parser.add_argument("--quality-status", default="unchecked")
54
+ parser.add_argument("--dry-run", action="store_true")
55
+ return parser.parse_args()
56
+
57
+
58
+ def main() -> None:
59
+ args = parse_args()
60
+ bags = find_bags(args.input_dir)
61
+ rows: list[tuple[Path, str, Path, str]] = []
62
+ for index, bag in enumerate(bags, start=1):
63
+ session_id = session_id_from_name(bag, index)
64
+ target = args.repo_root / "raw" / "sessions" / session_id / "bag.bag"
65
+ rows.append((bag, session_id, target, args.mode))
66
+
67
+ if not rows:
68
+ print(f"No matching bags found in {args.input_dir}")
69
+ return
70
+
71
+ if args.dry_run:
72
+ print_plan(rows)
73
+ return
74
+
75
+ for bag, session_id, _, _ in rows:
76
+ session_dir = add_session(
77
+ bag=bag,
78
+ session_id=session_id,
79
+ calibration_id=args.calibration_id,
80
+ quality_status=args.quality_status,
81
+ mode=args.mode,
82
+ repo_root=args.repo_root,
83
+ )
84
+ print(f"Imported {bag} -> {session_dir}")
85
+
86
+
87
+ if __name__ == "__main__":
88
+ main()
scripts/init_git_lfs.sh ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ git lfs install
5
+ git lfs track "*.bag"
6
+ git lfs track "*.mcap"
7
+ git lfs track "*.db3"
8
+ git lfs track "*.parquet"
9
+ git lfs track "*.arrow"
10
+ git lfs track "*.jpg"
11
+ git lfs track "*.jpeg"
12
+ git lfs track "*.png"
13
+ git lfs track "*.tiff"
14
+ git lfs track "*.mp4"
15
+ git lfs track "*.npz"
16
+ git lfs track "*.npy"
17
+ git lfs track "*.pcd"
18
+ git lfs track "*.ply"
19
+ git lfs track "*.zst"
20
+ git lfs track "*.tar"
21
+ git lfs track "*.tar.gz"
22
+
23
+ echo
24
+ echo "Next:"
25
+ echo "git add .gitattributes"
26
+ echo "git commit -m \"configure git lfs\""
scripts/scan_bag_topics.py ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ from __future__ import annotations
3
+
4
+ import argparse
5
+ from pathlib import Path
6
+ from typing import Any
7
+
8
+ import yaml
9
+
10
+
11
+ def import_rosbag() -> Any:
12
+ try:
13
+ import rosbag # type: ignore
14
+ except ImportError as exc:
15
+ raise ImportError(
16
+ "Failed to import rosbag. Please source your ROS environment first, for example:\n"
17
+ "source /opt/ros/noetic/setup.bash"
18
+ ) from exc
19
+ return rosbag
20
+
21
+
22
+ def to_nsec(stamp: Any) -> int:
23
+ if hasattr(stamp, "to_nsec"):
24
+ return int(stamp.to_nsec())
25
+ return int(float(stamp) * 1_000_000_000)
26
+
27
+
28
+ def category_for_topic(topic: str, msg_type: str) -> str:
29
+ lower = f"{topic} {msg_type}".lower()
30
+ if topic in {"/tf", "/tf_static"}:
31
+ return "tf"
32
+ if "imu" in lower:
33
+ return "imu"
34
+ if "tof" in lower or "nlink" in lower:
35
+ return "tof"
36
+ if "livox/lidar" in lower or "pointcloud" in lower:
37
+ return "lidar"
38
+ if "odom" in lower:
39
+ return "odometry"
40
+ if "camera" in lower:
41
+ return "camera"
42
+ return "other"
43
+
44
+
45
+ def scan_session(session_dir: Path) -> dict[str, Any]:
46
+ rosbag = import_rosbag()
47
+ bag_path = session_dir / "bag.bag"
48
+ if not bag_path.exists():
49
+ raise FileNotFoundError(f"Missing bag: {bag_path}")
50
+
51
+ with rosbag.Bag(str(bag_path), "r") as bag:
52
+ info = bag.get_type_and_topic_info()
53
+ topic_types = {topic: item.msg_type for topic, item in info.topics.items()}
54
+ stats: dict[str, dict[str, Any]] = {
55
+ topic: {
56
+ "topic": topic,
57
+ "msg_type": msg_type,
58
+ "count": 0,
59
+ "timestamp_min_ns": None,
60
+ "timestamp_max_ns": None,
61
+ "hz_mean": 0.0,
62
+ "category": category_for_topic(topic, msg_type),
63
+ }
64
+ for topic, msg_type in topic_types.items()
65
+ }
66
+
67
+ for topic, _, stamp in bag.read_messages():
68
+ stamp_ns = to_nsec(stamp)
69
+ item = stats.setdefault(
70
+ topic,
71
+ {
72
+ "topic": topic,
73
+ "msg_type": topic_types.get(topic, ""),
74
+ "count": 0,
75
+ "timestamp_min_ns": None,
76
+ "timestamp_max_ns": None,
77
+ "hz_mean": 0.0,
78
+ "category": category_for_topic(topic, topic_types.get(topic, "")),
79
+ },
80
+ )
81
+ item["count"] += 1
82
+ item["timestamp_min_ns"] = stamp_ns if item["timestamp_min_ns"] is None else min(item["timestamp_min_ns"], stamp_ns)
83
+ item["timestamp_max_ns"] = stamp_ns if item["timestamp_max_ns"] is None else max(item["timestamp_max_ns"], stamp_ns)
84
+
85
+ topics = sorted(stats.values(), key=lambda item: item["topic"])
86
+ total_messages = 0
87
+ start_time_ns: int | None = None
88
+ end_time_ns: int | None = None
89
+ for item in topics:
90
+ count = int(item["count"])
91
+ total_messages += count
92
+ min_ns = item["timestamp_min_ns"]
93
+ max_ns = item["timestamp_max_ns"]
94
+ if min_ns is not None:
95
+ start_time_ns = min_ns if start_time_ns is None else min(start_time_ns, min_ns)
96
+ if max_ns is not None:
97
+ end_time_ns = max_ns if end_time_ns is None else max(end_time_ns, max_ns)
98
+ if count > 1 and min_ns is not None and max_ns is not None and max_ns > min_ns:
99
+ item["hz_mean"] = float(count - 1) / ((max_ns - min_ns) / 1_000_000_000.0)
100
+
101
+ duration_sec = None
102
+ if start_time_ns is not None and end_time_ns is not None:
103
+ duration_sec = (end_time_ns - start_time_ns) / 1_000_000_000.0
104
+
105
+ return {
106
+ "session_id": session_dir.name,
107
+ "bag": "bag.bag",
108
+ "duration_sec": duration_sec,
109
+ "start_time_ns": start_time_ns,
110
+ "end_time_ns": end_time_ns,
111
+ "num_messages": total_messages,
112
+ "topics": topics,
113
+ }
114
+
115
+
116
+ def update_metadata(session_dir: Path, summary: dict[str, Any]) -> None:
117
+ metadata_path = session_dir / "metadata.yaml"
118
+ if not metadata_path.exists():
119
+ raise FileNotFoundError(f"Missing metadata: {metadata_path}")
120
+ metadata = yaml.safe_load(metadata_path.read_text(encoding="utf-8")) or {}
121
+ metadata["time"] = {
122
+ "duration_sec": summary["duration_sec"],
123
+ "start_time_ns": summary["start_time_ns"],
124
+ "end_time_ns": summary["end_time_ns"],
125
+ "num_messages": summary["num_messages"],
126
+ }
127
+ metadata["topics"] = summary["topics"]
128
+ metadata_path.write_text(yaml.safe_dump(metadata, sort_keys=False, allow_unicode=False), encoding="utf-8")
129
+
130
+
131
+ def parse_args() -> argparse.Namespace:
132
+ parser = argparse.ArgumentParser(description="Scan one session bag and write topic statistics.")
133
+ parser.add_argument("--session-dir", required=True, type=Path)
134
+ parser.add_argument("--write-metadata", action="store_true")
135
+ return parser.parse_args()
136
+
137
+
138
+ def main() -> None:
139
+ args = parse_args()
140
+ summary = scan_session(args.session_dir)
141
+ summary_path = args.session_dir / "topic_summary.yaml"
142
+ summary_path.parent.mkdir(parents=True, exist_ok=True)
143
+ summary_path.write_text(yaml.safe_dump(summary, sort_keys=False, allow_unicode=False), encoding="utf-8")
144
+ if args.write_metadata:
145
+ update_metadata(args.session_dir, summary)
146
+ print(f"Wrote {summary_path}")
147
+
148
+
149
+ if __name__ == "__main__":
150
+ main()
scripts/validate_dataset.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ from __future__ import annotations
3
+
4
+ import argparse
5
+ import hashlib
6
+ from pathlib import Path
7
+ from typing import Any
8
+
9
+ import yaml
10
+
11
+
12
+ def sha256_file(path: Path) -> str:
13
+ digest = hashlib.sha256()
14
+ with path.open("rb") as handle:
15
+ for chunk in iter(lambda: handle.read(1024 * 1024), b""):
16
+ digest.update(chunk)
17
+ return digest.hexdigest()
18
+
19
+
20
+ def read_yaml(path: Path) -> dict[str, Any]:
21
+ return yaml.safe_load(path.read_text(encoding="utf-8")) or {}
22
+
23
+
24
+ def require(condition: bool, message: str, errors: list[str]) -> None:
25
+ if not condition:
26
+ errors.append(message)
27
+
28
+
29
+ def expected_sha(path: Path) -> str:
30
+ text = path.read_text(encoding="utf-8").strip()
31
+ if not text:
32
+ raise ValueError(f"Empty sha256 file: {path}")
33
+ return text.split()[0]
34
+
35
+
36
+ def validate_session(session_dir: Path, repo_root: Path, errors: list[str]) -> None:
37
+ bag_path = session_dir / "bag.bag"
38
+ sha_path = session_dir / "bag.bag.sha256"
39
+ metadata_path = session_dir / "metadata.yaml"
40
+
41
+ require(bag_path.exists(), f"Missing bag: {bag_path}", errors)
42
+ require(sha_path.exists(), f"Missing sha256: {sha_path}", errors)
43
+ require(metadata_path.exists(), f"Missing metadata: {metadata_path}", errors)
44
+ if not (bag_path.exists() and sha_path.exists() and metadata_path.exists()):
45
+ return
46
+
47
+ actual = sha256_file(bag_path)
48
+ expected = expected_sha(sha_path)
49
+ require(actual == expected, f"SHA256 mismatch: {bag_path}", errors)
50
+
51
+ metadata = read_yaml(metadata_path)
52
+ require(metadata.get("session_id") == session_dir.name, f"session_id mismatch: {metadata_path}", errors)
53
+ calibration_id = metadata.get("calibration_id")
54
+ require(bool(calibration_id), f"Missing calibration_id: {metadata_path}", errors)
55
+ if calibration_id:
56
+ require((repo_root / "calibration" / calibration_id).exists(), f"Missing calibration: {calibration_id}", errors)
57
+
58
+
59
+ def validate_gitattributes(path: Path, errors: list[str]) -> None:
60
+ require(path.exists(), "Missing .gitattributes", errors)
61
+ if not path.exists():
62
+ return
63
+ text = path.read_text(encoding="utf-8")
64
+ require("*.bag" in text, ".gitattributes does not track *.bag", errors)
65
+ require("*.parquet" in text, ".gitattributes does not track *.parquet", errors)
66
+
67
+
68
+ def parse_args() -> argparse.Namespace:
69
+ parser = argparse.ArgumentParser(description="Validate dataset repository integrity.")
70
+ parser.add_argument("--repo-root", default=Path("."), type=Path)
71
+ return parser.parse_args()
72
+
73
+
74
+ def main() -> None:
75
+ args = parse_args()
76
+ repo_root = args.repo_root.resolve()
77
+ errors: list[str] = []
78
+
79
+ sessions_dir = repo_root / "raw" / "sessions"
80
+ require(sessions_dir.exists(), "Missing raw/sessions", errors)
81
+ require((repo_root / "metadata" / "sessions.parquet").exists(), "Missing metadata/sessions.parquet", errors)
82
+ require((repo_root / "metadata" / "topics.parquet").exists(), "Missing metadata/topics.parquet", errors)
83
+ validate_gitattributes(repo_root / ".gitattributes", errors)
84
+
85
+ session_dirs = sorted(path for path in sessions_dir.iterdir() if path.is_dir()) if sessions_dir.exists() else []
86
+ names = [path.name for path in session_dirs]
87
+ require(len(names) == len(set(names)), "Duplicate session directory names found", errors)
88
+
89
+ if not session_dirs:
90
+ print("No sessions found. Repository structure is valid for an empty first-version dataset.")
91
+
92
+ for session_dir in session_dirs:
93
+ validate_session(session_dir, repo_root, errors)
94
+
95
+ if errors:
96
+ for error in errors:
97
+ print(f"ERROR: {error}")
98
+ raise SystemExit(1)
99
+
100
+ print("Dataset validation passed.")
101
+
102
+
103
+ if __name__ == "__main__":
104
+ main()
tests/test_paths.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+
3
+
4
+ def test_key_paths_exist() -> None:
5
+ root = Path(__file__).resolve().parents[1]
6
+ assert (root / "raw" / "sessions").exists()
7
+ assert (root / "metadata").exists()
8
+ assert (root / "calibration" / "robot_v1_template").exists()
9
+ assert (root / ".gitattributes").exists()
10
+ assert (root / "dataset.yaml").exists()
tests/test_schema.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+
3
+ import pandas as pd
4
+
5
+
6
+ def test_schema_doc_exists() -> None:
7
+ root = Path(__file__).resolve().parents[1]
8
+ assert (root / "metadata" / "schema.md").exists()
9
+
10
+
11
+ def test_existing_parquet_files_are_readable() -> None:
12
+ root = Path(__file__).resolve().parents[1]
13
+ for path in [root / "metadata" / "sessions.parquet", root / "metadata" / "topics.parquet"]:
14
+ if path.exists():
15
+ pd.read_parquet(path)