Skip to content

05 Kinematic reconstruction (Step 3) and platoon consistency

Entry function:

from trajlab.processing.kinematics import KinematicsParams, reconstruct_kinematics

result = reconstruct_kinematics(tracks, params=KinematicsParams(method="montanino_punzo"))
tracks = result.tracks  # speed [km/h], acceleration [m/s^2]

Purpose

Positions from image-based tracking contain noise; differentiating them directly amplifies it (noise in the speed ∝ f, in the acceleration ∝ f²; at 30 Hz acceleration spikes beyond ±50 m/s²). Step 3 reconstructs smooth, internally consistent longitudinal kinematics (pos_lon, speed, acceleration) and smooths pos_lat.

Interface

Pipeline step Requires columns Produces columns Further output columns
kinematics id, datum, pos_lon, pos_lat speed, acceleration mp_reconstructed
platoon_consistency id, datum, pos_lon, speed, acceleration, id_front — —

speed is in km/h, acceleration in m/s² along the direction of travel. mp_reconstructed marks samples changed by Montanino & Punzo Steps 1 or 3. The lateral position pos_lat is always smoothed with Savitzky-Golay.

Parameter Default Description
kinematics.enabled True Run the step.
kinematics.smooth_window_sec 4 Savitzky-Golay window in seconds.
kinematics.smooth_window_frames None Explicit window in frames; wins over smooth_window_sec when set.
kinematics.poly_order 2 Polynomial order. Quadratic, because a cubic leaves visible ripples in the acceleration.
kinematics.max_reversal_m 15 Backward motion in meters above which a track is discarded as a tracking error.
kinematics.frame_rate 30 Nominal recording frame rate in Hz, used by get_smooth_window_frames when no rate is given.
kinematics.method 'montanino_punzo' "montanino_punzo" or "savgol".
kinematics.lateral_smooth_window_sec None Savitzky-Golay window in seconds for pos_lat with the montanino_punzo method; None uses the same window as the longitudinal smoothing (smooth_window_sec / smooth_window_frames), i.e. exactly the lateral smoothing of the savgol method.
kinematics.mp *(section)* Parameters of the montanino_punzo method; a dict is converted. Defaults to MontaninoPunzoConfig().
kinematics.reconstruction None Alternative longitudinal reconstruction used in place of the Montanino & Punzo steps of the montanino_punzo method (same 10 Hz grid, same write-back), e.g. {"method": "tv", "params": {"lam": 0.03, "order": 3}} or with "params_by_speed": [[20.0, {...}], [null, {...}]] (upper speed bound in m/s per entry, chosen by the vehicle's median speed); see processing.kinematics.filters.track_kinematics. Chosen per dataset by the synthetic recovery test. Mandatory keys: admissible_v_bands (speed bands that passed the counter-check) and edge_s (track-edge exclusion); the output gets the columns recon_admissible and recon_edge. Defaults to None (Montanino & Punzo).
kinematics.spatial_correction None Removes a spatially fixed position error before the longitudinal reconstruction: {"profiles": "<parquet>"}, a table from processing.kinematics.spatial_correction.estimate_spatial_bias for this recording and direction (estimated from the raw positions and the lanes of a first run). Only lanes that passed the time-half cross-validation are corrected; the column spatial_corrected flags the corrected rows. Defaults to None (off).
Parameter Default Description
kinematics.mp.rate_hz 10 Rate in Hz at which the method runs. The paper's thresholds refer to 10 Hz (dt = 0.1 s); native samples are averaged in 0.1 s bins on the common grid and the result is interpolated back.
kinematics.mp.outlier_accel_max_mps2 5 Step 1 (Sec. 2.1) acceleration threshold in m/s^2.
kinematics.mp.outlier_decel_min_mps2 -8 Step 1 deceleration threshold in m/s^2.
kinematics.mp.outlier_reference_points 10 Step 1 spline reference points on each side (1 s at 10 Hz).
kinematics.mp.lowpass_cutoff_hz 0.5 Steps 2/4 (Sec. 2.2/2.4) Butterworth cut-off in Hz. Defaults to 0.5 (paper: 1.0; at 1.0 Hz many 1 s windows of drone data keep more than one jerk sign inversion).
kinematics.mp.lowpass_order 1 Butterworth order.
kinematics.mp.filter_zero_phase True Zero-phase filtering (sosfiltfilt; the magnitude response is applied twice) instead of causal filtering (not specified in the paper).
kinematics.mp.filter_padlen_sec None Zero-phase filtering only: length of the odd extension at both track ends in seconds (sosfiltfilt(padtype="odd")). None keeps the scipy default of 3 * (2 * n_sections + 1) samples (0.9 s at 10 Hz for order 1), whose start-up transient reaches about 1 m/s2 within the first and last 3-4 s; a longer padding does not reduce it.
kinematics.mp.edge_method 'pad' Zero-phase only: "pad" (odd extension, the behavior up to v1.0) or "gust" (Gustafsson's initial conditions; halves the track-end error without cutting data).
kinematics.mp.window_a_min_mps2 -3 Eq. 2 a_min in m/s^2 (also the Step 3 trigger).
kinematics.mp.window_a_max_mps2 2 Eq. 2 a_max in m/s^2.
kinematics.mp.window_lookahead 5 Eq. 2 c, look-ahead samples.
kinematics.mp.rec_a_min_mps2 -5 Eq. 3i a_Rec,min in m/s^2.
kinematics.mp.rec_a_max_mps2 3 Eq. 3i a_Rec,max in m/s^2.
kinematics.mp.phi_mps2 1 Eq. 3g/h relaxation of the acceleration continuity in m/s^2.
kinematics.mp.max_jerk_inversions 1 Eq. 3j D, maximum jerk sign inversions per window.
kinematics.mp.jerk_window_sec 1 Eq. 3j Z in seconds (the paper's "s = 1 s").
kinematics.mp.max_window_sec 10 Longest reconstruction window in seconds before an outlier is left as it is (not in the paper).
kinematics.mp.h_min_m 1 Eq. 2e/3l minimum spacing to the leader in meters (platoon-consistency post-pass only).
kinematics.mp.platoon_consistency False Run the platoon-consistency post-pass (Eq. 2e/3l) after Step 6.
kinematics.mp.max_platoon_iterations 10 Iterations within circular leader-follower groups in the post-pass.
kinematics.mp.trim_track_ends_sec 2 If set, cut each track end whose output acceleration lies outside the Step 1 outlier bounds within this many seconds of the end, up to the deepest such row (Step 1 never moves the end positions; not in the paper). Defaults to 2.0 since 1.0 (None: off).
kinematics.mp.trim_track_ends_fixed_sec None If set, cut this many seconds from both ends of every track, unconditionally (removes the start-up transient of the filter; tracks shorter than twice the cut are dropped). Defaults to None (off).

Method: common pre-processing

  • Monotonicity: pos_lon increases with travel (Step 1); a track that moves backwards by more than max_reversal_m (15 m; tracking identity swap) is discarded.

Method: Montanino & Punzo (default, method = "montanino_punzo")

Multistep reconstruction of Montanino & Punzo (2013, TRR 2390, 99–111) in the extended form of Montanino & Punzo (2015, TR-B 80, 82–106, Sec. 2); processing/kinematics/montanino_punzo.py.

  • Rate: the paper's thresholds refer to 10 Hz. Native positions are averaged in 0.1 s bins centerd on whole multiples of 0.1 s (identical to the output grid; one-sided end bins dropped) and reconstructed at 10 Hz. Eq. 1: $v_t = (x_t - x_{t-1})/\Delta t$, $a_t = (v_t - v_{t-1})/\Delta t$.
  • Step 1 (outliers): $a > +5$ or $a < -8$ m/s² → positions replaced by a natural cubic spline through 10 points on each side (distance kept).
  • Step 2 (noise): Butterworth low-pass of order 1 on the speed, zero-phase (sosfiltfilt), cut-off 0.5 Hz (deviation: the paper uses 1 Hz; see the design choices). The sum of the speeds (distance) is restored by adding $(\Sigma v_{in} - \Sigma v_{out})/n$ (addition; without it 7.5 cm distance error).
  • Step 3 (constrained local reconstruction): windows where $a \notin [-3, 2]$ m/s²; the window end from the compatibility cone of Eq. 2 (look-ahead $c = 5$); speeds replaced by a 5th-degree polynomial that minimizes $\max |a|$ (epigraph form, SLSQP with exact linear Jacobians) subject to Eq. 3: $v \ge 0$, continuity at both ends (φ = 1 m/s²), $a \in [-5, 3]$, at most one jerk sign inversion per 1 s, internal consistency (distance preserved), optionally the platoon constraint. Infeasible windows are enlarged up to 10 s (addition).
  • Step 4: Step 2's filter again.
  • Output: pos_lon, speed, acceleration directly from the 10 Hz result when the output grid has the same rate (speed at $t - \Delta t/2$, acceleration at $t - \Delta t$ interpolated to the grid points); native-rate values for Steps 4–5 by PCHIP.

Method: Savitzky-Golay (method = "savgol")

A generic smoothing choice (not from Montanino & Punzo): local polynomial of order 2 over 4 s (odd number of frames from each vehicle's sampling interval: 121 at 30 Hz, 41 at 10 Hz), with linear constant-velocity padding at both ends to avoid boundary distortion. Positions from the 0th, speed from the 1st, acceleration from the 2nd analytical derivative. Faster than M&P; used in the diagnostic passes of the perspective correction and in lane comparisons where only pos_lat matters.

Method: platoon consistency (optional post-pass, mp.platoon_consistency)

Leaders are known only after Step 6, so this is a post-pass on the 10 Hz output grid (processing/kinematics/platoon.py, experimental): the leader–follower tree is built from id_front; vehicles that lead each other at different times form a strongly connected group in one layer; layer by layer, vehicles with a clearance below mp.h_min_m get Step 3 again with the spacing constraints (Eq. 2e/3l). Step 6 is then recomputed. As in the paper, windows are triggered by unphysical accelerations only, so a spacing violation without one is reported but not fixed (see the design choices).

Design choices

The choices below are made for this library unless a paper is named; the evidence for each is given under "Source" (a test, a script of applications/ant2027/ or a measurement named in the text).

  • Butterworth cut-off 0.5 Hz instead of the paper's 1 Hz. At 1 Hz the first-order filter (−6 dB/octave) leaves much high-frequency content in the second difference: the share of 1 s windows with more than one jerk sign inversion is 48 % on one direction of Site 1 and 30 % on DLR-HT; at 0.5 Hz it is 20 % and 4 %, while 0.75 Hz reduces it by at most half. Internal consistency (distance preserved) does not depend on the cut-off. Source: Montanino & Punzo (2015) for the filter; the Step 3 unit tests in tests/processing/kinematics/test_kinematics_mp.py pin 1.0 Hz explicitly (at 0.5 Hz their synthetic trajectory opens no window).
  • Savitzky-Golay is offered as a separate method and not attributed to Montanino & Punzo. Neither paper uses Savitzky-Golay filtering. Montanino & Punzo (2013) is cited for the multistep method, (2015) for the extended Step 3, Punzo et al. (2011) for the consistency criteria.
  • Output taken directly from the 10 Hz reconstruction. The reconstruction grid and the output grid are both anchored at whole multiples of 0.1 s from the Unix epoch, so they coincide and no interpolation round trip is needed; only native-rate values (Steps 4–5) are interpolated (PCHIP).
  • One-sided end bins are dropped. At 25 Hz a 0.1 s bin holds 2 or 3 samples; an end bin with samples at 0 and 40 ms has its mean 20 ms off the grid point, which gives a first speed of 21.6 instead of 27 m/s, an acceleration of 54 m/s² and infeasible Step 3 windows at every track end. End bins whose mean time is more than 10 % of the step off the grid point are dropped; interior bins are unchanged.
  • Interpolation instead of binning at ≤ 10 Hz native rate. With at most one native sample per grid bin, the positions are interpolated linearly onto the grid points. With a drifting native clock (9.99 Hz) the end-bin rule had dropped up to 60 s at the track ends, which were then extrapolated with the end speed and acceleration. Higher native rates keep the binning.
  • Infeasible Step 3 windows are rejected before the nonlinear solver (run time only, results bit-identical). Every Eq. 3 window is a linear programme. Before SLSQP is called, (1) the end accelerations are checked against the bounds (with |f' − a_end| ≤ φ no feasible slope exists otherwise), (2) HiGHS checks feasibility (constraints relaxed by the SLSQP acceptance tolerance), and (3) the window search stops at max_window_s. Without these checks each infeasible window cost 300 SLSQP iterations; now the cost is linear in samples and window solves. Source: tests/processing/kinematics/test_mp_runtime.py.
  • Track ends outside the Step 1 bounds are cut (trim_track_ends_sec, default 2 s). Step 1 never moves the first or last position of a track (the spline needs reference points on both sides), so outliers there remain and spoil every evaluation of the track ends. The option cuts, per end, up to the deepest row within the given depth whose acceleration lies outside [outlier_decel_min_mps2, outlier_accel_max_mps2], at the end of the kinematics step (before lanes and neighbors). Interior rows are never touched. Source: tests/processing/kinematics/test_trim_track_ends.py.
  • Spacing violations do not open reconstruction windows. As in Montanino & Punzo (2015), windows are triggered by unphysical accelerations only; the platoon post-pass reports such violations but does not fix them. Letting spacing violations open a window would be a deviation from the paper.

Validation and limitations

  • tests/processing/kinematics/test_kinematics_mp.py, tests/processing/kinematics/test_platoon.py, tests/processing/kinematics/test_mp_runtime.py, tests/processing/kinematics/test_trim_track_ends.py; trajlab.analysis.quality.kinematic (jerk statistics, smoothing residual) compares methods.
  • Sites 1 and 2 (10 Hz input): acceleration p1/p99 about ±2 m/s² for both methods (M&P slightly wider tails), jerk p99 1.3–3.9 m/s³; raw differences are unusable (jerk p99 15–51 m/s³). Share of 1 s windows with more than one jerk inversion: 48 → 20 % (Site 1, one direction) when the cut-off goes from 1.0 to 0.5 Hz.
  • Step 3 of M&P is first-order: many jerk inversions remain; interior bins with dropped frames are not time-corrected.