Skip to main content

crgutils

crgutils is a Python library for loading, validating, and evaluating ASAM OpenCRG road surface files.

Supported formats and capabilities:

  • ASCII .crg inputs in LRFI and LDFI formats
  • Binary .crg inputs in KRBI and KDBI formats
  • Road-space queries (u, v) → z, (u, v) → (x, y), (u, v) → (phi, kappa)
  • World-space queries (x, y) → z, (x, y) → (u, v), (x, y) → (phi, kappa)
  • All five border modes: NONE, EX_ZERO, EX_KEEP, REPEAT, REFLECT
  • Header-defined evaluation options and pending runtime modifiers

Install

Core package:

uv sync

Core package with test dependencies:

uv sync --extra dev

If you also want the demo workspace members, especially the visualizer's extra dependencies:

uv sync --all-packages

Python 3.11+ is required.

Quick Start

import crgutils

ds = crgutils.read("samples/crg-txt/handmade_straight.crg")  # load + validate + apply modifiers
cp = ds.create_contact_point()                                 # default options

z = cp.eval_uv_to_z(10.0, 0.0)            # elevation at road (u=10, v=0)
x, y = cp.eval_uv_to_xy(10.0, 0.5)        # road → world coords
u, v = cp.eval_xy_to_uv(x, y)             # world → road coords
phi, kappa = cp.eval_uv_to_pk(10.0, 0.0)  # heading and curvature

Override evaluation options when creating the contact point:

cp = ds.create_contact_point(border_mode_u=crgutils.BorderMode.REPEAT)

API Surface

Symbol Purpose
crgutils.read(path, **kwargs) Load, validate, and prepare a .crg file; returns CRGDataset
dataset.create_contact_point(**options) Create a ContactPoint evaluation context
crgutils.ContactPoint(dataset, **options) Stateful evaluation context (direct constructor)

Exported types:

Type Description
CRGDataset Parsed road surface (arrays + metadata)
EvalOptions Frozen dataclass for evaluation parameters
BorderMode NONE / EX_ZERO / EX_KEEP / REPEAT / REFLECT
RefLineContinue EXTRAPOLATE / CLOSE_TRACK
CurvMode LATERAL / REF_LINE
GridNaNMode KEEP / SET_ZERO / KEEP_LAST

ContactPoint evaluation methods

cp.eval_uv_to_z(u, v)        float            # elevation from road coords
cp.eval_xy_to_z(x, y)        float            # elevation from world coords
cp.eval_uv_to_xy(u, v)       (float, float)   # road → world
cp.eval_xy_to_uv(x, y)       (float, float)   # world → road
cp.eval_uv_to_pk(u, v)       (float, float)   # heading, curvature
cp.eval_xy_to_pk(x, y)       (float, float)   # heading, curvature
cp.eval_uv_to_z_grid(u, v)   np.ndarray       # vectorised elevation
cp.eval_xy_to_z_grid(x, y)   np.ndarray       # vectorised elevation
cp.with_options(**overrides)  ContactPoint     # new context, shared dataset

Sample Data

Bundled sample files live in:

samples/crg-txt/    ASCII CRG files (straight, curved, banked, sloped, circle, …)
samples/crg-bin/    Binary CRG files (Belgian block cobblestone, country road, …)

Both the demo scripts and the test suite load from these directories.

Demos

The repository has two demo areas:

  • demo/c-api/ contains Python ports of the upstream OpenCRG C API demos
  • demo/viz/ contains interactive visualization tools with their own dependencies

C-API Demo Ports

uv run python demo/c-api/simple.py                        # xy→z on a 2D grid
uv run python demo/c-api/reader.py                        # header / channel / road info
uv run python demo/c-api/curvature.py                     # curvature profile
uv run python demo/c-api/eval_z.py                        # uv→z, round-trip z, pk
uv run python demo/c-api/eval_xy_uv.py                    # uv→xy→uv round-trips
uv run python demo/c-api/eval_options.py                  # 29 option/modifier tests

Each script defaults to a file in samples/crg-txt/ and accepts an explicit path:

uv run python demo/c-api/reader.py samples/crg-bin/belgian_block.crg
uv run python demo/c-api/eval_xy_uv.py samples/crg-txt/handmade_curved.crg
uv run python demo/c-api/eval_options.py -t 5   # run only test 5

Pass --help to any script for usage details.

Visualizer

The visualizer lives in the viz workspace member and includes both a marimo app and a notebook:

uv sync --package viz
uv run --package viz marimo edit demo/viz/crg_viz.py
uv run --package viz jupyter notebook demo/viz/render.ipynb

The marimo app lets you browse bundled sample files or point it at any local .crg file.

Tests

uv run pytest

The test suite covers the loader, all evaluation functions, all five border modes, modifiers, check(), ContactPoint option inheritance, and round-trip accuracy.

Repository Layout

src/crgutils/   library source
samples/        bundled CRG sample files (crg-txt/ and crg-bin/)
demo/c-api/     Python ports of the OpenCRG C API demos
demo/viz/       visualization app and notebook
tests/          pytest test suite

Notes

  • The binary Belgian-block sample contains all-NaN edge channels that produce expected RuntimeWarnings from NumPy when computing array summaries; the file still loads and is fully covered by tests.

Release files for crgutils 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for crgutils 0.1.1
File Size Uploaded
crgutils-0.1.1.tar.gz 22.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for crgutils 0.1.1
File Interpreter ABI Platform
crgutils-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 49.8 kB

Release files / crgutils-0.1.1.tar.gz

Download URL crgutils-0.1.1.tar.gz
Size 22.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2cdcb8613230988bf776085076228abffaaeac1bab15f4b6744ac0fe0873c4b8
BLAKE2b-256 checksum
How to use checksums
f858545300211ce4ad32e0f5e478e54a8ea481c44cb515961ef72270dc4c4e55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / crgutils-0.1.1-py3-none-any.whl

Download URL crgutils-0.1.1-py3-none-any.whl
Size 27.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7c8c566491342807495aed47a4a9fdf339f357e20b2dce2df41119579461b16b
BLAKE2b-256 checksum
How to use checksums
c26cb3838f7696439e8bf916def14128f584602216da667481760e964888f6c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page