Skip to content

Pipeline overview

The pipeline is the sequence of the entry functions of the steps (defaults of the preset drone_hgv_paper; Using single processing steps):

from trajlab.processing.alignment import align_lateral_positions
from trajlab.processing.events import add_event_neighbors
from trajlab.processing.kinematics import reconstruct_kinematics
from trajlab.processing.lanes import assign_lanes, estimate_lane_geometry
from trajlab.processing.perspective import correct_perspective
from trajlab.processing.reference_line import project_to_reference_line
from trajlab.processing.stitching import stitch_fragments
from trajlab.processing.surroundings import compute_surroundings

tracks = project_to_reference_line(raw, ref_line)  # 01
tracks = correct_perspective(tracks).tracks  # 02
tracks = align_lateral_positions(tracks).tracks  # 03
tracks = stitch_fragments(tracks).tracks  # 04 (impute_trajectories: off in the preset)
tracks = reconstruct_kinematics(tracks).tracks  # 05
geometry = estimate_lane_geometry(tracks)  # 06
lanes = assign_lanes(geometry.tracks, lane_centers=geometry.centers, road_length_m=ref_line.length)  # 07-09
tracks = compute_surroundings(lanes.tracks)  # 10 (resample_tracks: off in the preset)
events = add_event_neighbors(lanes.events, tracks)  # 07, the event table

trajlab turns raw drone or camera trajectories (UTM positions per vehicle and frame) into road-relative, kinematically consistent trajectories with lane labels, lane-change events and the surrounding vehicles of every vehicle. The pipeline runs once per travel direction.

This page gives the conventions, the order of the steps, the configuration and the run outputs. Each step has its own document with the method, its background, the input/output interface and the configuration (see Documents).

Results on our own data refer to drone recordings at two German freeway sites (not public): Site 1 with campaigns 1a and 1b, Site 2 with campaign 2 (22 recordings, 44 directions).

Conventions

Topic Convention
Longitudinal position pos_lon (s, m) increases in the direction of travel. Step 1 guarantees this, whatever direction the reference line was digitised in.
Lateral position pos_lat (d, m) is positive to the left of the direction of travel.
Lane IDs 0 = auxiliary lane (on/off-ramp, acceleration or deceleration lane; only inside configured lanes.auxiliary_lane_zones). 1 = rightmost main lane of the widest cross-section, IDs increase to the left. -1 = unassigned.
Neighbors *_left = lane + 1, *_right = lane − 1. Vehicles in lane 1 see lane-0 vehicles as right neighbors.
Lane-change direction lc_direction = +1 ("left") = towards a higher lane ID (increasing pos_lat), -1 ("right") the opposite. A merge from lane 0 to lane 1 is a left lane change.
Rates Steps 1–5 run at the native frame rate; the output is on one common grid t0 + k · 0.1 s (10 Hz, the same t0 for all vehicles).
Units Speed in km/h, acceleration in m/s², positions and distances in m, times in s.
Inputs No public function mutates the DataFrame passed to it.

The column names and constants are defined in trajlab/conventions.py.

Processing chain

raw UTM trajectories (id, datum, geometry, class, length, ...)
   │
   ├─ reference line ............ estimate_ref_lines: principal axis + B-spline (RMS tolerance 0.75 m)      01
   ▼
 Step 1  projection ............. Frenet s, d; travel-direction normalization; end clamping                 01
 (opt.)  perspective ............ HGV lateral offset (relief displacement): empirical class shift          02
 Step 2  alignment .............. 5 % road-edge profile subtracted; auxiliary-lane and lane-count zones    03
 (opt.)  stitching, imputation .. fragment linking (Hungarian, gated cascade); re-gridding of gaps         04
 Step 3  kinematics ............. Montanino & Punzo (default) or Savitzky-Golay                            05
 Step 4  lane geometry .......... rolling restricted GMM (Chen & Krumm 2010) + Hungarian lane tracking     06
 Step 5  lane assignment ........ lane-change detector (SEWMA) + HMM (default) or heuristic            07–09
         output grid ............ common 10 Hz grid for all vehicles                                       10
 Step 6  surroundings ........... leaders/followers in all six directions at identical timestamps          10
 (opt.)  platoon consistency .... M&P Step 3 with spacing constraints, layer by layer                      05
         lane-change events ..... event table with neighbor attributes                                     07
   ▼
