# CLAUDE.md Context for continuing work on this dataset. Captures the design decisions, conventions, and operational details worked out so far. Read this before touching the ETL or schema. ## What this dataset is `Inova-Mk1-Telemetry` is the **tick-anchored printer-state dataset**: one row per 10 Hz recorder tick, with the full sensor snapshot (~64 columns: temperatures, position, power, lights) on every row, the nearest camera frame bytes embedded inline when one fell in the prior 100 ms window, and 1 kHz `position_hf` events from that window collected as a per-tick list. It is the **third leaf** in the Inova Mk1 dataset ecosystem alongside `Inova-Mk1-Database` (canonical printer entities) and `Inova-Mk1-ASTM` (mechanical-test specimens). Unlike the other two, this dataset has **no local `source/` directory** — its raw inputs are the flat exports written by the recorder repo (`Agentic-Additive-Manufacturing-Process-Optimization`), which contains this dataset as a submodule at `datasets/Inova-Mk1-Telemetry`. The ETL here reshapes those flat exports into one parquet file per build. ## Data lineage — printer to row End-to-end, before this dataset's ETL touches anything: ``` ┌────────────────────────────┐ │ Inova Mk1 SLS printer │ firmware events: position, temp, power, lights; │ (SLS4All.Compact) │ camera frames (chamber, galvo, thermal); │ on 192.168.1.146 │ high-rate position events (~1 kHz, native). └──────────────┬─────────────┘ │ HTTP (port 5001) + WebSocket ▼ ┌────────────────────────────┐ │ Inova-API-Plugin │ C# plugin running inside the printer firmware. │ (sls4all/Inova-API-Plugin)│ Authoritative source for sensor semantics: │ │ • InovaApiPlugin.cs → defines /state/snapshot │ │ • exposes /movement/position/stream (~1 kHz WS) │ │ • exposes /temperature/bedmatrix/stream (~2 Hz WS) │ │ • exposes /plotter/commands/stream (per slicer cmd) └──────────────┬─────────────┘ │ REST polling + WS streams ▼ ┌────────────────────────────┐ │ Recorder repo │ TypeScript/Fastify server runs as a long-lived │ (Agentic-Additive-…-Opt) │ background process; writes to Postgres + image │ │ files on disk. │ │ server/src/recorder/telemetry.ts │ │ • polls /state/snapshot @ 10 Hz │ │ • expand() explodes each frame into the │ │ deterministic ~64 (sensor_id, kind) rows │ │ of the `telemetry` table │ │ server/src/recorder/positionStream.ts │ │ • subscribes WS /movement/position/stream │ │ • writes `position_hf` rows on motion events │ │ server/src/recorder/camera.ts │ │ • polls firmware HTTP frame endpoints │ │ • writes JPG/PNG/GIF to data/frames/{build}/ │ │ • writes one row per file in `frames` table └──────────────┬─────────────┘ │ scripts/export.py (in the recorder repo) ▼ ┌────────────────────────────┐ │ Flat exports │ Idempotent dumps of the live Postgres + frame │ data/exports/ │ files. Contract surface between the recorder │ in the recorder repo │ repo and this dataset. │ │ builds.jsonl — 30 builds │ │ events.jsonl — sparse │ │ frames.jsonl — ~1.27 M │ │ plotter_commands.jsonl — 0 rows │ │ telemetry/{build_id}.parquet — ~10 files │ │ position_hf/{build_id}.parquet — sparse │ │ build_to_inova_session.csv — sidecar │ │ sensors.csv — sidecar └──────────────┬─────────────┘ │ scripts/ticks/01_extract.py (here) ▼ ┌────────────────────────────┐ │ This dataset │ Per-build wide parquet, one row per 10 Hz tick. │ data/ticks/{NNN}.parquet │ Embedded image bytes, denormalized build │ │ context, ~79 columns including position burst. └────────────────────────────┘ ``` The two **sidecar CSVs** at the recorder layer (`build_to_inova_session.csv`, `sensors.csv`) are hand-annotated by a human, not generated. They're checked into the recorder repo and read by this dataset's ETL via the containing-repo path. ## How the data is captured ### The repos Two GitHub repos own the upstream data path. Both belong to the same user; neither is a fork. | Repo | URL | What it is | |---|---|---| | Recorder | https://github.com/ppak10/Agentic-Additive-Manufacturing-Process-Optimization | TypeScript/Fastify server + dockerized Postgres + Python tooling. Owns the live DB, the image files, and `scripts/export.py`. This dataset's ETL depends on its `data/exports/` tree. | | Inova plugin | https://github.com/ppak10/Inova-API-Plugin | C# plugin loaded by the SLS4All firmware on the printer. Exposes the REST + WebSocket endpoints the recorder polls. **Authoritative source for sensor semantics** (`InovaApiPlugin.cs`). | The recorder also pins **`sls4all/SLS4All.Compact`** as a submodule at tag `public/1.195.0` — that's the SLS4All firmware itself, kept as a read-only vendor reference. Don't touch it; it's there so the plugin can build against a known firmware ABI. Submodule layout inside the recorder repo: ``` sls4all/ Inova-API-Plugin/ # the C# plugin (our code; editable) SLS4All.Compact/ # firmware (vendor; pinned) Inova-Defect-Detection-Model/# layer-wise defect detection model datasets/ Inova-Mk1-Telemetry/ # THIS repo (update=none — never blanket --recurse-submodules; 566 GB) Inova-Mk1-Database/ # canonical printer entities (update=none) Inova-Mk1-ASTM/ # mechanical-test specimens (update=none) Inova-Mk1-Conversations/ # agent transcripts (update=none) ``` ### How the recorder runs The recorder is a single Fastify Node process plus a Postgres container. `server/src/index.ts` starts the HTTP API and **five in-process recorder workers** in parallel: | Worker | File | What it does | |---|---|---| | `startTelemetryRecorder` | `server/src/recorder/telemetry.ts` | Subscribes to plugin WS `/state/stream` at `TELEMETRY_HZ`. Calls `expand()` on each frame, batches ~100 rows / 200 ms, writes into `telemetry` table. Source of truth for ~64 sensor columns per tick. | | `startCameraRecorder` | `server/src/recorder/camera.ts` | Polls firmware HTTP endpoints at `CAMERA_HZ` for chamber and galvo frames. Writes JPG/PNG bytes to `data/frames/{build_id}/{ts_ms}_{kind}.{ext}` and a row to the `frames` table. | | `startBedMatrixRecorder` | `server/src/recorder/bedmatrix.ts` | Polls thermal IR matrix at `THERMAL_HZ`. Writes GIFs (often animated) to disk and frame rows. | | `startPositionStreamRecorder` | `server/src/recorder/positionStream.ts` | Subscribes to plugin WS `/movement/position/stream` (~1 kHz native, event-driven). Writes to `position_hf` only on motion. Sparse during heating, bursts during raster. | | `startPlotterStreamRecorder` | `server/src/recorder/plotterStream.ts` | Subscribes to plugin WS `/plotter/commands/stream`. Writes one row per CodeCommand to `plotter_commands`. Newer than the historical builds — 0 rows currently. | | `startJobDetector` | `server/src/recorder/job.ts` | Watches firmware state to open/close `builds` rows (sets `started_at`, `phase`, `ended_at`). One build is created per print run. | All workers also write structured rows into `events` on state transitions. ### Runtime configuration The recorder reads `.env` at startup (`.env.example` in the repo shows the keys, redacted). Key settings: ```ini INOVA_API_BASE_URL=http://192.168.1.146:5001 # plugin REST/WS port INOVA_FIRMWARE_BASE_URL=http://192.168.1.146 # firmware HTTP port 80 DATABASE_URL=postgres://inova:inova@localhost:5432/inova TELEMETRY_HZ=10 CAMERA_HZ=5 THERMAL_HZ=2 FRAMES_DIR=../data/frames ``` The `INOVA_API_BASE_URL` is the on-network address of the **physical printer** running the firmware + plugin. If you're working remotely, the recorder can't talk to it; rely on the already-exported flat files in `data/exports/` instead. The Postgres container (`agentic-sls-postgres`) runs locally on the same host as the Fastify server, persisted to `data/postgres/` (root-owned, accessible only inside the container). ### How to bring it up from scratch Only needed if you're rebuilding the recorder side — this dataset's ETL doesn't require any of it once `data/exports/` exists. ```sh # In the recorder repo: # Don't use blanket --recurse-submodules: this dataset (566 GB) is itself a # submodule at datasets/Inova-Mk1-Telemetry (guarded by update=none). Init # the submodules you need explicitly instead. git clone git@github.com:ppak10/Agentic-Additive-Manufacturing-Process-Optimization.git git submodule update --init sls4all/Inova-API-Plugin sls4all/SLS4All.Compact cp .env.example .env # then fill in printer IP docker compose up -d # brings up Postgres cd server && npm install # then run the Fastify server in dev/prod mode ``` The recorder writes continuously while a build is live. When you want flat files, run `python scripts/export.py` in the recorder repo — that produces the JSONL/parquet/CSV tree under `data/exports/` that this dataset's ETL consumes. ## Ecosystem (concrete paths) Assuming you're working on this machine (`/mnt/storage2`): | Repo | Filesystem path | Role | |---|---|---| | This dataset | `/mnt/storage2/GitHub/Agentic-Additive-Manufacturing-Process-Optimization/datasets/Inova-Mk1-Telemetry/` | Where you are now. A submodule of the recorder repo. ETL reads the containing repo's exports; writes `data/ticks/`. | | Recorder repo | `/mnt/storage2/GitHub/Agentic-Additive-Manufacturing-Process-Optimization/` | Owns the live DB + export script and contains this dataset as a submodule. **The only repo this dataset depends on.** This ETL reads `data/exports/`. | | Database dataset | `/mnt/storage2/GitHub/Agentic-Additive-Manufacturing-Process-Optimization/datasets/Inova-Mk1-Database/` | Fellow submodule. Informational only — *not* a dependency. Consumers can join `print_profile_name` against `source/PrintProfiles/*.json` themselves to recover the UUID; see "Joining back to Inova-Mk1-Database" in the README. | | ASTM dataset | `/mnt/storage2/GitHub/Agentic-Additive-Manufacturing-Process-Optimization/datasets/Inova-Mk1-ASTM/` | Fellow submodule. Independent leaf; no direct dependency. | `scripts/_lib.py` resolves the recorder path relative to its own location: `ROOT` is the repo root (`_lib.py` → two `.parent`s up), and then: - **Recorder** (`AGENTIC_ROOT`): `ROOT.parent.parent` — two climbs from `ROOT` (`datasets/Inova-Mk1-Telemetry` → `datasets` → recorder root). If you move the repo out of the recorder's `datasets/` folder, that climb needs updating. **Authoritative references** for sensor semantics in the recorder repo: - `sls4all/Inova-API-Plugin/InovaApiPlugin.cs` — `/state/snapshot` returns `{ position, lights, power, temperature }`. Lines 85–213 are the endpoint definitions; lines 495–507 are the `CaptureSnapshot` shape. - `server/src/recorder/telemetry.ts` lines 25–50 — `expand()` is the only place that defines which `(sensor_id, kind)` rows get written. Every row in the `telemetry` table is one entry from this function. Read this file before assuming what a column means. - `server/src/db/schema.sql` — canonical DDL for all 6 Postgres tables. ## Running the ETL ### Prerequisites 1. Sibling recorder repo at the expected path with a populated `data/exports/` directory. If it doesn't exist or is stale, run `scripts/export.py` there first. The recorder DB has to be reachable (Docker container `agentic-sls-postgres`) for the exporter to work. 2. uv installed; `pyproject.toml` deps (`pyarrow`, `polars`) will be installed via `uv sync` or auto-resolved by `uv run`. This dataset has **no other repo dependencies** at ETL time. In particular, `Inova-Mk1-Database` is not required — `print_profile_name` is preserved as a string and consumers can resolve the UUID themselves if they want. ### Commands ```sh # All builds with telemetry (full rebuild — ~2 hours, ~30 GB output) uv run scripts/ticks/01_extract.py # One or more specific builds (smoke test or incremental) uv run scripts/ticks/01_extract.py 13 # ~2 min for build 13 uv run scripts/ticks/01_extract.py 13 26 28 # build 26 is ~30 min on its own ``` The script **always overwrites** existing `data/ticks/{build_id:03d}.parquet` files — there's no skip-if-exists check. If you want incremental behavior, pass only the build IDs you want to refresh. ### Expected wall-time and output sizes From the last full run (10 builds, 1.01 M ticks total, completed 2026-06-24): | build_id | ticks | size | notes | |---:|---:|---:|---| | 1 | 102,805 | 2.9 GB | "Hex Coasters" Init/BedPrep phase | | 2 | 68 | 2.4 MB | partial — recorder joined mid-run | | 12 | 201,660 | 4.6 GB | "Hex Coasters" Layers phase | | 13 | 13,811 | 527 MB | "D790 + D638 + Benchy" Heating | | 14 | 2 | 48 KB | failed heating attempt | | 16 | 14 | 788 KB | failed heating attempt | | 17 | 2 | 32 KB | failed heating attempt | | 25 | 24 | 1.2 MB | failed heating attempt | | 26 | 355,580 | 11 GB | longest run (9h54m) | | 28 | 340,162 | 11 GB | 2026-06-07 print, 9h28m | | **total** | **1.01 M** | **30 GB** | wall time: **2h 7m** | Wall time is dominated by IO — each non-null `frame_*` column triggers a disk read from `data/frames/{build_id}/{ts_ms}_{kind}.{ext}` in the recorder repo. CPU/RAM are unremarkable. ### Verifying output ```sh # Schema sanity uv run python -c " import pyarrow.parquet as pq pf = pq.ParquetFile('data/ticks/026.parquet') print(f'rows: {pf.metadata.num_rows:,}, row_groups: {pf.metadata.num_row_groups}') for f in pf.schema_arrow: if f.name.startswith('frame_'): print(f' {f.name}: {f.type}') " # Expected: struct on all three frame_* columns. # Decode one embedded image to confirm bytes are valid uv run --with pillow python -c " import polars as pl, io from PIL import Image df = pl.read_parquet('data/ticks/026.parquet', columns=['frame_chamber']) row = df.filter(pl.col('frame_chamber').is_not_null()).head(1).row(0, named=True) img = Image.open(io.BytesIO(row['frame_chamber']['bytes'])) print(img.format, img.size) " # Expected: JPEG (600, 650) or similar. # Frame-attached rates per build uv run python -c " import polars as pl df = pl.read_parquet('data/ticks/026.parquet', columns=['frame_chamber','frame_galvo','frame_thermal']) for c in df.columns: print(f'{c}: {df[c].is_not_null().sum():,} / {df.height:,}') " # Expected: chamber ~36%, galvo ~37%, thermal ~16%. ``` ## Where humans must intervene Two pieces of context can't be derived; they live in the recorder repo and someone has to edit them by hand: - `Agentic-…-Optimization/data/exports/build_to_inova_session.csv` — maps `build_id` → `inova_session_id UUID`. Until filled in, `inova_session_id` is null in every row here and consumers fall back to name-based joining via `print_profile_name`. Recommended cadence: edit when you add a new build that maps to a known `PrintSession`. - `Agentic-…-Optimization/data/exports/sensors.csv` — `(sensor_id, kind, unit, description)`. The `unit` and `description` columns are blank by default. This dataset's card cites those values when describing column meanings. Until filled in, we hardcode firmware conventions (temps °C, power W, position microns) in this CLAUDE.md and in the README. Neither blocks the ETL. They improve dataset metadata. ## Architectural decisions - **One config, not four.** Early iteration had separate `builds`, `telemetry`, `position_hf`, and `frames` configs. Replaced with a single `ticks` config because ML consumers almost always want the joined view: state + frame + position at one moment in time. The four-silo version pushed the join cost onto every downstream user. - **Anchor on the 10 Hz telemetry tick, not strict outer join.** The recorder's `/state/snapshot` poll fires at 10 Hz and `expand()` emits a deterministic ~64-row burst into the `telemetry` table — so a tick already represents a full state snapshot. Anchoring on ticks gives every row densely populated columns; frames and `position_hf` attach to the tick they're closest to. A strict outer join across all stream timestamps gave ~3M mostly-sparse rows for less ML value. - **Wide format, dotted column names matching upstream.** Sensor columns are named exactly `{sensor_id}.{kind}` — e.g. `powderBed.temp.current`, `laser.power`, `positions.position.x`. This matches the upstream `sensors.csv` glossary 1:1 so unit annotations land where consumers will look. ~64 sensor columns + build context + frame paths + bedmatrix + position burst = 79 columns total. - **Frames attach by nearest-before-tick within a 100 ms window** and **the image bytes are embedded inline**. Frame timestamps don't align with telemetry ticks (chamber 5 Hz, thermal 2 Hz, galvo varies). For each tick we look back 100 ms and grab the most recent frame of each kind; nulls when nothing landed. Each `frame_*` column is a struct of `{bytes: binary, path: string}` matching HF's `Image` feature wire format — declared as `dtype: image` in the README so `datasets` decodes to `PIL.Image` on access. The `path` field inside the struct is the original relative filename (`"26/1780265532038_chamber.jpg"`) preserved for traceability back to the recorder repo. - **Null is preserved when no frame attaches** — we explicitly did **not** forward-fill the latest captured frame. Reason: shuffled training with forward-fill would pair the same image with widely varying telemetry rows (e.g. one chamber jpg stamped onto thousands of consecutive ticks during a 30-min heating phase), teaching the model spurious associations. Filtering null-frame rows at consume time is a one-liner; recovering "this image is stale" from a forward-filled column is impossible. - **`bedmatrix` is the IR temperature matrix as raw numbers, not a rendered image.** It attaches nearest-before-tick within the same 100 ms window as frames, but embeds as a numeric struct `{width: int32, height: int32, values: list (row-major °C), path: string}` — a 32×24 = 768-cell bed-surface temperature grid, null when nothing landed. **History:** through 2026-07-12 the same sensor was captured as a pre-rendered GIF heatmap under frame kind `thermal` (the source of `frame_thermal`, HTTP-polled from `/api/bedmatrix/image/`). Recorder commit `8d98e0c` dropped that poll; the dedicated `bedmatrix.ts` WS recorder (`/temperature/bedmatrix/stream`) now streams the raw matrix as JSON under kind `bedmatrix`. That JSON stream has actually run since build 13, so `bedmatrix` backfills across the whole dataset and is strictly richer than the old heatmap. Consequence: **`frame_thermal` is null for builds captured after 2026-07-12** (044 is the last with it; 046 has none) — use `bedmatrix` for thermal from there on. To recover a heatmap image, colormap `values` reshaped to `height × width`. - **`position_hf` preserved as per-tick bursts.** The firmware emits `PositionChangedHighFrequency` event-driven, not at fixed 1 kHz — so it bursts during motion and is empty during heating. We keep the full burst inside each tick's window as `position_hf_burst: list>`. Empty list when no motion. Lossless within the 100 ms window; the raw `position_hf/{build_id}.parquet` upstream is the fallback if you need motion data between ticks. - **Build context denormalized into every row.** `build_id`, `job_name`, `started_at`, `ended_at`, `phase`, `print_profile_name`, `inova_session_id` repeat on every row. Parquet dictionary encoding makes this essentially free (~1 byte per row regardless of value). - **`print_profile_name` only, no `print_profile_id`.** The recorder's `events.jsonl` carries the *name* a build started with; the UUID lives in `Inova-Mk1-Database/source/PrintProfiles/*.json`. Earlier versions of the ETL cached the name→UUID lookup into a `print_profile_id` column, but doing that turned `Inova-Mk1-Database` into an ETL-time dependency for a one-line consumer join. We dropped the column so this dataset stands on its own with only the recorder repo. Consumers who want the UUID can join externally — see the README section "Joining back to Inova-Mk1-Database." - **One parquet file per build.** `data/ticks/{build_id:03d}.parquet` (zero-padded to 3 digits so a lexical `ls` sorts numerically and the layout caps cleanly at 999 builds). HF globs `data/ticks/*.parquet` to load the full dataset. Builds without telemetry produce no file; consumers should expect missing build IDs. - **Polars for the pivot + asof joins.** ~22 M telemetry rows (build 26) pivot to ~355 K ticks in seconds. Polars' `pivot` and `join_asof(tolerance=100ms)` do the heavy lifting; the position_hf burst is a manual sorted-merge. - **Streaming chunked write for the embed step.** With image bytes inlined, build 26 alone is ~11 GB on disk. The writer is a `pyarrow.parquet.ParquetWriter` fed `CHUNK_ROWS=2000`-row slices; each slice does its own image-bytes read, so peak working set per chunk is bounded (~500 MB even for thermal-heavy builds). Polars handles the upstream pivot/join; pyarrow handles the streaming output. ## Directory layout ``` .python-version # 3.13 pyproject.toml # pyarrow, polars, imageio[ffmpeg], pillow, numpy .gitattributes # *.parquet, *.mp4, *.gif → LFS scripts/ _lib.py # recorder-repo paths + JSONL streaming ticks/ 00_recover_spool41.py # one-off: recover build 41 from NVMe spool (DB was wiped) 00_export_new_db.py # one-off: export DB builds with ID remap (old_id:new_id; identity N:N since 2026-07-13) 01_extract.py # the single ETL — wide-pivot + asof + burst + embed previews/ 01_render.py # per-build MP4 previews from data/ticks/ 02_timelapse.py # per-build timelapse GIFs, one frame per print layer data/ ticks/{build_id:03d}.parquet # LFS; e.g. 001.parquet, 026.parquet previews/ {build_id:03d}/ chamber.mp4 # LFS; optical, forward-filled, 10 fps real-time thermal.mp4 # LFS; IR matrix galvo.mp4 # LFS; scan-mirror trace composite.mp4 # LFS; 1×3 panel: chamber | thermal | galvo timelapse_chamber.gif # LFS; layer-by-layer GIF, 25 fps, ≤ 12 s timelapse_thermal.gif # LFS timelapse_galvo.gif # LFS timelapse_composite.gif # LFS; 1×3 panel GIF ``` There is no `source/` (raw data lives in the containing recorder repo's `data/exports/`). `scripts/ticks/01_extract.py` is organized as: 1. `load_builds_index()` / `load_frames_for_build()` — load upstream JSONL 2. `pivot_telemetry()` — long-to-wide on `(sensor_id, kind)` 3. `attach_frames()` — three `join_asof(strategy='backward', tolerance=100ms)` calls 4. `attach_bedmatrix()` — one more `join_asof` for the IR matrix JSON path 5. `attach_position_hf()` — manual sorted-merge to build the burst lists 6. `denormalize_build()` — `pl.lit()` columns for build context 7. `_embed_frame_column()` / `_embed_bedmatrix_column()` / `_embed_chunk()` / `process_build()` — chunked write with pyarrow `ParquetWriter` 8. `main()` — iterate target build IDs, call `process_build()` per build ## Row shape ```python # per row, ~79 columns: { # Build context (denormalized; same on every row of a given file) "build_id": 26, "ts": datetime(2026, 6, 2, 21, 16, 53, 936, tzinfo=UTC), "job_name": "D790 and D638 and Benchy 2026_06_02", "started_at": "...", "ended_at": "...", "phase": "Heating", "print_profile_name": "2026_05_30 20mJ/mm Formlabs PA12 GF", "inova_session_id": None, # filled when upstream CSV is curated # Position (microns, firmware native) — always present "positions.position.x": ..., "positions.position.y": ..., "positions.position.z1": ..., "positions.position.z2": ..., "positions.position.r": ..., # Lights "lights.lights.enabled": 0.0, "lights.lights.count": 4.0, # Power (W) — ~9 columns "laser.power": 1140.0, "fanGalvo.power": ..., "buzzer.power": ..., "powerman.power.current": 1140.0, "powerman.power.required": 1540.0, "powerman.power.max": 1300.0, ... # Temperature (°C) — ~51 columns "powderBed.temp.current": 97.32, "powderBed.temp.average": 97.11, "powderBed.temp.target": 100.0, "printBed.temp.current": ..., "printChamber1.temp.current": ..., "quadrant1.temp.current": ..., "surfaceAvg.temp.average": ..., ... # Frames — embedded HF Image structs (PIL.Image on load) or None "frame_chamber": {"bytes": b"\xff\xd8...", "path": "26/1780265532038_chamber.jpg"}, "frame_galvo": {"bytes": b"\x89PNG...", "path": "26/1780265532040_galvo.png"}, "frame_thermal": None, # legacy GIF heatmap; null for builds after 2026-07-12 # IR temperature matrix (raw numbers, replaces frame_thermal) — struct or None "bedmatrix": {"width": 32, "height": 24, "values": [97.3, 97.1, ...], # 768 floats, row-major °C "path": "26/1780433796515_bedmatrix.json"}, # 1 kHz position-stream burst within (tick_ts - 100ms, tick_ts] "position_hf_burst": [ {"ts_offset_ms": -84.2, "x": 0.123, "y": 0.045, "z1": ..., "has_homed": True}, {"ts_offset_ms": -32.7, "x": 0.131, "y": 0.046, ...}, ], } ``` ## Sensor groups (from `expand()` in the recorder) The ~64 sensor columns break down by group. All four come from a single `/state/snapshot` GET, so they share the tick timestamp exactly: | Group | Columns | Source | |---|---|---| | Position (10 Hz) | `positions.position.{x,y,z1,z2,r}` — 5 cols | `s.position[k]` for k in (x,y,z1,z2,r). Microns, firmware native. | | Lights | `lights.lights.{enabled,count}` — 2 cols | `s.lights.{isEnabled,lightCount}`. `enabled` is 0/1. | | Power (W) | `{e.id}.power` for each `s.power.entries` — typically `{laser,fanGalvo,buzzer,laserSafety,io-en,wd-en,wd-in}` — 7 cols, plus `powerman.power.{current,required,max}` — 3 cols | `s.power.entries[].id` is the per-device draw; `powerman.*` is the manager state. | | Temperature (°C) | `{e.id}.temp.{current,average,target}` for each `s.temperature.entries` — typically `{powderBed, printBed, powderChamber1..4, printChamber1..4, quadrant1..4, surface, surfaceAvg, surfaceMin, surfaceMax, testTemp1}` — ~51 cols total | `e.targetTemperature` is omitted when null, so `temp.target` columns can be null even when `current`/`average` are populated. | If `expand()` in the recorder ever changes, all of those column names change with it — no normalization here. ## Important gotchas - **`frame_*` bytes are embedded; `path` inside the struct is recorder-relative.** Each non-null frame column carries the actual image bytes plus the original relative path (`"26/1780265532038_chamber.jpg"`, meaning `Agentic-Additive-Manufacturing-Process-Optimization/data/frames/...`). The path is for traceability only — consumers don't need the recorder repo to access the image. The unattached frames (~half of the 1.27 M captured) still live only in the recorder repo; this dataset only carries the per-tick attached subset. - **`frame_thermal` is legacy and null for builds captured after 2026-07-12; use `bedmatrix` instead.** The recorder stopped polling the pre-rendered IR heatmap GIF (commit `8d98e0c`) and now streams the raw 32×24 temperature matrix as JSON under kind `bedmatrix`. Build 044 is the last with `frame_thermal`; 046 onward has none. `bedmatrix` is a numeric struct (`{width, height, values: list row-major °C, path}`), backfilled across the whole dataset (the JSON stream has run since build 13), and strictly richer — colormap `values` reshaped to `height × width` to recover a heatmap. The preview renderers now do exactly this: `previews/*/thermal.mp4`, `composite.mp4`, `timelapse_thermal.gif`, and `timelapse_composite.gif` render the thermal panel from `bedmatrix` (inferno colormap over a fixed 20–200 °C range; see `scripts/previews/_thermal.py`), falling back to `frame_thermal` only for the three earliest builds (001/002/012) that predate the stream. So thermal previews exist for all builds, including post-2026-07-12 ones. - **`positions.position.*` columns are 10 Hz**, not 1 kHz. They come from the snapshot's `position` field. For 1 kHz fidelity during motion, read `position_hf_burst`. - **`inova_session_id` is always null** until someone curates `build_to_inova_session.csv` in the recorder repo. Consumers who need an entity-graph link can fall back to joining on `print_profile_name` against `Inova-Mk1-Database` meanwhile. - **`build_id` is a Postgres BIGSERIAL**, not a UUID. One Database `PrintSession` may have many `build_id`s (one per recorder restart / attempt). That's why session-id mapping must be hand-authored. - **Sensor units are firmware-convention, not labeled in this dataset.** `*.temp.*` are °C, `*.power*` are W, `positions.position.*` are **microns** (firmware native; divide by 1000 for mm). Authoritative annotations live in the upstream `sensors.csv` glossary; when it's filled in, the dataset card will be updated. - **Builds without `telemetry/{build_id}.parquet` produce no file here.** `data/ticks/` will have gaps for failed-heating runs (typically 12–38 s with zero recorded telemetry). - **The 100 ms window is the recorder's tick interval.** Frame attachment is "the most recent frame within the prior tick interval"; this is a design choice (could be wider or interpolated). If a frame is more than 100 ms stale at tick time, it's null even if it's the closest existing frame. Consider widening the window if frame_kind null rates feel too high. - **The ETL always overwrites.** No skip-if-exists. If you only want incremental refresh, pass specific build IDs on the command line. - **`events` and `plotter_commands` upstream tables are not exposed here.** `events` (78 rows) is sparse; `plotter_commands` (0 rows) postdates the historical builds. Both stay upstream-only for v1. - **The recorder repo is a moving target.** It's actively developed; new sensors, new build records, schema changes can appear. Diff `server/src/db/schema.sql` and `server/src/recorder/telemetry.ts` against your last known state before relying on column names. ## Current state - `ticks` config: 26 parquet files across builds 001–046 (with gaps; 045 is an empty/aborted build with no telemetry, so no file). Build 041 was recovered from the NVMe spool after the Postgres DB was wiped. Builds 042–043 were added under the old offset scheme; builds 044 and 046 were added 2026-07-13 via **identity mapping** now that the DB realigned to 1:1 — see "Build ID mapping" below. - `print_profile_name` is preserved on every row; the `print_profile_id` UUID is *not* materialized here (see the architectural decision above). - `events` and `plotter_commands` not surfaced as configs. - **`peregrine` config** (added 2026-07-19): sparse, defect-labeled counterpart to `ticks`, shaped like the ORNL Peregrine dataset — one row per *labeled layer*, `data/peregrine/{build:03d}.parquet`, built by `scripts/peregrine/01_extract.py` from `source/labels/` + `data/frames_index/` + `source/telemetry/`. Images are raw JPEG/PNG `binary` (post-recoat chamber = `image_after_powder`, post-scan chamber = `image_after_melt`, galvo = `part_mask`), labels are bbox-level `list<{class,bbox,polarity}>` + `has_` bools + a few process scalars. Only re-runs the changed build (no full rewrite). Post-recoat vs post-scan stills are split by the z2 **step** preceding each label (z2 ramps monotonically to ~29 mm — it does NOT cycle to 0 per recoat; don't reuse the return-to-0 heuristic). Prereqs per build: `sls-export` + `sls-export-labels` + `sls-deliver-frames` must have run. - **Forward-fill semantics deferred.** Current attach is "fresh frame within 100 ms of tick or null." Carrying the latest captured frame forward to fill null rows is left to consumers (one-line groupby + ffill); baking it into the dataset would destroy the fresh-vs-stale signal that's the whole point of keeping nulls. - `previews/` MP4s and timelapse GIFs: rendered through 046. Timelapse GIFs re-rendered 2026-07-13 with `CHAMBER_BRIGHTNESS_RATIO` raised 0.25 → 0.5 to drop dim-frame flashes. ## Build ID mapping **History.** The recorder's Postgres DB was wiped between build 040 and the next print (2026-07-09). The new DB briefly restarted its `builds_id_seq` at 1, so builds 042–043 were added under an **offset** (DB id 1→042, 2→043) to avoid colliding with the existing dataset files. **Current state (verified 2026-07-13).** The DB has since realigned: it now holds builds 1–46 carrying the original job names, and **`build_id` matches the dataset id 1:1** — no offset needed. Builds carrying telemetry: `42, 43, 44, 46`. Build 45 is empty (aborted: no `ended_at`, 0 telemetry rows, `None` job name) and produces no dataset file. The exact mechanism of the realignment (restore from backup vs. re-import) is unconfirmed; treat the DB as a moving target and re-verify IDs before each import. **To add a new build**, use `00_export_new_db.py` with an **identity mapping** (`N:N`) — it scopes the export to one build and appends only that build's rows to the shared JSONL files (safer than re-running the recorder's `export.py`): ```sh uv run --with psycopg2-binary scripts/ticks/00_export_new_db.py 46:46 uv run scripts/ticks/01_extract.py 46 uv run scripts/previews/01_render.py 46 uv run scripts/previews/02_timelapse.py 46 ``` Before running, query the DB to confirm the target build has `ended_at` set and non-zero telemetry, and that its id doesn't already have a `data/ticks/{id:03d}.parquet`. **Don't run two `00_export_new_db.py` invocations concurrently** — they all append to the same `builds.jsonl`/`frames.jsonl`/`events.jsonl`, so parallel appends interleave and corrupt them. Run builds one at a time. Frame files live in `data/frames/{build_id}/` and the paths stored in `frames.jsonl` reference those same ids, so the ETL reads them without renaming. ## Adding a build — recipe **If the recorder DB is healthy (sequence hasn't reset):** 1. New build runs in the recorder, produces telemetry / frames / position_hf in Postgres + on disk. 2. Run `scripts/export.py` in the recorder repo to refresh `data/exports/`. Pass `--builds N` to scope to one build if you don't want to re-export everything. 3. (Optional) edit `Agentic-…-Optimization/data/exports/build_to_inova_session.csv` for the `inova_session_id` UUID. 4. `uv run scripts/ticks/01_extract.py N` → `data/ticks/NNN.parquet` 5. `uv run scripts/previews/01_render.py N` → four MP4s under `previews/NNN/` 6. `uv run scripts/previews/02_timelapse.py N` → four timelapse GIFs under `previews/NNN/` 7. `git add data/ticks/NNN.parquet previews/NNN/` (LFS) and commit. **If the DB IDs don't line up with the recorder's `export.py` expectations** (e.g. after a reset/realignment): use `00_export_new_db.py` with an `old_id:new_id` mapping instead of step 2 — currently an identity mapping (`N:N`). See "Build ID mapping" above. ## Regenerate everything ```sh rm -f data/ticks/*.parquet uv run scripts/ticks/01_extract.py ``` Takes ~2 hours, produces ~30 GB. The IO is the bottleneck; the Polars pivot and asof joins are fast. ## Preview videos and timelapse GIFs ### MP4 previews (`01_render.py`) `scripts/previews/01_render.py` walks `data/ticks/*.parquet` and emits four MP4s per build under `previews/{build_id:03d}/`: - `chamber.mp4` — optical, from `frame_chamber` - `thermal.mp4` — IR matrix, from `frame_thermal` - `galvo.mp4` — scan-mirror trace, from `frame_galvo` - `composite.mp4` — 1×3 panel (chamber | thermal | galvo) Design choices: - **Real-time playback at 10 fps** — output duration matches build wall-clock. Null cells are forward-filled (viewing convenience only; not training data). - **Letterbox-fit into a canvas locked by the first non-null frame** (handles thermal dim drift). - **Streamed row-group iteration** (`BATCH_ROWS=1000`) — necessary for 11+ GB parquets. - **NVENC encode** (`h264_nvenc`, K620 GPUs) with libx264 fallback (`RENDER_CPU=1`). ```sh uv run scripts/previews/01_render.py # all builds uv run scripts/previews/01_render.py 13 26 # specific builds uv run scripts/previews/01_render.py 26 --kinds chamber,composite ``` ### Timelapse GIFs (`02_timelapse.py`) `scripts/previews/02_timelapse.py` emits four animated GIFs per build: - `timelapse_chamber.gif`, `timelapse_thermal.gif`, `timelapse_galvo.gif` - `timelapse_composite.gif` — 1×3 panel **Layer detection:** `positions.position.z2` is quantized in 100 µm buckets. Only z2 > 0 rows are used — z2 stays at 0 during pre-print heating, so this naturally excludes non-printing ticks. The *last* non-null frame in each z2 bucket is the representative (most-recent view of the layer just before recoating). **Playback:** 25 fps, capped at 300 frames (max 12 s GIF). Builds with fewer than 300 detected layers are not padded. Null-frame levels are forward-filled within the GIF. Canvas height 240 px (half the MP4 height) to keep file sizes web-friendly. **Composite pass:** does a single parquet stream reading all three frame columns at once (not three separate passes). ```sh uv run scripts/previews/02_timelapse.py # all builds uv run scripts/previews/02_timelapse.py 26 28 # specific builds uv run scripts/previews/02_timelapse.py 26 --kinds chamber,composite ``` Always overwrites. For incremental work, name the build IDs.