Add your description here
Project description
crgutils
crgutils is a Python library for loading, validating, and evaluating ASAM OpenCRG road surface files.
Supported formats and capabilities:
- ASCII
.crginputs inLRFIandLDFIformats - Binary
.crginputs inKRBIandKDBIformats - 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 demosdemo/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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file crgutils-0.1.0.tar.gz.
File metadata
- Download URL: crgutils-0.1.0.tar.gz
- Upload date:
- Size: 22.6 kB
- Tags: Source
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31440cf70bee193072527c18a7aa8997e109f98c73ffff510acf4a75fc9ab67f
|
|
| MD5 |
0ab7a8f47c9ed826a547964a457a07d0
|
|
| BLAKE2b-256 |
6c9516cb350b059f7154f95a7dafde2be8d7916ee6821a258f8edcf23365b12b
|
File details
Details for the file crgutils-0.1.0-py3-none-any.whl.
File metadata
- Download URL: crgutils-0.1.0-py3-none-any.whl
- Upload date:
- Size: 27.1 kB
- Tags: Python 3
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9a601a5528fdf0a5d29c7964ba607ba8fb6a877189fd126a410d970899dbad0
|
|
| MD5 |
6bfbbae6f1cb26a7df6dac834830cdff
|
|
| BLAKE2b-256 |
2337a21468fb52ce27d4d46a13acbc60676406a5278e8c3d8b83a1dedf13ce2d
|