processed trajectories (+ event table, run metadata)

Execution order (trajlab.processing.pipeline.PIPELINE_STEPS): projection → perspective → alignment → stitching → imputation → kinematics → lanes → lane_correction → resampling → surroundings → platoon_consistency → lane_change_events

Each step declares the columns it requires and produces (PipelineStep.requires / produces / extra_outputs); run_pipeline checks them before a step runs. A step whose outputs are already present is skipped unless cache="refresh".

Running it

import trajlab

east, west = trajlab.estimate_ref_lines(raw)  # reference lines from the data
config = trajlab.PipelineConfig.from_dict(
    {
        "lanes": {"n_main_lanes": 3},
        "perspective": {"correction": "class_offset_empirical"},
    }
)
result = trajlab.run_pipeline_detailed(raw[raw["orientation"] > 0], east, config)
out, events = result.tracks, result.events
  • trajlab.run_pipeline(...) returns only the processed trajectories; trajlab.run_pipeline_detailed(...) returns a PipelineResult with the trajectories (tracks) and the lane-change event table (events, 07).
  • keep_intermediates=True (of run_pipeline_detailed) also keeps a dict step name → DataFrame after that step (intermediates).
  • out.attrs["trajlab"] (read with trajlab.run_metadata(out)) holds the run metadata: library version and git commit, dependency versions, the full configuration, input/output row counts, one record per step, the perspective estimate (perspective) and the Step 4 diagnostics (lane_geometry). With metadata_path=... it is also written as JSON.

Configuration

PipelineConfig has one section per step (projection, perspective, alignment, stitching, imputation, kinematics (+ kinematics.mp), lanes (+ lanes.hmm), lane_change, resampling, surroundings). Each section is a dataclass with documented defaults; the step documents list their parameters (generated from the code). PipelineConfig.from_dict / to_dict / from_json / to_json convert to and from nested dicts; unknown keys raise an error. Site-specific settings (number of lanes, auxiliary-lane zones, lane-count zones) belong to the lanes section; the package ships examples as site files (trajlab/config/sites/*.yaml, trajlab.config.load_site).

Context artifacts

Some steps hand results that are not columns to later steps in PipelineContext.artifacts (lane centers, the HMM geometry, the perspective estimate, the event table, the Montanino & Punzo counters). run_pipeline_detailed does not return the context; the event table and the run metadata carry what a user needs. The list of artifacts and where each one ends up is in output_format.md.

Documents

Document Content
01 Reference line and projection reference line from the data, Frenet projection, direction normalization
02 Perspective correction lateral offset of tall vehicles (HGVs)
03 Road-edge alignment baseline correction, auxiliary-lane and lane-count zones, edge freeze
04 Stitching and imputation fragment linking, evaluation with artificial gaps, re-gridding
05 Kinematics Montanino & Punzo multistep reconstruction, Savitzky-Golay, platoon consistency
06 Lane geometry restricted / free GMM, lane tracking, lane gain and drop
07 Lane-change detection SEWMA detector, lane changes vs. excursions, event table, near_road_end
08 Lane assignment: heuristic crossovers, segments, conflict resolution
09 Lane assignment: HMM hidden Markov model, EM, feasibility, add-on rules (default since 1.0)
10 Output grid and surroundings resampling, neighbors, headways, clearances
11 Evaluation lane metrics, in-lane overtakings, synthetic data, degradation, datasets

Documents 01–09 have a section "Design choices": what is done, why, the evidence, and the source.

References

See the step documents; the full list is in references. Methods and thresholds without a cited paper are choices made for this library; each step document explains them in its section "Design choices".