omega-prime: Tutorial for using the python library¶
Create omega-prime files¶
To create files in accordance with the omega-prime specification, you need the map information as ASAM OpenDRIVE XML and the infomration on dynamic elements as ASAM OSI GroundTruth messages. Alternatively, the information on dynamic elements can be provided as a table.
Create from ASAM OSI¶
The following code creates a omega-prime file from an ASAM OSI trace file (e.g., created from esmini (see example_files/README.md)) and an ASAM OpenDRIVE map.
import omega_prime
r = omega_prime.Recording.from_file(
"../../example_files/pedestrian.osi", map_path="../../example_files/fabriksgatan.xodr", apply_proj=False
)
r.to_mcap("example.mcap")
If you have large amount of data (e.g., 32.000 objects over a whole day), we suggest using the Apache Parquet file format to store omega-prime data. To do so run the following
r.to_parquet("example.parquet")
Parquet files created with the method can be loaded with the from_file function
r = omega_prime.Recording.from_file("example.mcap", apply_proj=False)
Create from table¶
You can also directly create a recording from object data in table form (we use polars). Create a table df like the following:
| total_nanos | idx | x | y | z | vel_x | vel_y | vel_z | acc_x | acc_y | acc_z | length | width | height | roll | pitch | yaw | type | role | subtype |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 42.6987 | -69.8783 | 0.75 | -2.04032 | 9.78964 | 0 | 0 | 0 | 0 | 5.04 | 2 | 1.5 | 0 | 0 | 1.77627 | 2 | 0 | 4 |
| 0 | 1 | 35.6784 | -23.5705 | 0.923 | 0 | 0 | 0 | 0 | 0 | 0 | 0.6 | 0.5 | 1.8 | 0 | 0 | 1.7984 | 3 | -1 | -1 |
| 3.3e+07 | 0 | 42.6306 | -69.5554 | 0.75 | -2.04288 | 9.78896 | 0 | -0.0774077 | -0.020523 | 0 | 5.04 | 2 | 1.5 | 0 | 0 | 1.7768 | 2 | 0 | 4 |
| 3.3e+07 | 1 | 35.6784 | -23.5705 | 0.923 | 0 | 0 | 0 | 0 | 0 | 0 | 0.6 | 0.5 | 1.8 | 0 | 0 | 1.7984 | 3 | -1 | -1 |
| 6.6e+07 | 0 | 42.5623 | -69.2325 | 0.75 | -2.04801 | 9.7879 | 0 | -0.155563 | -0.0323452 | 0 | 5.04 | 2 | 1.5 | 0 | 0 | 1.77732 | 2 | 0 | 4 |
| 6.6e+07 | 1 | 35.6784 | -23.5705 | 0.923 | 0 | 0 | 0 | 0 | 0 | 0 | 0.6 | 0.5 | 1.8 | 0 | 0 | 1.7984 | 3 | -1 | -1 |
type, subtyp and role have to be integers and correspond to the enumerations betterosi.MovingObject.Type, betterosi.MovingObject.VehicleClassification.Type and betterosi.MovingObject.VehicleClassification.Role. The role and subtype have to be -1 when the type is not of VEHICLE.
The enumartions are defined as shown below.
import betterosi
print(f"MovingObject.Type: { ({o.name: o.value for o in betterosi.MovingObject.Type}) }")
print(
f"MovingObject.VehicleClassification.Type: { ({o.name: o.value for o in betterosi.MovingObject.VehicleClassification.Type}) }"
)
print(
f"MovingObject.VehicleClassification.Role: { ({o.name: o.value for o in betterosi.MovingObject.VehicleClassification.Role}) }"
)
MovingObject.Type: {'UNKNOWN': 0, 'OTHER': 1, 'VEHICLE': 2, 'PEDESTRIAN': 3, 'ANIMAL': 4}
MovingObject.VehicleClassification.Type: {'UNKNOWN': 0, 'OTHER': 1, 'SMALL_CAR': 2, 'COMPACT_CAR': 3, 'CAR': 4, 'LUXURY_CAR': 5, 'DELIVERY_VAN': 6, 'HEAVY_TRUCK': 7, 'SEMITRACTOR': 16, 'SEMITRAILER': 8, 'TRAILER': 9, 'MOTORBIKE': 10, 'BICYCLE': 11, 'BUS': 12, 'TRAM': 13, 'TRAIN': 14, 'WHEELCHAIR': 15, 'STANDUP_SCOOTER': 17, 'MICROMOBILITY_DEVICE': 18, 'WORK_MACHINE': 19, 'WATERCRAFT': 20, 'AIRCRAFT': 21, 'LAND_VEHICLE': 22}
MovingObject.VehicleClassification.Role: {'UNKNOWN': 0, 'OTHER': 1, 'CIVIL': 2, 'AMBULANCE': 3, 'FIRE': 4, 'POLICE': 5, 'PUBLIC_TRANSPORT': 6, 'ROAD_ASSISTANCE': 7, 'GARBAGE_COLLECTION': 8, 'ROAD_CONSTRUCTION': 9, 'MILITARY': 10}
import polars as pl
import omega_prime
df = pl.read_csv("../../example_files/example.csv")
r = omega_prime.Recording(df=df, map=omega_prime.MapOdr.from_file("../../example_files/fabriksgatan.xodr"))
Read and plot omega-prime file¶
import omega_prime
By default the map information is not parsed. For parsing the map we utilize pyxodr. To directly parse the map you have to set parse_map=True.
r = omega_prime.Recording.from_file("example.mcap", parse_map=True, apply_proj=False)
ax = r.plot()
ax.set_xlim(-20, 50)
ax.set_ylim(-75, 20)
(-75.0, 20.0)
ax = r.plot_frame(10)
ax.set_xlim(-20, 50)
ax.set_ylim(-75, 20)
(-75.0, 20.0)
r.plot_altair(start_frame=0, end_frame=400, metric_column="vel_y", idx=0)
r.map
<omega_prime.map_odr.MapOdr at 0x7bf7179623f0>
r.moving_objects
{0: <omega_prime.recording.MovingObject at 0x7bf7178a86e0>,
1: <omega_prime.recording.MovingObject at 0x7bf7176c9950>}
File Validation¶
By default, data is validated on file reading which takes time. to skip validation read the file with omega_prime.Recording.from_file(..., validate=False)
Interpolation¶
A simple (angle aware) linear (nearest neighbour for classification type data) interpolation function is build in
r.interpolate(hz=10)
r.interpolate(new_nanos=[0, int(1e8), int(2e8), int(3e8)])
CLI usage¶
!omega-prime --help
Usage: omega-prime [OPTIONS] COMMAND [ARGS]... ╭─ Options ────────────────────────────────────────────────────────────────────╮ │ --install-completion Install completion for the current shell. │ │ --show-completion Show completion for the current shell, to copy │ │ it or customize the installation. │ │ --help Show this message and exit. │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Commands ───────────────────────────────────────────────────────────────────╮ │ from-lxd Convert datasets from LevelXData to omega-prime. │ │ qualify Qualify Omega Prime dataframe. │ │ from-osi Convert from ASAM OSI GroundTruth trace. │ │ from-csv Convert from csv table according to schema │ │ validate Check an omega-prime file for specification │ │ conformance. │ │ to-odr Extracts the ASAM OpenDRIVE file from the │ │ omega-prime file. │ │ to-parquet Converts MCAP or OSI omega-prime into a parquet file │ │ (beneficial for faster loading of large data). │ │ visualize Visualize an omega-prime recording using Altair. │ │ Opens interactive plot in browser. │ │ attach-odr Attach an ASAM OpenDRIVE (.xodr) map to an existing │ │ omega-prime recording and write a new file. │ │ materialize-projection Export the currently projected coordinates as │ │ canonical coordinates. Useful for viewers such as │ │ Lichtblick that do not apply OSI projection │ │ metadata. │ ╰──────────────────────────────────────────────────────────────────────────────╯
Create Omega file from ASAM OSI and ASAM OpenDRIVE¶
!omega-prime from-osi --help
Usage: omega-prime from-osi [OPTIONS] {input} {output} Convert from ASAM OSI GroundTruth trace. ╭─ Arguments ──────────────────────────────────────────────────────────────────╮ │ * input <file> Path to ASAM OSI trace file (either `.osi` or │ │ `.mcap`) │ │ [required] │ │ * output <file> Desired filename of omega file [required] │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Options ────────────────────────────────────────────────────────────────────╮ │ --map-path <file> Path to ASAM OpenDRIVE xml to use as │ │ map │ │ --validate --no-validate [default: validate] │ │ --help Show this message and exit. │ ╰──────────────────────────────────────────────────────────────────────────────╯
!omega-prime from-osi ./../../example_files/pedestrian.osi example.mcap --map-path ./../../example_files/fabriksgatan.xodr
Create Omega file from CSV and ASAM OpenDRIVE¶
!omega-prime from-csv --help
Usage: omega-prime from-csv [OPTIONS] {input} {output} Convert from csv table according to schema ╭─ Arguments ──────────────────────────────────────────────────────────────────╮ │ * input <file> Path to csv according to omega moving object csv │ │ schema │ │ [required] │ │ * output <file> Desired filename of omega file [required] │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Options ────────────────────────────────────────────────────────────────────╮ │ --odr <file> Path to ASAM OpenDRIVE xml to use as │ │ map │ │ --validate --no-validate [default: validate] │ │ --help Show this message and exit. │ ╰──────────────────────────────────────────────────────────────────────────────╯
!omega-prime from-csv ./../../example_files/example.csv example.mcap --odr ./../../example_files/fabriksgatan.xodr
Validation check of omega file¶
!omega-prime validate --help
Usage: omega-prime validate [OPTIONS] {input} Check an omega-prime file for specification conformance. ╭─ Arguments ──────────────────────────────────────────────────────────────────╮ │ * input <file> Path to omega file to validate [required] │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Options ────────────────────────────────────────────────────────────────────╮ │ --help Show this message and exit. │ ╰──────────────────────────────────────────────────────────────────────────────╯
!omega-prime validate ./example.mcap
File example.mcap is valid.