Skip to content

Consolidate per-dataset geometry helpers into utils.geometry#21

Merged
stepankonev merged 1 commit into
mainfrom
consolidate-geometry-utils
Jun 5, 2026
Merged

Consolidate per-dataset geometry helpers into utils.geometry#21
stepankonev merged 1 commit into
mainfrom
consolidate-geometry-utils

Conversation

@stepankonev

Copy link
Copy Markdown
Owner

Removes geometry code that was reimplemented across dataset processors, and replaces in-repo math with scipy where it already lived.

What

A new standard_e2e/utils/geometry.py centralises five operations that were duplicated per dataset:

  • quats_wxyz_to_rotmats / quat_wxyz_to_rotmat — Hamilton (w,x,y,z) quaternion → rotation matrix, backed by scipy.spatial.transform.Rotation. The scalar-first→scalar-last (xyzw) reorder scipy needs now lives in one place.
  • se3(rotation, translation) — 4×4 SE(3) assembly.
  • intrinsics_matrix(fx, fy, cx, cy) — pinhole K.
  • transform_points(transform, points) — homogeneous (N,3) transform.

comma2k19, WayveScenes (incl. the COLMAP reader), NAVSIM, and Argoverse 2 now all route through these. Notably comma2k19 and wayve_scenes/_colmap were hand-rolling the Hamilton quaternion formula that NAVSIM/AV2 already obtained from scipy — that duplication (and convention-handling drift risk) is gone.

Safety

  • A regression test (tests/test_geometry.py::test_quats_match_hand_rolled_hamilton_formula) asserts the scipy-backed helper reproduces the previous hand-rolled Hamilton formula bit-for-bit (max abs diff ~1e-15 over random unit quaternions) — important because comma2k19's coordinate convention is empirically locked.
  • scipy is declared as a direct dependency (it was already pulled in transitively and imported by the NAVSIM/AV2 processors); uv.lock relocked.

Tests

black / isort / flake8 / mypy clean; pytest passes (tests/test_geometry.py 6/6, plus the comma2k19 / wayve / colmap suites that exercise the migrated paths).

Note: the two test_navsim_dataset_processor.py real-log tests fail on this machine regardless of this branch — nuplan's HD-map loader tries to create a .maplocks dir under the read-only /mnt/bigdisk/datasets mount (PermissionError); verified the same failure on main.

Quaternion->rotation, SE(3) assembly, camera-intrinsics, and homogeneous
point-transform logic was reimplemented across the comma2k19, WayveScenes,
NAVSIM, and Argoverse 2 processors -- comma2k19 and wayve_scenes/_colmap even
hand-rolled the Hamilton quaternion formula that NAVSIM and AV2 already get
from scipy.

Add standard_e2e/utils/geometry.py (quats_wxyz_to_rotmats / quat_wxyz_to_rotmat,
se3, intrinsics_matrix, transform_points) and route all four datasets through
it; the scalar-first wxyz <-> scalar-last xyzw reorder scipy needs now lives in
one place. A regression test asserts the scipy-backed quaternion helper
reproduces the old hand-rolled formula bit-for-bit.

Declare scipy as a direct dependency (it was already imported transitively) and
relock.
@codecov

codecov Bot commented Jun 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.36364% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...atasets/av2_sensor/av2_sensor_dataset_processor.py 25.00% 3 Missing ⚠️
...ng/src_datasets/navsim/navsim_dataset_processor.py 50.00% 2 Missing ⚠️
...ets/wayve_scenes/wayve_scenes_dataset_processor.py 75.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@stepankonev stepankonev merged commit 24456bc into main Jun 5, 2026
3 checks passed
@stepankonev stepankonev deleted the consolidate-geometry-utils branch June 5, 2026 05:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant