Using single processing steps
Use this page when you want to run one processing step on its own instead of the whole pipeline: to look at an intermediate result, to change one parameter of one step, or to apply a step to data that was processed elsewhere.
run_pipeline runs all steps with one configuration. Each step package of trajlab.processing also has one entry
function. It takes a DataFrame and optional parameters, and needs no configuration file. Its default parameters are
those of the preset drone_hgv_paper (the processing chain of the ANT 2027 paper). For the lane geometry, the lane
assignment, the lane-change detection and the kinematics these defaults are the same as in the preset
roadside_camera.
Five steps by hand
The example runs five entry functions on the eastbound direction of the synthetic motorway that ships with trajlab
(trajlab.examples): the projection onto the reference line (step 01), the alignment (03), the kinematics (05), the
lane geometry (06), and the lane assignment together with the lane-change detection (07–09). The example is executed
when the documentation site is built, so on the site the output appears below the code. On GitHub only the code is
shown.
import trajlab
from trajlab.processing.alignment import align_lateral_positions
from trajlab.processing.kinematics import reconstruct_kinematics
from trajlab.processing.lanes import assign_lanes, estimate_lane_geometry
from trajlab.processing.reference_line import project_to_reference_line
from trajlab.road_layout import LaneLayout
raw = trajlab.examples.synthetic_motorway()
ref_east, _ = trajlab.estimate_ref_lines(raw)
east = raw[raw["orientation"] > 0]
layout = LaneLayout(n_main_lanes=3)
tracks = project_to_reference_line(east, ref_east) # 01: pos_lon along the road, pos_lat across it
tracks = align_lateral_positions(tracks, layout=layout).tracks # 03: each lane at a constant pos_lat
kinematics = reconstruct_kinematics(tracks) # 05: speed and acceleration (Montanino & Punzo)
geometry = estimate_lane_geometry(kinematics.tracks, layout=layout) # 06: lane centers, a first lane per sample
lanes = assign_lanes( # 07-09: lane changes and the corrected lanes (hidden Markov model)
geometry.tracks, layout=layout, lane_centers=geometry.centers, road_length_m=ref_east.length
)
out, events = lanes.tracks, lanes.events
print(f"{out['id'].nunique()} vehicles, {len(out)} samples")
print("samples per lane:", out["lane"].value_counts().sort_index().to_dict())
print(f"median speed: {out['speed'].median():.1f} km/h")
print("events:", events["event_type"].value_counts().to_dict())
62 vehicles, 10573 samples
samples per lane: {1: 3067, 2: 3330, 3: 4176}
median speed: 108.3 km/h
events: {'lane_change': 6, 'lateral_excursion': 3}
The example leaves out the perspective correction (02) and the stitching (04), although the synthetic motorway has
heavy vehicles and a camera hand-over. Its lanes and lane changes are therefore close to, but not equal to, those of
run_pipeline with the same preset. The pipeline overview lists the whole sequence.
The entry functions
Most entry functions return an object whose attributes hold the results: .tracks is always the processed track
table, and the other attributes are named in the table. "frame" means that the function returns the table itself.
The parameters are either keywords of the function or one parameter object (...Params), described below.
| Page | Entry function | Parameters | Result |
|---|---|---|---|
| 01 | reference_line.project_to_reference_line(tracks, ref_line) |
keywords | frame |
| 02 | perspective.correct_perspective(tracks) |
PerspectiveParams |
.tracks, .estimate (the estimated offset) |
| 03 | alignment.align_lateral_positions(tracks) |
AlignmentParams |
.tracks, .edge_profile (the estimated road edge per bin along the road) |
| 04 | stitching.stitch_fragments(tracks), stitching.impute_trajectories(tracks) |
keywords | .tracks, .links (which pieces were joined); frame |
| 05 | kinematics.reconstruct_kinematics(tracks) |
KinematicsParams |
.tracks, .mp_tracks (the Montanino & Punzo reconstruction per vehicle), .counters |
| 06 | lanes.estimate_lane_geometry(tracks) |
LaneGeometryParams |
.tracks, .centers (lane centers), .diagnostics |
| 07 | lane_changes.detect_lane_changes(tracks), events.add_event_neighbors(events, tracks) |
keywords | event table |
| 08, 09 | lanes.assign_lanes(tracks) |
LaneAssignmentParams |
.tracks, .events |
| 10 | surroundings.resample_tracks(tracks), surroundings.compute_surroundings(tracks) |
keywords | .tracks; frame |
The site layout (number of main lanes, auxiliary-lane zones and zones with a different lane count) is one
trajlab.road_layout.LaneLayout, passed to every step that needs it. A step checks its input columns, and if one is
missing it names the step that adds it.
Changing the parameters of one step
To set a parameter, create the step's parameter object with that value, for example
KinematicsParams(method="savgol"); all other parameters keep their defaults. dataclasses.replace(params, ...) does
the same starting from an existing object. Here the kinematics run with the Savitzky-Golay filter instead of the
Montanino & Punzo method, and the lanes are assigned with the heuristic instead of the hidden Markov model:
from dataclasses import replace
from trajlab.processing.kinematics import KinematicsParams
from trajlab.processing.lanes import LaneAssignmentParams
savgol = reconstruct_kinematics(tracks, params=KinematicsParams(method="savgol"))
heuristic = replace(LaneAssignmentParams(), method="heuristic")
labeled = estimate_lane_geometry(savgol.tracks, layout=layout).tracks
lanes_h = assign_lanes(labeled, params=heuristic, layout=layout, road_length_m=ref_east.length)
print("events:", lanes_h.events["event_type"].value_counts().to_dict())
events: {'lane_change': 6, 'lateral_excursion': 6}
With the default parameters, calling all entry functions in the order of the pages gives exactly the output of
run_pipeline(..., config=load_preset("drone_hgv_paper")), apart from the rounding of the floats to 2 decimals that
the pipeline applies at the end. The test suite checks this.