{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# H1 street-crossing walks: one LeRobot episode without the LeRobot library\n",
    "\n",
    "RoadData.AI sample data \u00b7 tested 2026-11-26 against the published files (Python 3.12.14, numpy 2.5.4, opencv-python 5.1.0, pyarrow 18.1.0). Outputs below are from that run."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**H1 street-crossing walks** is in LeRobot v2.1 format: `meta/info.json`, one Parquet file per episode and one MP4 per camera. This reads them with `pyarrow` and OpenCV.\n",
    "\n",
    "Run `01_download_sample.py h1-street-crossing-lerobot` first."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "format v2.1 | fps 12 | episodes 46 | frames 5991\n",
      "  action                           float32 [2]\n",
      "  observation.state                float32 [25]\n",
      "  observation.images.ego_view      video [252, 448, 3]\n",
      "  timestamp                        float32 [1]\n",
      "  frame_index                      int64 [1]\n",
      "  episode_index                    int64 [1]\n",
      "  index                            int64 [1]\n",
      "  task_index                       int64 [1]\n"
     ]
    }
   ],
   "source": [
    "import json\n",
    "import pyarrow.parquet as pq\n",
    "import cv2\n",
    "root = './h1-street-crossing-lerobot'\n",
    "info = json.load(open(f'{root}/meta/info.json'))\n",
    "print('format', info['codebase_version'], '| fps', info['fps'], '| episodes', info['total_episodes'], '| frames', info['total_frames'])\n",
    "for k, f in info['features'].items(): print(f'  {k:32s} {f.get(\"dtype\")} {f.get(\"shape\")}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "135 steps\n",
      "observation.state: list<element: double>\n",
      "  child 0, element: double\n",
      "action: list<element: double>\n",
      "  child 0, element: double\n",
      "timestamp: double\n",
      "frame_index: int64\n",
      "episode_index: int64\n",
      "index: int64\n",
      "task_index: int64\n",
      "annotation.human.task_description: int64\n",
      "next.reward: double\n",
      "next.done: bool\n",
      "-- schema metadata --\n",
      "pandas: '{\"index_columns\": [{\"kind\": \"range\", \"name\": null, \"start\": 0, \"' + 1521\n"
     ]
    }
   ],
   "source": [
    "t = pq.read_table(f'{root}/data/chunk-000/episode_000000.parquet')\n",
    "print(t.num_rows, 'steps'); print(t.schema)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "velocity command at start, middle, end: [0.0, 0.0] [1.665, 0.9] [0.0, 0.0]\n"
     ]
    }
   ],
   "source": [
    "a = t.column('action').to_pylist()\n",
    "print('velocity command at start, middle, end:', a[0], a[len(a) // 2], a[-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "135 frames at 12.0 fps, 448 x 252\n"
     ]
    }
   ],
   "source": [
    "cap = cv2.VideoCapture(f'{root}/videos/chunk-000/observation.images.ego_view/episode_000000.mp4')\n",
    "print(int(cap.get(cv2.CAP_PROP_FRAME_COUNT)), 'frames at', cap.get(cv2.CAP_PROP_FPS), 'fps,', int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)), 'x', int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.12.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}