10 Output grid and surroundings (Step 6)
Entry functions:
from trajlab.processing.surroundings import compute_surroundings, resample_tracks
tracks = resample_tracks(tracks, rate_hz=10.0).tracks # off in the preset drone_hgv_paper
tracks = compute_surroundings(tracks)
Purpose
Steps 1–5 run at the native frame rate of each vehicle. Before the surroundings are computed, all trajectories are resampled to one common time grid, so that vehicles can be compared at identical timestamps. Step 6 then finds the leader and follower of every vehicle in its own and in the adjacent lanes, with headways, clearances and relative speeds.
Interface
| Pipeline step | Requires columns | Produces columns | Further output columns |
|---|---|---|---|
resampling |
id, datum |
— | — |
surroundings |
id, datum, lane, pos_lon, speed |
id_front |
id_front, headway_front, clearance_front, rel_speed_front, id_rear, headway_rear, clearance_rear, rel_speed_rear, id_front_left, headway_front_left, clearance_front_left, rel_speed_front_left, id_rear_left, headway_rear_left, clearance_rear_left, rel_speed_rear_left, id_front_right, headway_front_right, clearance_front_right, rel_speed_front_right, id_rear_right, headway_rear_right, clearance_rear_right, rel_speed_rear_right |
| Parameter | Default | Description |
|---|---|---|
resampling.rate_hz |
10 |
Rate of the grid t0 + k / rate_hz in Hz; None keeps the native rate. |
resampling.interpolate_columns |
[] |
Columns always interpolated linearly in time (must be numeric). |
resampling.nearest_columns |
[] |
Columns always taken from the nearest native sample. |
resampling.drop_columns |
[] |
Columns left out of the output. |
| Parameter | Default | Description |
|---|---|---|
surroundings.enabled |
True |
Run the step. |
surroundings.default_vehicle_length_m |
4.5 |
Vehicle length in meters used when the input has no length column. |
surroundings.tie_tolerance_m |
0.001 |
Longitudinal distance in meters up to which an adjacent-lane vehicle counts as exactly side by side; such a vehicle is a rear neighbor (negative clearance), never a front one. |
Method: output grid (resample_to_output_grid)
- One grid $t_0 + k/$
rate_hz(default 10 Hz) for all vehicles, $t_0$ = the global minimum time floored to a whole grid step counted from the Unix epoch. Each vehicle keeps only the grid points inside its own observed time span; nothing is extrapolated. - Continuous columns (
pos_lon,pos_lat,speed,acceleration,utm_x,utm_y,pos_lat_raw,y_correction,pos_lon_ref) are interpolated linearly in time; with Montanino & Punzo at the same rate,pos_lon,speedandaccelerationcome directly from the 10 Hz reconstruction (05). - The other known columns (
lane,lane_fixed, flags,class,length,orientation, …) take the value of the nearest native sample. - Unknown columns follow their dtype (floats interpolated, everything else nearest);
interpolate_columns,nearest_columnsanddrop_columnsoverride this. The rule used for each unknown column is logged. - The geometry is rebuilt from
utm_x/utm_y.rate_hz = Nonekeeps the native rate.
The grid, the neighbor search, the tie rule and the default length are chosen for this library.
Method: surroundings
front left front front right
[FL] [F] [FR]
─────────────────────── [subject] ───────────────────────
[RL] [R] [RR]
rear left rear rear right
- A
merge_asofonpos_lonmatches the subject with candidates at the identical timestamp in the target lane (same lane,+1left,-1right);(id, time)must be unique. "Front" is increasingpos_lon(forward search), "rear" the opposite. - Unassigned points (lane −1) get no neighbors and are nobody's neighbor.
- Tie rule: an adjacent-lane vehicle with $|\Delta s| \le$
tie_tolerance_m(1 mm) is a rear neighbor, never a front one (its rear clearance is negative). Same-lane ties are conflicts and excluded. A missinglengthis filled withdefault_vehicle_length_m(4.5 m). - Headway: center-to-center distance along the direction of travel. Clearance: headway $- (L_{subject} + L_{target})/2$. Relative speed: $v_{target} - v_{subject}$.
- The lane-change event table (07) takes its neighbor attributes from these columns.
Validation and limitations
tests/processing/surroundings/test_surroundings_ties.py,tests/processing/surroundings/test_resampling.py,tests/processing/test_conventions.py(neighbor signs and lanes).- Pairwise measures need common timestamps: evaluation inputs thinned to 10 Hz must use every n-th frame of the recording, not every n-th sample of each track; per-track thinning gives the vehicles differently phased timestamps, and pairwise measures then find no common time steps.