Datasets
Generated by docs/scripts/make_api_pages.py.
Dataset-specific preparation before the pipeline, for datasets that need more than a reader.
trajlab.datasets.i24: I-24 MOTION (corridor windows, lateral correction per camera, filters and masks, the ramp frame, interchange excerpts and the runner of the main carriageway).
The readers themselves are in trajlab.io.readers; the processing steps of trajlab.processing are the same for
every dataset.
I-24 MOTION (Gloudemans et al. 2023): from the provider's day files to lanes on the main carriageway.
I-24 MOTION records a 4-mile freeway near Nashville with about 300 pole cameras; the provider delivers trajectory
fragments in road coordinates, one per camera view. Before the pipeline, these fragments need a preparation that
no other dataset needs: the lateral error of each camera's mapping to the road, fragments of the other carriageway,
the ramps, and the settling at the fragment ends. This package does that; docs/datasets/i24_motion.md explains
why, what it supports and what it does not.
The workflow, each step one call::
from trajlab.datasets import i24
window = i24.read_i24motion_day("11-22-2022.zip", "2022-11-22 09:10", "2022-11-22 09:20", out_dir="wb_0910",
direction=-1)
raw = i24.read_i24motion_window(window, direction=-1)
result = i24.run_i24motion(raw, "i24_motion") # table by traffic state, preparation, lanes, settling labels
Modules: trajlab.io.readers.i24_motion_day (the day-file reader and the corridor's mile markers, re-exported
here), lateral (correction M4 and the shipped tables), preparation (filters and masks), ramps (the
ramp-aligned frame), interchanges (excerpts around one interchange) and runner (run_i24motion). The
stitching of the fragments is experimental: trajlab.experimental.i24_stitching.
I24Excerpt
dataclass
I24Excerpt(positions: DataFrame, zone: Series, provenance: dict[str, Any] = dict(), table: DataFrame = pd.DataFrame(), ramp: RampLine | None = None)
Prepared positions around one interchange zone, with where they come from.
Attributes:
| Name | Type | Description |
|---|---|---|
positions |
DataFrame
|
Prepared positions ( |
zone |
Series
|
The zone's row of |
provenance |
dict[str, Any]
|
Window, traffic state, table, margin and counts of the excerpt. |
table |
DataFrame
|
Lateral table of the window's traffic state. |
ramp |
RampLine | None
|
Ramp line of the zone, after |
I24Preparation
dataclass
I24Preparation(positions: DataFrame, counts: dict[str, Any], duplicates: DataFrame)
Result of run_i24motion_preparation.
Attributes:
| Name | Type | Description |
|---|---|---|
positions |
DataFrame
|
The prepared positions of one direction, corrected, without geometry, with |
counts |
dict[str, Any]
|
Fragments and positions removed or found by each step. |
duplicates |
DataFrame
|
The candidate pairs of |
RampLine
RampLine(line: DataFrame, gore_in: float, gore_out: float)
The ramp line of one zone: d_ramp(s), its arc length, the auxiliary-lane centre and the gores.
Attributes:
| Name | Type | Description |
|---|---|---|
line |
One row per bin: |
|
gore_in |
|
|
gore_out |
|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
DataFrame
|
The bins of the traced line, as the attribute. |
required |
gore_in
|
float
|
The entry gore [m], as the attribute. |
required |
gore_out
|
float
|
The exit gore [m], as the attribute. |
required |
arc_at
arc_at(lon: float) -> float
Arc length [m] of the line at pos_lon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lon
|
float
|
|
required |
Returns:
| Type | Description |
|---|---|
float
|
Arc length [m] from the start of the line. |
I24MotionOptions
dataclass
I24MotionOptions(stitching: Literal['none', 'experimental'] = 'none', table: Literal['reference', 'estimate'] = 'reference', estimate_minutes: float | None = None, chunk_minutes: float | None = 2.0, median_cut: bool = True, remove_duplicates: bool = False)
Options of run_i24motion; the key dataset of the preset sets them (preset i24_motion).
Attributes:
| Name | Type | Description |
|---|---|---|
stitching |
Literal['none', 'experimental']
|
|
table |
Literal['reference', 'estimate']
|
|
estimate_minutes |
float | None
|
With |
chunk_minutes |
float | None
|
Run the pipeline in time chunks of this length [min] (bounded memory); None: in one run. |
median_cut |
bool
|
Remove the positions beyond the median-side edge ( |
remove_duplicates |
bool
|
Remove the shorter fragment of each duplicate pair. |
__post_init__
__post_init__() -> None
Check the choices.
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
I24MotionResult
dataclass
I24MotionResult(tracks: DataFrame, events: DataFrame, table: DataFrame, counts: dict[str, object] = dict(), links: DataFrame = pd.DataFrame(), low_speed_links: DataFrame = pd.DataFrame())
Result of run_i24motion.
Attributes:
| Name | Type | Description |
|---|---|---|
tracks |
DataFrame
|
Pipeline output ( |
events |
DataFrame
|
Pipeline events. |
table |
DataFrame
|
The lateral table used. |
counts |
dict[str, object]
|
Counts of the preparation, with the window's traffic state and median speed [km/h]. |
links |
DataFrame
|
Link records of the stitching (empty without it). |
low_speed_links |
DataFrame
|
|
compute_i24motion_detector_count
compute_i24motion_detector_count(positions: DataFrame, lon: float, lanes: tuple[int, ...], *, period: tuple[Timestamp, Timestamp], track: str = C.ID, max_gap_s: float = 5.0) -> int
Count the tracks that cross a virtual detector at lon in one of lanes within period.
A track crosses where two of its consecutive positions, at most max_gap_s apart, lie on both sides of
lon (a stitched vehicle crosses over a bridged gap, a fragment only where it has positions); its lane is that
of the position before the crossing. Each track counts at most once, so that the overlap of two fragments of one
vehicle at a link and the jitter of a position around lon count once.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
DataFrame
|
Positions with the column |
required |
lon
|
float
|
Position of the detector [m]. |
required |
lanes
|
tuple[int, ...]
|
Lane labels the detector covers. |
required |
period
|
tuple[Timestamp, Timestamp]
|
Start and end (excluded) of the counting period. |
required |
track
|
str
|
Column of the track id ( |
ID
|
max_gap_s
|
float
|
Longest time between two consecutive positions of a crossing [s]. |
5.0
|
Returns:
| Type | Description |
|---|---|
int
|
The number of crossing tracks. |
compute_i24motion_excerpt
compute_i24motion_excerpt(raw: DataFrame, zone: str, *, margin_m: float = MARGIN_M) -> I24Excerpt
Cut the fragments around one zone out of a window and prepare them as the whole window.
The traffic state, and with it the reference table, is that of the whole window
(estimate_i24motion_window_state); the preparation works per fragment and per position, so the excerpt's
positions are those of the prepared whole window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
DataFrame
|
Window of one direction ( |
required |
zone
|
str
|
Name of a zone of |
required |
margin_m
|
float
|
Margin around the zone [m]. |
MARGIN_M
|
Returns:
| Type | Description |
|---|---|
I24Excerpt
|
The excerpt. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
compute_i24motion_ramp_frame
compute_i24motion_ramp_frame(excerpt: I24Excerpt) -> I24Excerpt
Trace the zone's ramp line and map the ramp part of an excerpt into the ramp-aligned frame.
The line is traced over the zone plus RAMP_SEEN_M (estimate_i24motion_ramp_line); the positions are
projected with project_i24motion_ramp and lane_pt is recomputed on the mapped positions: the ramp part
becomes lane 0 with the auxiliary lane, and a merging vehicle reaches lane 1 without a lateral jump. On the
2022-11-22 development windows the lateral spread of the ramp vehicles fell from p95 2-8 m to 0.8-2.9 m.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
excerpt
|
I24Excerpt
|
|
required |
Returns:
| Type | Description |
|---|---|
I24Excerpt
|
The excerpt with the mapped positions (the frame's columns added), its |
I24Excerpt
|
provenance. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the zone's ramp is not in view in this window (raised by |
read_i24motion_interchange_zones
read_i24motion_interchange_zones(direction: int) -> pd.DataFrame
Return the interchange zones of one direction, with mile markers, pos_lon range and length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
direction
|
int
|
+1 (EB) or -1 (WB). |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
|
DataFrame
|
|
compute_i24motion_corrected_lateral
compute_i24motion_corrected_lateral(raw: DataFrame, offsets: DataFrame) -> pd.DataFrame
Subtract the lateral error from pos_lat.
Within a camera section the error of each lane is interpolated linearly along the road between the section centres and held beyond the outer ones, so the correction steps only at the hand-overs, where the error steps as well; across the road it is interpolated linearly between the smooth lane centres and held outside lanes 1 and 4. Within 20 m of a break, a position takes the camera on the side of the break where the median position of its fragment lies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
DataFrame
|
Output of |
required |
offsets
|
DataFrame
|
Result of |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
A copy of |
DataFrame
|
and |
estimate_i24motion_lane_centres
estimate_i24motion_lane_centres(raw: DataFrame, *, bin_m: float = CENTRE_BIN_M) -> pd.DataFrame
Estimate the four main-lane centres per section of the road from the lateral positions.
Per section, the lane peaks are the maxima of the histogram of pos_lat; a candidate is a set of four
neighbouring peaks with even distances (0.8-1.25 of their mean). Sections with exactly one candidate fix the
lanes; where an auxiliary lane, a ramp beside the road or a second camera view gives several candidates, the one
closest to the running median of the unambiguous sections is taken. Each centre is the median of the positions
within 0.6 m of its peak.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
DataFrame
|
Positions of one direction ( |
required |
bin_m
|
float
|
Length of a section [m]. |
CENTRE_BIN_M
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per section with enough positions: |
DataFrame
|
rightmost, lowest |
estimate_i24motion_lateral_offsets
estimate_i24motion_lateral_offsets(raw: DataFrame, *, model: LateralModel = 'surface', bin_m: float = OFFSET_BIN_M, reference_m: float = REFERENCE_WINDOW_M) -> pd.DataFrame
Estimate the lateral error of every camera section, with breaks only at the camera hand-overs.
- Positions used: only fragments without a lane change (lateral range below half a lane width), so that real lane changes are not taken for error. Merging and diverging ramp vehicles change lanes and drop out with them; vehicles that stay on an auxiliary lane form a peak of their own, which the choice of the four main lanes leaves aside. The main lanes inside the ramp masks are therefore corrected like the rest of the road.
- Lane centres per
bin_m(estimate_i24motion_lane_centres); the smooth centre of each lane is its running median overreference_m; the errore_k(s)is the difference. - Camera hand-overs are the peaks of the density of fragment starts and ends along the road (at least twice
the median count per section,
HANDOVER_MIN_DISTANCE_Mapart): the provider's fragments end where a camera hands over. Further breaks are where all four lane centres step together by more thanJUMP_BREAK_Mwithin 20 m (a step of the mapping without a cluster of fragment ends, e.g. eastbound MM 61.25 on 2022-11-22); such a break replaces a hand-over from the fragment ends within 20 m, because it is located by the lane centres themselves. -
Per camera section, the error is modelled (least squares with Huber weights, all lanes together):
-
"linear":a + b s; "quadratic":a + b s + q s^2;"affine":a + b s + c d + e s d(d: smooth lane centre; the error may differ across the lanes, i.e. the lane width per camera);"surface":e_k(s)itself per lane, smoothed alongsby a running median of three sections; sections without the four lanes take the linear model of their camera.
The correction keeps the order of the lanes: it moves their common position and, for "affine" and
"surface", their width per camera.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
DataFrame
|
Output of |
required |
model
|
LateralModel
|
Model of the error per camera section (above). |
'surface'
|
bin_m
|
float
|
Length of the sections of the lane centres [m]. |
OFFSET_BIN_M
|
reference_m
|
float
|
Length of the running median of the smooth lane centres [m]. |
REFERENCE_WINDOW_M
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per section and lane: |
DataFrame
|
camera section along |
DataFrame
|
|
DataFrame
|
|
DataFrame
|
breaks from common steps of the lane centres). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
estimate_i24motion_window_state
estimate_i24motion_window_state(raw: DataFrame) -> tuple[WindowState, float]
Estimate the traffic state of a window, which selects the reference table.
The state is the duration-weighted median of the mean speeds of the fragments with positions in the window
(|pos_lon end - pos_lon start| / duration, fragments of at least 1 s): below CONGESTED_BELOW_KMH
congested, else free.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
DataFrame
|
Window of one direction with |
required |
Returns:
| Type | Description |
|---|---|
tuple[WindowState, float]
|
The state and the median speed [km/h]. |
read_i24motion_reference_table
read_i24motion_reference_table(direction: int, state: WindowState) -> pd.DataFrame
Read the shipped lateral table of one direction and traffic state (INCEPTION v1.0, November 2022).
The tables are estimate_i24motion_lateral_offsets (surface model) of the 2022-11-22 development windows
(REFERENCE_TABLES). Applied to 2022-11-23 they kept the lane-centre deviation at p95 0.16-0.27 m and moved
the cells by a median of 0.03-0.05 m (docs/datasets/i24_motion.md). They hold for the camera layout of
INCEPTION v1.0 in November 2022; for other days of that release, estimate a table on the window and compare.
Eastbound has one table for both states (its development window was free flow).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
direction
|
int
|
+1 (EB) or -1 (WB). |
required |
state
|
WindowState
|
Traffic state of the window ( |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
The table, as |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
read_i24motion_table
read_i24motion_table(path: Path | str) -> pd.DataFrame
Read a lateral table written by write_i24motion_table (exact to the last bit).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
CSV file of the table; its |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
The table of |
write_i24motion_table
write_i24motion_table(table: DataFrame, path: Path | str) -> None
Write a lateral table as CSV, with its attrs (model, camera breaks) in <path>.json.
The floats are written with 17 significant digits, so that read_i24motion_table returns them to the last bit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
DataFrame
|
Result of |
required |
path
|
Path | str
|
CSV file to write; the |
required |
compute_i24motion_edge_labels
compute_i24motion_edge_labels(tracks: DataFrame, *, edge_s: float = EDGE_SETTLING_S, min_duration_s: float = EDGE_SETTLING_MIN_DURATION_S, lane_columns: tuple[str, ...] = (C.LANE_FIXED, C.LANE)) -> pd.DataFrame
Give the first and last edge_s of every fragment the lane of its nearest interior sample.
The provider's lateral positions settle at the ends of a fragment (camera entry and exit), so a label change
there is mostly an artefact. In fragments of at least min_duration_s, every sample within edge_s of the
start takes the label of the first sample after it, every sample within edge_s of the end the label of the
last sample before it; the samples are kept and flagged edge_settling. Shorter fragments are unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tracks
|
DataFrame
|
Pipeline output ( |
required |
edge_s
|
float
|
Length of the settling at each end [s]. |
EDGE_SETTLING_S
|
min_duration_s
|
float
|
Shortest fragment that is changed [s]. |
EDGE_SETTLING_MIN_DURATION_S
|
lane_columns
|
tuple[str, ...]
|
Lane columns to change (those present). |
(LANE_FIXED, LANE)
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
A copy of |
compute_i24motion_point_lanes
compute_i24motion_point_lanes(positions: DataFrame, table: DataFrame) -> np.ndarray
Return the lane of every position: the nearest smooth lane centre of the lateral table.
Lanes from the right as in trajlab.conventions: 1 = rightmost main lane, 0 = right of lane 1 (auxiliary lane
or ramp roadway), 5 = left of lane 4. Use the corrected positions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
DataFrame
|
Positions of one direction ( |
required |
table
|
DataFrame
|
Lateral table ( |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Lane per position (int8 array, 0-5). |
compute_i24motion_traffic_state
compute_i24motion_traffic_state(speed: ndarray | float) -> np.ndarray
Return the traffic state of speeds: congested below 10 m/s, transition 10-18 m/s, free above (STATE_BANDS).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
speed
|
ndarray | float
|
Speed(s) [m/s]; NaN counts as free. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
|
detect_i24motion_duplicates
detect_i24motion_duplicates(df: DataFrame, handovers_lon: ndarray) -> pd.DataFrame
Find pairs of fragments that are one vehicle seen twice (a duplicate).
A pair is a duplicate if the two overlap in time over at least DUPLICATE_MIN_OVERLAP of the shorter fragment
and, at the times of the shorter one inside the overlap (the longer interpolated), the median |d difference| is
at most DUPLICATE_MAX_DD_M, the median |x difference| at most DUPLICATE_MAX_DX_LENGTHS of the mean length,
and the length and width differ by at most DUPLICATE_MAX_DLENGTH_M / DUPLICATE_MAX_DWIDTH_M. Candidates:
pairs that share a 1-s cell and lie within 10 m along and 2 m across the road there.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Corrected positions of one direction (sorted or not). |
required |
handovers_lon
|
ndarray
|
Camera breaks [m] ( |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per candidate pair: |
DataFrame
|
( |
DataFrame
|
and |
detect_i24motion_id_switch_suspects
detect_i24motion_id_switch_suspects(df: DataFrame, table: DataFrame) -> pd.DataFrame
Count the fragments with a suspected ID switch (counted only, nothing changed).
- dimension jump: |length| or |width| changes by more than
SWITCH_DLENGTH_M/SWITCH_DWIDTH_MwithinSWITCH_DIM_WINDOW_Sinside a fragment; - lateral sweep: the lateral position moves by more than
SWITCH_LANESlane widths withinSWITCH_SWEEP_WINDOW_S.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Corrected positions of one direction. |
required |
table
|
DataFrame
|
Fixed lateral table (lane width along the road). |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per fragment with a suspicion: |
DataFrame
|
range within the window, in lane widths), |
detect_i24motion_median_side
detect_i24motion_median_side(positions: DataFrame, table: DataFrame) -> np.ndarray
Mark the corrected positions beyond the median-side edge of the main carriageway.
A position lies beyond the edge if it is more than MEDIAN_SIDE_MARGIN_LANES lane widths left of the outer edge
of lane 4 (its centre plus half a lane width). These positions are off the main carriageway; removed, they are no
anchor of the stitching (a fragment then ends at its last position inside the band).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
DataFrame
|
Corrected positions of one direction. |
required |
table
|
DataFrame
|
Lateral table used for the correction. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Boolean array aligned with |
detect_i24motion_off_band
detect_i24motion_off_band(raw: DataFrame, table: DataFrame) -> np.ndarray
Mark the single positions far outside the band of the main lanes, outside the ramp masks.
The band runs from half a lane width right of the lane-1 centre to half a lane width left of the lane-4 centre
of table; a position more than OFF_BAND_LANES lane widths beyond it is off the band. Inside a ramp mask
(an auxiliary-lane zone of the corridor site file widened by RAMP_MASK_MARGIN_M) nothing is marked: the ramp
roadway lies there.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
DataFrame
|
Positions of one direction before the lateral correction ( |
required |
table
|
DataFrame
|
Lateral table of the window. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Boolean array aligned with |
detect_i24motion_off_coverage
detect_i24motion_off_coverage(raw: DataFrame, *, section_m: float = 100.0, min_share: float = COVERAGE_MIN_SHARE) -> pd.DataFrame
Find the sections at the ends of the covered road where the cameras' coverage thins out.
From each end of the observed road inwards, sections of section_m count as off coverage while their number
of positions is below min_share of the median section; the first section above it ends the search. Sections
inside the corridor are never off coverage, however few positions they have.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
DataFrame
|
Positions of one direction ( |
required |
section_m
|
float
|
Length of a section [m]. |
100.0
|
min_share
|
float
|
Share of the median number of positions per section below which an end section is off coverage. |
COVERAGE_MIN_SHARE
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per section: |
detect_i24motion_off_mainline
detect_i24motion_off_mainline(raw: DataFrame, *, bin_m: float = CENTRE_BIN_M, margin_lanes: float = OFF_MAINLINE_MARGIN_LANES, ramp_margin_m: float = RAMP_MASK_MARGIN_M) -> pd.Series
Mark the positions off the main carriageway: ramps, auxiliary lanes, outside its band, implausible fragments.
The band of the main carriageway follows the lane centres (estimate_i24motion_lane_centres on raw,
smoothed over five sections): lane 1 centre minus 0.5 + margin_lanes lane widths to lane 4 centre plus the
same. Inside a ramp mask (an auxiliary-lane zone of the corridor site file widened by ramp_margin_m), the
band ends half a lane width outside the lane-1 centre: the positions beyond lie on the auxiliary lane or the
ramp. Use the corrected positions (compute_i24motion_corrected_lateral).
Fragments whose lateral range exceeds half a lane width and LATERAL_PER_LONGITUDINAL_MAX of their
longitudinal travel are marked as a whole: on 2022-11-22 these are near-stationary detections that slide across
several lanes (11 m within 6 m of travel), which no vehicle does; a lane change moves 3.7 m over 50 m or more.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
DataFrame
|
Output of |
required |
bin_m
|
float
|
Length of the sections of the lane centres [m]. |
CENTRE_BIN_M
|
margin_lanes
|
float
|
Margin of the band outside the outer half lanes, in lane widths. |
OFF_MAINLINE_MARGIN_LANES
|
ramp_margin_m
|
float
|
Widening of the ramp masks at both ends [m]. |
RAMP_MASK_MARGIN_M
|
Returns:
| Type | Description |
|---|---|
Series
|
Boolean Series aligned with |
detect_i24motion_other_carriageway
detect_i24motion_other_carriageway(raw: DataFrame) -> pd.Series
Mark the fragments that lie on the other carriageway.
A fragment is on the other carriageway if the median of its lateral position lies beyond the median line of the
road (y of the provider with the sign of the other direction). Whole fragments are marked, never single
positions, so a vehicle of this direction that drifts towards the median keeps all its positions. On
2022-11-22 the distribution of these medians has almost no mass between 0 and 6 ft: the marked fragments are
detections of the other direction or mis-mapped, not vehicles in the HOV lane.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
DataFrame
|
Output of |
required |
Returns:
| Type | Description |
|---|---|
Series
|
Boolean Series aligned with |
run_i24motion_preparation
run_i24motion_preparation(raw: DataFrame, table: DataFrame, *, median_cut: bool = True, remove_duplicates: bool = False) -> I24Preparation
Prepare one window of one direction for the stitching and the run on the main carriageway.
- Whole fragments on the other carriageway (
detect_i24motion_other_carriageway), then single positions far outside the band of the main lanes (detect_i24motion_off_band) are removed. - The lateral error is subtracted with
table(compute_i24motion_corrected_lateral). - With
median_cut, the positions beyond the median-side edge are removed (detect_i24motion_median_side). - Duplicates are found (
detect_i24motion_duplicates); withremove_duplicates, the shorter fragment of each pair is removed. On the 2022-11-22 calibration windows the removal changed precision and recall of the stitching only within noise (0-30 pairs per 10-min window), so they are kept by default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
DataFrame
|
Window of one direction ( |
required |
table
|
DataFrame
|
Lateral table ( |
required |
median_cut
|
bool
|
Remove the positions beyond the median-side edge (step 3). |
True
|
remove_duplicates
|
bool
|
Remove the shorter fragment of each duplicate pair (step 4). |
False
|
Returns:
| Type | Description |
|---|---|
I24Preparation
|
The prepared positions, the counts of every step and the duplicate pairs. |
estimate_i24motion_ramp_line
estimate_i24motion_ramp_line(positions: DataFrame, table: DataFrame, lon_range: tuple[float, float], *, enters: bool, leaves: bool) -> RampLine
Trace the ramp line of one zone through the densest band of the positions right of lane 1.
Per RAMP_BIN_M bin, the bands are the peaks of the histogram of pos_lat right of lane 1 (more than half a
lane width right of its centre), each fragment weighing one. The trace starts in the bin with the most fragments
there, at its highest band,
and goes up- and downstream to the band nearest to the previous one, at most RAMP_MAX_STEP_M per bin away;
it ends after RAMP_MAX_MISSING_BINS bins without a band. A second, parallel band (another camera's mapping of
the same ramp) is not followed. The line is the running median over RAMP_SMOOTH_BINS of the traced bands.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
DataFrame
|
Corrected positions of one direction ( |
required |
table
|
DataFrame
|
Fixed lateral table of the window ( |
required |
lon_range
|
tuple[float, float]
|
|
required |
enters
|
bool
|
The zone has an on-ramp (an entry gore is looked for). |
required |
leaves
|
bool
|
The zone has an off-ramp (an exit gore is looked for). |
required |
Returns:
| Type | Description |
|---|---|
RampLine
|
The ramp line. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no bin in |
project_i24motion_ramp
project_i24motion_ramp(positions: DataFrame, ramp: RampLine, table: DataFrame) -> pd.DataFrame
Project the ramp-side positions onto the ramp line and give the ramp part of the line one continuous frame.
Every position right of lane 1 within the traced extent of the line gets ramp_arc (arc length of its foot
point [m]) and ramp_offset (signed distance to the line [m], positive towards the carriageway). Positions on
the ramp part (before gore_in or after gore_out) are mapped: pos_lon becomes the gore's pos_lon
minus (plus) the arc length between foot point and gore, pos_lat the auxiliary-lane centre plus the offset,
blended linearly into the provider's pos_lat over BLEND_M before the gore. The values in the main
carriageway's frame are kept in pos_lon_mainline_frame and pos_lat_mainline_frame; ramp_frame marks the
mapped positions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
DataFrame
|
Corrected positions ( |
required |
ramp
|
RampLine
|
Line of |
required |
table
|
DataFrame
|
Fixed lateral table of the window. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
|
run_i24motion
run_i24motion(window: DataFrame, config: PipelineConfig | str = 'i24_motion', *, options: I24MotionOptions | None = None) -> I24MotionResult
Run one window of one direction of I-24 MOTION from the provider's fragments to lanes on the main carriageway.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window
|
DataFrame
|
Window of one direction ( |
required |
config
|
PipelineConfig | str
|
Pipeline configuration, or the name of a preset; with a name, its key |
'i24_motion'
|
options
|
I24MotionOptions | None
|
Options; None: those of the preset ( |
None
|
Returns:
| Type | Description |
|---|---|
I24MotionResult
|
The tracks and events of the window, the table, the counts and, with stitching, the links. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the experimental stitching is asked for while the pipeline's own stitching step is on. |
compute_i24motion_mm
compute_i24motion_mm(pos_lon: float | ndarray | Series, direction: int, *, x_origin_ft: float | None = None) -> np.ndarray
Convert pos_lon of read_i24motion_corridor back to mile markers (compute_i24motion_pos_lon inverted).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pos_lon
|
float | ndarray | Series
|
Longitudinal position(s) [m]. |
required |
direction
|
int
|
+1 (EB) or -1 (WB). |
required |
x_origin_ft
|
float | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Mile marker(s) [mi], an array of the shape of |
compute_i24motion_pos_lon
compute_i24motion_pos_lon(mm: float | ndarray, direction: int, *, x_origin_ft: float | None = None) -> np.ndarray
Convert I-24 MOTION mile markers to pos_lon of read_i24motion_corridor.
pos_lon = direction * (mm * 5280 - x_origin_ft) * 0.3048, with MM 60 = 316 800 ft (data documentation v1.x).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mm
|
float | ndarray
|
Mile marker(s) [mi]. |
required |
direction
|
int
|
+1 (EB) or -1 (WB). |
required |
x_origin_ft
|
float | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
|
read_i24motion_corridor
read_i24motion_corridor(source: Path | str | DataFrame, direction: int | None = None, x_origin_ft: float | None = None) -> gpd.GeoDataFrame
Read one direction of I-24 MOTION (Gloudemans et al. 2023) with a fixed origin and the corridor's zones.
source is a folder written by read_i24motion_day, a parquet file or a DataFrame in the sample format of
read_i24motion, which does the reading. Differences to it:
pos_lonstarts at the fixed originI24_ORIGIN_MMof the direction (miles x 5280 ft), the upstream end of the corridor, not at the data, so that the zones of the site files apply to every window;- the number of main lanes and the auxiliary-lane zones of the corridor site file (
I24_SITES), converted topos_lonwith the same origin, are stored inattrs;trajlab.site_config_from_attrsturns them into the site settings of a run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Path | str | DataFrame
|
Folder of |
required |
direction
|
int | None
|
+1 (EB) or -1 (WB); None: the only direction of the source. |
None
|
x_origin_ft
|
float | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
The |
GeoDataFrame
|
|
GeoDataFrame
|
(its |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
read_i24motion_day
read_i24motion_day(day_file: Path | str, start: str | Timestamp, end: str | Timestamp, *, out_dir: Path | str, direction: int | None = None, margin_s: float = 30.0, bucket_s: float = 60.0, order_lag_s: float | None = I24_ORDER_LAG_S) -> Path
Read one time window of an I-24 MOTION day file into time-bucketed parquet files (Gloudemans et al. 2023).
The day file of INCEPTION v1.0 (e.g. 11-22-2022.zip, about 6 GB) holds a zip with one JSON array of about
18 GB, one document per trajectory fragment. It is streamed without unpacking, with the standard library only:
the documents are split at the provider's layout (a closing brace at the start of a line), a document is parsed
only if it overlaps the window, and reading stops once every later document must lie after the window.
Kept: the documents of direction whose time span overlaps [start, end), with their points in
[start - margin_s, end + margin_s). They are written to out_dir as one parquet file per bucket_s
(named after the local start time of the bucket, e.g. 2022-11-22T07-30-00.parquet; a fragment spanning
buckets is split over them), in the sample format of read_i24motion with the column in_window (point in
[start, end)). _window.json in out_dir records the window and marks it complete; a second call with
the same arguments returns at once.
The file is not ordered by time. Reading stops when, in each direction read, the largest first_timestamp
seen exceeds end + order_lag_s; on 2022-11-22 no document lay more than 45 min behind that maximum
(I24_ORDER_LAG_S). order_lag_s=None reads the whole file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
day_file
|
Path | str
|
The provider's day archive (zip with an inner zip holding the |
required |
start
|
str | Timestamp
|
Start of the window, local time (America/Chicago), e.g. |
required |
end
|
str | Timestamp
|
End of the window (excluded), local time. |
required |
out_dir
|
Path | str
|
Folder for the bucket files; created if missing. It must be empty or hold the same window. |
required |
direction
|
int | None
|
+1 (EB) or -1 (WB); None keeps both. |
None
|
margin_s
|
float
|
Time [s] kept before |
30.0
|
bucket_s
|
float
|
Length of a time bucket [s]. |
60.0
|
order_lag_s
|
float | None
|
Largest delay [s] of a document behind the latest |
I24_ORDER_LAG_S
|
Returns:
| Type | Description |
|---|---|
Path
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
FileNotFoundError
|
If |
ImportError
|
If |
read_i24motion_window
read_i24motion_window(folder: Path | str, direction: int) -> pd.DataFrame
Read a window of read_i24motion_day for the stitching: one direction, WINDOW_COLUMNS, no geometry.
The rows and values of these columns are those of read_i24motion_corridor (same conversions, same order):
the bucket files are read with a filter on the direction and only the source columns that the conversion
needs; the class names come from a lookup per class code instead of per row.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
folder
|
Path | str
|
Folder of |
required |
direction
|
int
|
+1 (EB) or -1 (WB). |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
The positions of |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the folder holds no parquet file. |
ImportError
|
If |
read_i24motion_zones
read_i24motion_zones(direction: int, *, x_origin_ft: float | None = None) -> pd.DataFrame
Return the auxiliary-lane zones of the I-24 MOTION corridor in one direction, in mile markers and pos_lon.
The zones of the site file (I24_SITES; zone_mm, visible_from_mm, lane_end_mm in miles, in the
direction of travel) are converted with compute_i24motion_pos_lon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
direction
|
int
|
+1 (EB) or -1 (WB). |
required |
x_origin_ft
|
float | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per zone, in the order of the site file: |
DataFrame
|
|
DataFrame
|
lon_end |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
I-24 MOTION interchanges: excerpts of the corridor around one auxiliary-lane zone, the ramp frame, detectors.
An interchange zone is an auxiliary-lane zone of the corridor site files i24_eb / i24_wb (on-ramp with its
acceleration lane, off-ramp with its deceleration lane, weaving lane). Main functions:
read_i24motion_interchange_zones: the zones of one direction with theirpos_lonrange and whether vehicles enter or leave there;compute_i24motion_excerpt: the fragments that touch a zone plus a margin, prepared as the whole window (run_i24motion_preparationwith the table of the window's traffic state), clipped to the zone plus the margin;compute_i24motion_ramp_frame: the ramp part of an excerpt mapped into the ramp-aligned frame (trajlab.datasets.i24.ramps);compute_i24motion_detector_count: tracks crossing a virtual detector.
Lanes are those of compute_i24motion_point_lanes on the corrected positions: 1 = rightmost main lane, 0 = right of
lane 1 (auxiliary lane or ramp roadway), 5 = left of lane 4. The ramps of both directions lie on the right.
On the 2022-11-22 development windows an excerpt stitched on its own gave the same successor as the stitched whole window for 99.2-100 % of the fragments that end in the zone in 11 of 12 cases (zone x window), and 94.7 % in the twelfth: excerpts are a valid basis for the study of one interchange. Links whose tail or head lies within one gap (about 150 m at free-flow speed) of the excerpt ends can differ, because a fragment that leaves the excerpt ends there.
I24Excerpt
dataclass
I24Excerpt(positions: DataFrame, zone: Series, provenance: dict[str, Any] = dict(), table: DataFrame = pd.DataFrame(), ramp: RampLine | None = None)
Prepared positions around one interchange zone, with where they come from.
Attributes:
| Name | Type | Description |
|---|---|---|
positions |
DataFrame
|
Prepared positions ( |
zone |
Series
|
The zone's row of |
provenance |
dict[str, Any]
|
Window, traffic state, table, margin and counts of the excerpt. |
table |
DataFrame
|
Lateral table of the window's traffic state. |
ramp |
RampLine | None
|
Ramp line of the zone, after |
read_i24motion_interchange_zones
read_i24motion_interchange_zones(direction: int) -> pd.DataFrame
Return the interchange zones of one direction, with mile markers, pos_lon range and length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
direction
|
int
|
+1 (EB) or -1 (WB). |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
|
DataFrame
|
|
compute_i24motion_excerpt
compute_i24motion_excerpt(raw: DataFrame, zone: str, *, margin_m: float = MARGIN_M) -> I24Excerpt
Cut the fragments around one zone out of a window and prepare them as the whole window.
The traffic state, and with it the reference table, is that of the whole window
(estimate_i24motion_window_state); the preparation works per fragment and per position, so the excerpt's
positions are those of the prepared whole window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
DataFrame
|
Window of one direction ( |
required |
zone
|
str
|
Name of a zone of |
required |
margin_m
|
float
|
Margin around the zone [m]. |
MARGIN_M
|
Returns:
| Type | Description |
|---|---|
I24Excerpt
|
The excerpt. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
compute_i24motion_ramp_frame
compute_i24motion_ramp_frame(excerpt: I24Excerpt) -> I24Excerpt
Trace the zone's ramp line and map the ramp part of an excerpt into the ramp-aligned frame.
The line is traced over the zone plus RAMP_SEEN_M (estimate_i24motion_ramp_line); the positions are
projected with project_i24motion_ramp and lane_pt is recomputed on the mapped positions: the ramp part
becomes lane 0 with the auxiliary lane, and a merging vehicle reaches lane 1 without a lateral jump. On the
2022-11-22 development windows the lateral spread of the ramp vehicles fell from p95 2-8 m to 0.8-2.9 m.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
excerpt
|
I24Excerpt
|
|
required |
Returns:
| Type | Description |
|---|---|
I24Excerpt
|
The excerpt with the mapped positions (the frame's columns added), its |
I24Excerpt
|
provenance. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the zone's ramp is not in view in this window (raised by |
compute_i24motion_detector_count
compute_i24motion_detector_count(positions: DataFrame, lon: float, lanes: tuple[int, ...], *, period: tuple[Timestamp, Timestamp], track: str = C.ID, max_gap_s: float = 5.0) -> int
Count the tracks that cross a virtual detector at lon in one of lanes within period.
A track crosses where two of its consecutive positions, at most max_gap_s apart, lie on both sides of
lon (a stitched vehicle crosses over a bridged gap, a fragment only where it has positions); its lane is that
of the position before the crossing. Each track counts at most once, so that the overlap of two fragments of one
vehicle at a link and the jitter of a position around lon count once.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
DataFrame
|
Positions with the column |
required |
lon
|
float
|
Position of the detector [m]. |
required |
lanes
|
tuple[int, ...]
|
Lane labels the detector covers. |
required |
period
|
tuple[Timestamp, Timestamp]
|
Start and end (excluded) of the counting period. |
required |
track
|
str
|
Column of the track id ( |
ID
|
max_gap_s
|
float
|
Longest time between two consecutive positions of a crossing [s]. |
5.0
|
Returns:
| Type | Description |
|---|---|
int
|
The number of crossing tracks. |
I-24 MOTION lateral correction (M4): the error of each camera's mapping to the road, per camera and lane.
Main functions: estimate_i24motion_lateral_offsets (the correction surface per camera section and lane, with the
camera breaks), compute_i24motion_corrected_lateral (subtract it), read_i24motion_reference_table (the shipped
tables of INCEPTION v1.0, 2022-11-22, per traffic state) and estimate_i24motion_window_state (which of them fits
a window).
Why (lateral profiles of INCEPTION v1.0, 2022-11-22, 10-min windows; docs/datasets/i24_motion.md): the lane
centres form a saw-tooth along the road. Within the section of one camera they drift by a few decimetres and step
back where the next camera takes over (up to 3 m at one hand-over). All lanes move together, so it is an error of the
camera's mapping to the road, not of the road's reference line. The alignment of the pipeline
(docs/pipeline/03_alignment.md) smooths along the road and keeps most of it.
estimate_i24motion_lane_centres
estimate_i24motion_lane_centres(raw: DataFrame, *, bin_m: float = CENTRE_BIN_M) -> pd.DataFrame
Estimate the four main-lane centres per section of the road from the lateral positions.
Per section, the lane peaks are the maxima of the histogram of pos_lat; a candidate is a set of four
neighbouring peaks with even distances (0.8-1.25 of their mean). Sections with exactly one candidate fix the
lanes; where an auxiliary lane, a ramp beside the road or a second camera view gives several candidates, the one
closest to the running median of the unambiguous sections is taken. Each centre is the median of the positions
within 0.6 m of its peak.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
DataFrame
|
Positions of one direction ( |
required |
bin_m
|
float
|
Length of a section [m]. |
CENTRE_BIN_M
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per section with enough positions: |
DataFrame
|
rightmost, lowest |
estimate_i24motion_lateral_offsets
estimate_i24motion_lateral_offsets(raw: DataFrame, *, model: LateralModel = 'surface', bin_m: float = OFFSET_BIN_M, reference_m: float = REFERENCE_WINDOW_M) -> pd.DataFrame
Estimate the lateral error of every camera section, with breaks only at the camera hand-overs.
- Positions used: only fragments without a lane change (lateral range below half a lane width), so that real lane changes are not taken for error. Merging and diverging ramp vehicles change lanes and drop out with them; vehicles that stay on an auxiliary lane form a peak of their own, which the choice of the four main lanes leaves aside. The main lanes inside the ramp masks are therefore corrected like the rest of the road.
- Lane centres per
bin_m(estimate_i24motion_lane_centres); the smooth centre of each lane is its running median overreference_m; the errore_k(s)is the difference. - Camera hand-overs are the peaks of the density of fragment starts and ends along the road (at least twice
the median count per section,
HANDOVER_MIN_DISTANCE_Mapart): the provider's fragments end where a camera hands over. Further breaks are where all four lane centres step together by more thanJUMP_BREAK_Mwithin 20 m (a step of the mapping without a cluster of fragment ends, e.g. eastbound MM 61.25 on 2022-11-22); such a break replaces a hand-over from the fragment ends within 20 m, because it is located by the lane centres themselves. -
Per camera section, the error is modelled (least squares with Huber weights, all lanes together):
-
"linear":a + b s; "quadratic":a + b s + q s^2;"affine":a + b s + c d + e s d(d: smooth lane centre; the error may differ across the lanes, i.e. the lane width per camera);"surface":e_k(s)itself per lane, smoothed alongsby a running median of three sections; sections without the four lanes take the linear model of their camera.
The correction keeps the order of the lanes: it moves their common position and, for "affine" and
"surface", their width per camera.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
DataFrame
|
Output of |
required |
model
|
LateralModel
|
Model of the error per camera section (above). |
'surface'
|
bin_m
|
float
|
Length of the sections of the lane centres [m]. |
OFFSET_BIN_M
|
reference_m
|
float
|
Length of the running median of the smooth lane centres [m]. |
REFERENCE_WINDOW_M
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per section and lane: |
DataFrame
|
camera section along |
DataFrame
|
|
DataFrame
|
|
DataFrame
|
breaks from common steps of the lane centres). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
compute_i24motion_corrected_lateral
compute_i24motion_corrected_lateral(raw: DataFrame, offsets: DataFrame) -> pd.DataFrame
Subtract the lateral error from pos_lat.
Within a camera section the error of each lane is interpolated linearly along the road between the section centres and held beyond the outer ones, so the correction steps only at the hand-overs, where the error steps as well; across the road it is interpolated linearly between the smooth lane centres and held outside lanes 1 and 4. Within 20 m of a break, a position takes the camera on the side of the break where the median position of its fragment lies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
DataFrame
|
Output of |
required |
offsets
|
DataFrame
|
Result of |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
A copy of |
DataFrame
|
and |
write_i24motion_table
write_i24motion_table(table: DataFrame, path: Path | str) -> None
Write a lateral table as CSV, with its attrs (model, camera breaks) in <path>.json.
The floats are written with 17 significant digits, so that read_i24motion_table returns them to the last bit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
DataFrame
|
Result of |
required |
path
|
Path | str
|
CSV file to write; the |
required |
read_i24motion_table
read_i24motion_table(path: Path | str) -> pd.DataFrame
Read a lateral table written by write_i24motion_table (exact to the last bit).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
CSV file of the table; its |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
The table of |
read_i24motion_reference_table
read_i24motion_reference_table(direction: int, state: WindowState) -> pd.DataFrame
Read the shipped lateral table of one direction and traffic state (INCEPTION v1.0, November 2022).
The tables are estimate_i24motion_lateral_offsets (surface model) of the 2022-11-22 development windows
(REFERENCE_TABLES). Applied to 2022-11-23 they kept the lane-centre deviation at p95 0.16-0.27 m and moved
the cells by a median of 0.03-0.05 m (docs/datasets/i24_motion.md). They hold for the camera layout of
INCEPTION v1.0 in November 2022; for other days of that release, estimate a table on the window and compare.
Eastbound has one table for both states (its development window was free flow).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
direction
|
int
|
+1 (EB) or -1 (WB). |
required |
state
|
WindowState
|
Traffic state of the window ( |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
The table, as |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
estimate_i24motion_window_state
estimate_i24motion_window_state(raw: DataFrame) -> tuple[WindowState, float]
Estimate the traffic state of a window, which selects the reference table.
The state is the duration-weighted median of the mean speeds of the fragments with positions in the window
(|pos_lon end - pos_lon start| / duration, fragments of at least 1 s): below CONGESTED_BELOW_KMH
congested, else free.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
DataFrame
|
Window of one direction with |
required |
Returns:
| Type | Description |
|---|---|
tuple[WindowState, float]
|
The state and the median speed [km/h]. |
I-24 MOTION preparation before a run: filters, masks, duplicates, settling at the fragment ends.
Main function: run_i24motion_preparation, the chain of one window in the order the steps depend on each other:
detect_i24motion_other_carriageway: whole fragments on the other carriageway, thendetect_i24motion_off_band: single positions far outside the band of the main lanes;- lateral correction with a fixed table (
trajlab.datasets.i24.lateral); detect_i24motion_median_side: corrected positions beyond the median-side edge of the main carriageway;detect_i24motion_duplicates: one vehicle seen twice (counted; removed only on request).
After the run: detect_i24motion_off_mainline (positions off the main carriageway: ramps, auxiliary lanes),
compute_i24motion_edge_labels (lane labels of the settling at fragment ends) and
detect_i24motion_off_coverage (road sections at the ends of the cameras' coverage).
Why (lateral profiles of INCEPTION v1.0, 2022-11-22, 10-min windows; docs/datasets/i24_motion.md):
- Whole fragments of one direction lie on the other carriageway (their lateral position beyond the median line; 2 % of the eastbound positions at 07:30). The lane geometry puts a lane on them and merges two real lanes.
- The provider's fragments start and end at lateral positions of 38-40 m, at the median line, 0.5-1.0 lane widths beyond the band of the main lanes; a point filter of 1.5 lane widths keeps them, the median-side cut removes them.
- The provider's lateral positions settle at the ends of a fragment (camera entry and exit): they move about twice as fast in the first and last 1-2 s as in its middle.
I24Preparation
dataclass
I24Preparation(positions: DataFrame, counts: dict[str, Any], duplicates: DataFrame)
Result of run_i24motion_preparation.
Attributes:
| Name | Type | Description |
|---|---|---|
positions |
DataFrame
|
The prepared positions of one direction, corrected, without geometry, with |
counts |
dict[str, Any]
|
Fragments and positions removed or found by each step. |
duplicates |
DataFrame
|
The candidate pairs of |
compute_i24motion_traffic_state
compute_i24motion_traffic_state(speed: ndarray | float) -> np.ndarray
Return the traffic state of speeds: congested below 10 m/s, transition 10-18 m/s, free above (STATE_BANDS).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
speed
|
ndarray | float
|
Speed(s) [m/s]; NaN counts as free. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
|
compute_i24motion_point_lanes
compute_i24motion_point_lanes(positions: DataFrame, table: DataFrame) -> np.ndarray
Return the lane of every position: the nearest smooth lane centre of the lateral table.
Lanes from the right as in trajlab.conventions: 1 = rightmost main lane, 0 = right of lane 1 (auxiliary lane
or ramp roadway), 5 = left of lane 4. Use the corrected positions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
DataFrame
|
Positions of one direction ( |
required |
table
|
DataFrame
|
Lateral table ( |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Lane per position (int8 array, 0-5). |
detect_i24motion_off_band
detect_i24motion_off_band(raw: DataFrame, table: DataFrame) -> np.ndarray
Mark the single positions far outside the band of the main lanes, outside the ramp masks.
The band runs from half a lane width right of the lane-1 centre to half a lane width left of the lane-4 centre
of table; a position more than OFF_BAND_LANES lane widths beyond it is off the band. Inside a ramp mask
(an auxiliary-lane zone of the corridor site file widened by RAMP_MASK_MARGIN_M) nothing is marked: the ramp
roadway lies there.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
DataFrame
|
Positions of one direction before the lateral correction ( |
required |
table
|
DataFrame
|
Lateral table of the window. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Boolean array aligned with |
detect_i24motion_median_side
detect_i24motion_median_side(positions: DataFrame, table: DataFrame) -> np.ndarray
Mark the corrected positions beyond the median-side edge of the main carriageway.
A position lies beyond the edge if it is more than MEDIAN_SIDE_MARGIN_LANES lane widths left of the outer edge
of lane 4 (its centre plus half a lane width). These positions are off the main carriageway; removed, they are no
anchor of the stitching (a fragment then ends at its last position inside the band).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
DataFrame
|
Corrected positions of one direction. |
required |
table
|
DataFrame
|
Lateral table used for the correction. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Boolean array aligned with |
run_i24motion_preparation
run_i24motion_preparation(raw: DataFrame, table: DataFrame, *, median_cut: bool = True, remove_duplicates: bool = False) -> I24Preparation
Prepare one window of one direction for the stitching and the run on the main carriageway.
- Whole fragments on the other carriageway (
detect_i24motion_other_carriageway), then single positions far outside the band of the main lanes (detect_i24motion_off_band) are removed. - The lateral error is subtracted with
table(compute_i24motion_corrected_lateral). - With
median_cut, the positions beyond the median-side edge are removed (detect_i24motion_median_side). - Duplicates are found (
detect_i24motion_duplicates); withremove_duplicates, the shorter fragment of each pair is removed. On the 2022-11-22 calibration windows the removal changed precision and recall of the stitching only within noise (0-30 pairs per 10-min window), so they are kept by default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
DataFrame
|
Window of one direction ( |
required |
table
|
DataFrame
|
Lateral table ( |
required |
median_cut
|
bool
|
Remove the positions beyond the median-side edge (step 3). |
True
|
remove_duplicates
|
bool
|
Remove the shorter fragment of each duplicate pair (step 4). |
False
|
Returns:
| Type | Description |
|---|---|
I24Preparation
|
The prepared positions, the counts of every step and the duplicate pairs. |
detect_i24motion_duplicates
detect_i24motion_duplicates(df: DataFrame, handovers_lon: ndarray) -> pd.DataFrame
Find pairs of fragments that are one vehicle seen twice (a duplicate).
A pair is a duplicate if the two overlap in time over at least DUPLICATE_MIN_OVERLAP of the shorter fragment
and, at the times of the shorter one inside the overlap (the longer interpolated), the median |d difference| is
at most DUPLICATE_MAX_DD_M, the median |x difference| at most DUPLICATE_MAX_DX_LENGTHS of the mean length,
and the length and width differ by at most DUPLICATE_MAX_DLENGTH_M / DUPLICATE_MAX_DWIDTH_M. Candidates:
pairs that share a 1-s cell and lie within 10 m along and 2 m across the road there.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Corrected positions of one direction (sorted or not). |
required |
handovers_lon
|
ndarray
|
Camera breaks [m] ( |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per candidate pair: |
DataFrame
|
( |
DataFrame
|
and |
detect_i24motion_id_switch_suspects
detect_i24motion_id_switch_suspects(df: DataFrame, table: DataFrame) -> pd.DataFrame
Count the fragments with a suspected ID switch (counted only, nothing changed).
- dimension jump: |length| or |width| changes by more than
SWITCH_DLENGTH_M/SWITCH_DWIDTH_MwithinSWITCH_DIM_WINDOW_Sinside a fragment; - lateral sweep: the lateral position moves by more than
SWITCH_LANESlane widths withinSWITCH_SWEEP_WINDOW_S.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Corrected positions of one direction. |
required |
table
|
DataFrame
|
Fixed lateral table (lane width along the road). |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per fragment with a suspicion: |
DataFrame
|
range within the window, in lane widths), |
detect_i24motion_other_carriageway
detect_i24motion_other_carriageway(raw: DataFrame) -> pd.Series
Mark the fragments that lie on the other carriageway.
A fragment is on the other carriageway if the median of its lateral position lies beyond the median line of the
road (y of the provider with the sign of the other direction). Whole fragments are marked, never single
positions, so a vehicle of this direction that drifts towards the median keeps all its positions. On
2022-11-22 the distribution of these medians has almost no mass between 0 and 6 ft: the marked fragments are
detections of the other direction or mis-mapped, not vehicles in the HOV lane.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
DataFrame
|
Output of |
required |
Returns:
| Type | Description |
|---|---|
Series
|
Boolean Series aligned with |
detect_i24motion_off_mainline
detect_i24motion_off_mainline(raw: DataFrame, *, bin_m: float = CENTRE_BIN_M, margin_lanes: float = OFF_MAINLINE_MARGIN_LANES, ramp_margin_m: float = RAMP_MASK_MARGIN_M) -> pd.Series
Mark the positions off the main carriageway: ramps, auxiliary lanes, outside its band, implausible fragments.
The band of the main carriageway follows the lane centres (estimate_i24motion_lane_centres on raw,
smoothed over five sections): lane 1 centre minus 0.5 + margin_lanes lane widths to lane 4 centre plus the
same. Inside a ramp mask (an auxiliary-lane zone of the corridor site file widened by ramp_margin_m), the
band ends half a lane width outside the lane-1 centre: the positions beyond lie on the auxiliary lane or the
ramp. Use the corrected positions (compute_i24motion_corrected_lateral).
Fragments whose lateral range exceeds half a lane width and LATERAL_PER_LONGITUDINAL_MAX of their
longitudinal travel are marked as a whole: on 2022-11-22 these are near-stationary detections that slide across
several lanes (11 m within 6 m of travel), which no vehicle does; a lane change moves 3.7 m over 50 m or more.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
DataFrame
|
Output of |
required |
bin_m
|
float
|
Length of the sections of the lane centres [m]. |
CENTRE_BIN_M
|
margin_lanes
|
float
|
Margin of the band outside the outer half lanes, in lane widths. |
OFF_MAINLINE_MARGIN_LANES
|
ramp_margin_m
|
float
|
Widening of the ramp masks at both ends [m]. |
RAMP_MASK_MARGIN_M
|
Returns:
| Type | Description |
|---|---|
Series
|
Boolean Series aligned with |
compute_i24motion_edge_labels
compute_i24motion_edge_labels(tracks: DataFrame, *, edge_s: float = EDGE_SETTLING_S, min_duration_s: float = EDGE_SETTLING_MIN_DURATION_S, lane_columns: tuple[str, ...] = (C.LANE_FIXED, C.LANE)) -> pd.DataFrame
Give the first and last edge_s of every fragment the lane of its nearest interior sample.
The provider's lateral positions settle at the ends of a fragment (camera entry and exit), so a label change
there is mostly an artefact. In fragments of at least min_duration_s, every sample within edge_s of the
start takes the label of the first sample after it, every sample within edge_s of the end the label of the
last sample before it; the samples are kept and flagged edge_settling. Shorter fragments are unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tracks
|
DataFrame
|
Pipeline output ( |
required |
edge_s
|
float
|
Length of the settling at each end [s]. |
EDGE_SETTLING_S
|
min_duration_s
|
float
|
Shortest fragment that is changed [s]. |
EDGE_SETTLING_MIN_DURATION_S
|
lane_columns
|
tuple[str, ...]
|
Lane columns to change (those present). |
(LANE_FIXED, LANE)
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
A copy of |
detect_i24motion_off_coverage
detect_i24motion_off_coverage(raw: DataFrame, *, section_m: float = 100.0, min_share: float = COVERAGE_MIN_SHARE) -> pd.DataFrame
Find the sections at the ends of the covered road where the cameras' coverage thins out.
From each end of the observed road inwards, sections of section_m count as off coverage while their number
of positions is below min_share of the median section; the first section above it ends the search. Sections
inside the corridor are never off coverage, however few positions they have.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
DataFrame
|
Positions of one direction ( |
required |
section_m
|
float
|
Length of a section [m]. |
100.0
|
min_share
|
float
|
Share of the median number of positions per section below which an end section is off coverage. |
COVERAGE_MIN_SHARE
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per section: |
I-24 MOTION ramps in a ramp-aligned frame: the ramp line from the data, the gore, and the projected positions.
The provider maps every detection to roadway coordinates of the main carriageway (x along, y across its
reference line; Gloudemans et al. 2023). On a ramp that curves away from, or towards, the carriageway, pos_lat
therefore grows sideways with the ramp's own geometry and with the mapping of each camera: in (pos_lon, pos_lat)
the ramp is a curve, not a lane parallel to lane 1, and the lateral gates and lanes of the main carriageway do not
apply to it.
Main functions:
estimate_i24motion_ramp_line: the ramp lined_ramp(s)of one zone, traced through the densest band of the positions right of lane 1, and the gores where it meets the centre of the auxiliary lane;project_i24motion_ramp: every ramp-side position projected onto the line: arc length to the gore and signed offset; on the ramp part of the line (before the entry gore, after the exit gore) the positions are given one continuouspos_lon(the gore'spos_lonminus / plus the arc length along the line) and apos_latof the auxiliary-lane centre plus the offset, blended into the provider'spos_latover the last metres before the gore, so that a merging vehicle keeps one continuous longitudinal and lateral coordinate from the ramp into lane 1.
RampLine
RampLine(line: DataFrame, gore_in: float, gore_out: float)
The ramp line of one zone: d_ramp(s), its arc length, the auxiliary-lane centre and the gores.
Attributes:
| Name | Type | Description |
|---|---|---|
line |
One row per bin: |
|
gore_in |
|
|
gore_out |
|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
DataFrame
|
The bins of the traced line, as the attribute. |
required |
gore_in
|
float
|
The entry gore [m], as the attribute. |
required |
gore_out
|
float
|
The exit gore [m], as the attribute. |
required |
arc_at
arc_at(lon: float) -> float
Arc length [m] of the line at pos_lon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lon
|
float
|
|
required |
Returns:
| Type | Description |
|---|---|
float
|
Arc length [m] from the start of the line. |
estimate_i24motion_ramp_line
estimate_i24motion_ramp_line(positions: DataFrame, table: DataFrame, lon_range: tuple[float, float], *, enters: bool, leaves: bool) -> RampLine
Trace the ramp line of one zone through the densest band of the positions right of lane 1.
Per RAMP_BIN_M bin, the bands are the peaks of the histogram of pos_lat right of lane 1 (more than half a
lane width right of its centre), each fragment weighing one. The trace starts in the bin with the most fragments
there, at its highest band,
and goes up- and downstream to the band nearest to the previous one, at most RAMP_MAX_STEP_M per bin away;
it ends after RAMP_MAX_MISSING_BINS bins without a band. A second, parallel band (another camera's mapping of
the same ramp) is not followed. The line is the running median over RAMP_SMOOTH_BINS of the traced bands.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
DataFrame
|
Corrected positions of one direction ( |
required |
table
|
DataFrame
|
Fixed lateral table of the window ( |
required |
lon_range
|
tuple[float, float]
|
|
required |
enters
|
bool
|
The zone has an on-ramp (an entry gore is looked for). |
required |
leaves
|
bool
|
The zone has an off-ramp (an exit gore is looked for). |
required |
Returns:
| Type | Description |
|---|---|
RampLine
|
The ramp line. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no bin in |
project_i24motion_ramp
project_i24motion_ramp(positions: DataFrame, ramp: RampLine, table: DataFrame) -> pd.DataFrame
Project the ramp-side positions onto the ramp line and give the ramp part of the line one continuous frame.
Every position right of lane 1 within the traced extent of the line gets ramp_arc (arc length of its foot
point [m]) and ramp_offset (signed distance to the line [m], positive towards the carriageway). Positions on
the ramp part (before gore_in or after gore_out) are mapped: pos_lon becomes the gore's pos_lon
minus (plus) the arc length between foot point and gore, pos_lat the auxiliary-lane centre plus the offset,
blended linearly into the provider's pos_lat over BLEND_M before the gore. The values in the main
carriageway's frame are kept in pos_lon_mainline_frame and pos_lat_mainline_frame; ramp_frame marks the
mapped positions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
DataFrame
|
Corrected positions ( |
required |
ramp
|
RampLine
|
Line of |
required |
table
|
DataFrame
|
Fixed lateral table of the window. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
|
I-24 MOTION from a window to lanes on the main carriageway: preparation, optional stitching, run, settling labels.
Main function: run_i24motion. The steps, each a public function of trajlab.datasets.i24 (or of
trajlab.experimental.i24_stitching):
- the lateral table: the shipped table of the window's traffic state, or one estimated on the window;
run_i24motion_preparation: other carriageway, positions off the band, lateral correction, median-side cut, duplicates;- with
stitching="experimental":stitch_i24motion(N2v3_K) andcompute_i24motion_bridges; detect_i24motion_off_mainline: ramps and auxiliary lanes set apart; the pipeline (run_pipeline_detailedwith the preseti24_motion) runs on the main carriageway, in time chunks;compute_i24motion_edge_labels(the settling at fragment ends), the positions off the main carriageway appended without a lane, anddetect_i24motion_off_coverage.
The stitching runs here, before the pipeline, and not in trajlab.processing: the pipeline's own stitching step
stays off in the preset.
I24MotionOptions
dataclass
I24MotionOptions(stitching: Literal['none', 'experimental'] = 'none', table: Literal['reference', 'estimate'] = 'reference', estimate_minutes: float | None = None, chunk_minutes: float | None = 2.0, median_cut: bool = True, remove_duplicates: bool = False)
Options of run_i24motion; the key dataset of the preset sets them (preset i24_motion).
Attributes:
| Name | Type | Description |
|---|---|---|
stitching |
Literal['none', 'experimental']
|
|
table |
Literal['reference', 'estimate']
|
|
estimate_minutes |
float | None
|
With |
chunk_minutes |
float | None
|
Run the pipeline in time chunks of this length [min] (bounded memory); None: in one run. |
median_cut |
bool
|
Remove the positions beyond the median-side edge ( |
remove_duplicates |
bool
|
Remove the shorter fragment of each duplicate pair. |
__post_init__
__post_init__() -> None
Check the choices.
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
I24MotionResult
dataclass
I24MotionResult(tracks: DataFrame, events: DataFrame, table: DataFrame, counts: dict[str, object] = dict(), links: DataFrame = pd.DataFrame(), low_speed_links: DataFrame = pd.DataFrame())
Result of run_i24motion.
Attributes:
| Name | Type | Description |
|---|---|---|
tracks |
DataFrame
|
Pipeline output ( |
events |
DataFrame
|
Pipeline events. |
table |
DataFrame
|
The lateral table used. |
counts |
dict[str, object]
|
Counts of the preparation, with the window's traffic state and median speed [km/h]. |
links |
DataFrame
|
Link records of the stitching (empty without it). |
low_speed_links |
DataFrame
|
|
run_i24motion
run_i24motion(window: DataFrame, config: PipelineConfig | str = 'i24_motion', *, options: I24MotionOptions | None = None) -> I24MotionResult
Run one window of one direction of I-24 MOTION from the provider's fragments to lanes on the main carriageway.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window
|
DataFrame
|
Window of one direction ( |
required |
config
|
PipelineConfig | str
|
Pipeline configuration, or the name of a preset; with a name, its key |
'i24_motion'
|
options
|
I24MotionOptions | None
|
Options; None: those of the preset ( |
None
|
Returns:
| Type | Description |
|---|---|
I24MotionResult
|
The tracks and events of the window, the table, the counts and, with stitching, the links. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the experimental stitching is asked for while the pipeline's own stitching step is on. |