Experimental
Generated by docs/scripts/make_api_pages.py.
Experimental tools: their API may change in any release, and their results are not validated like the rest.
trajlab.experimental.i24_stitching: stitching of the I-24 MOTION fragments (parameter set N2v3_K).
Import the modules directly; nothing is imported here.
Experimental: the API may change. Stitching of the I-24 MOTION fragments with the parameter set N2v3_K.
The state of the experiment (methods, variants and their measures, what did not help, the upper bound, open problems)
is on the documentation page docs/experimental/i24_stitching.md; stitching holds the code.
I24StitchParams
dataclass
I24StitchParams(max_overlap_sec: float, overlap_offsets: tuple[Mapping[str, float], ...], sigma_x: tuple[float, float], sigma_y: float, sigma_v: tuple[float, float], gate_sigma_x: float, gate_sigma_y: float, ambiguity_sigma: float, dim_sigmas: Mapping[str, float], dim_gate_sigma: float, max_gap_sec: float, envelopes: Mapping[str, float], lateral: Mapping[str, tuple[float, float, float]], gap_ambiguity_margin: float, gap_base_x_m: float, offsets_for_gaps: bool, field_prediction: bool, field_sigma: tuple[float, float], field_states: tuple[str, ...], gap_max_dv: float | None, class_cost: bool, bridge_trim_s: float)
One parameter set of the I-24 cascade for one direction (read_i24motion_stitch_params).
Attributes:
| Name | Type | Description |
|---|---|---|
max_overlap_sec |
float
|
Longest time overlap [s] of the overlap stage. |
overlap_offsets |
tuple[Mapping[str, float], ...]
|
Offset per camera hand-over ( |
sigma_x |
tuple[float, float]
|
|
sigma_y |
float
|
Spread of the lateral overlap residual [m]. |
sigma_v |
tuple[float, float]
|
|
gate_sigma_x |
float
|
Longitudinal overlap gate [sigma_x]. |
gate_sigma_y |
float
|
Lateral overlap gate [sigma_y]. |
ambiguity_sigma |
float
|
An overlap pair is ambiguous (not linked) if an alternative lies within this many sigma. |
dim_sigmas |
Mapping[str, float]
|
Spread [m] of the dimension differences of one vehicle per column (empty: no dimension term). |
dim_gate_sigma |
float
|
Gate of the dimension differences [sigma]. |
max_gap_sec |
float
|
Longest gap [s] of the gap stages. |
envelopes |
Mapping[str, float]
|
Acceleration envelope [m/s^2] of the gap stages per traffic state of the tail. |
lateral |
Mapping[str, tuple[float, float, float]]
|
|
gap_ambiguity_margin |
float
|
Ambiguity margin of the gap stages [m]. |
gap_base_x_m |
float
|
Longitudinal tolerance of the gap stages [m]. |
offsets_for_gaps |
bool
|
Apply the hand-over offsets also to gap pairs whose head starts in an offset zone. |
field_prediction |
bool
|
Predict the head start from the displacement of the tail's leader and follower in its lane over the gap, where they run through it, instead of the tail's own speed. |
field_sigma |
tuple[float, float]
|
|
field_states |
tuple[str, ...]
|
Traffic states of the tail in which the neighbour prediction applies. |
gap_max_dv |
float | None
|
Speed gate of the gap stages [m/s] (plus 0.25 m/s per second of gap); None: none. |
class_cost |
bool
|
The class as a cost term instead of a gate ( |
bridge_trim_s |
float
|
Time [s] trimmed at both fragment ends of a joint by |
to_json
to_json() -> str
Return the parameter set as JSON (the form of one direction in the parameter file).
Returns:
| Type | Description |
|---|---|
str
|
The JSON text. |
I24Stitching
dataclass
I24Stitching(positions: DataFrame, links: DataFrame)
Result of stitch_i24motion.
Attributes:
| Name | Type | Description |
|---|---|---|
positions |
DataFrame
|
The prepared positions with the stitched vehicle in |
links |
DataFrame
|
One row per assigned pair of every stage (the records of the library cascade: |
compute_i24motion_bridges
compute_i24motion_bridges(stitched: DataFrame, *, trim_s: float = 1.5, fit_s: float = 0.5, max_bridge_s: float = 4.0) -> pd.DataFrame
Join the fragments of every stitched vehicle with cubic Hermite bridges (C1 at both joints).
The joint of trajlab.processing.stitching.bridge_joints: trim_s is dropped at both fragment ends of a joint
(the provider's positions settle there), the end states are fitted over fit_s and the gap is filled on the
25-Hz grid. Vehicles of a single fragment are passed through as one block, so that the result is that of
bridge_joints at a fraction of its time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stitched
|
DataFrame
|
|
required |
trim_s
|
float
|
Time [s] dropped at both fragment ends of a joint ( |
1.5
|
fit_s
|
float
|
Window [s] of the end-state fits. |
0.5
|
max_bridge_s
|
float
|
Longest gap [s] that is bridged. |
4.0
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
|
DataFrame
|
each bridge). |
detect_i24motion_low_speed_links
detect_i24motion_low_speed_links(stitched: DataFrame) -> pd.DataFrame
Flag the links whose tail ends below LOW_SPEED_LINK_MPS: stitching in standing queues is not validated.
A link is a pair of consecutive provider fragments of one vehicle; the tail speed is the slope of pos_lon
over the last 1 s of the tail fragment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stitched
|
DataFrame
|
|
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per link: |
read_i24motion_stitch_params
read_i24motion_stitch_params(direction: int, path: Path | str | None = None) -> I24StitchParams
Read the parameter set of one direction from a parameter file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
direction
|
int
|
+1 (EB) or -1 (WB). |
required |
path
|
Path | str | None
|
Parameter file ( |
None
|
Returns:
| Type | Description |
|---|---|
I24StitchParams
|
The parameter set. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
stitch_i24motion
stitch_i24motion(prepared: DataFrame, params: I24StitchParams | None = None) -> I24Stitching
Link the provider fragments of one prepared window into vehicles (experimental).
The stages: the overlap stage, then the gap stages of the library's default cascade up to max_gap_sec, one
copy per traffic state of the tail (STATE_BANDS) with its envelope and lateral limits. Per stage: the end
states of the fragments, the costs of the admissible tail-head pairs, the one-to-one assignment with the
ambiguity check and the join, as trajlab.processing.stitching.stitch_trajectories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prepared
|
DataFrame
|
Prepared positions of one direction ( |
required |
params
|
I24StitchParams | None
|
Parameter set; None: the shipped N2v3_K of the direction. |
None
|
Returns:
| Type | Description |
|---|---|
I24Stitching
|
The stitched positions and the link records. |
Experimental: the API may change. Stitching of the I-24 MOTION fragments with the parameter set N2v3_K.
Main function: stitch_i24motion links the provider's fragments of one prepared window
(trajlab.datasets.i24.run_i24motion_preparation) into vehicles; compute_i24motion_bridges joins the fragments
of each vehicle with cubic Hermite bridges and detect_i24motion_low_speed_links flags the links whose tail ends
below 5 m/s (stitching in standing queues is not validated). trajlab.datasets.i24.run_i24motion runs them before
the pipeline when the preset says dataset: {stitching: experimental}.
The cascade is the one of trajlab.processing.stitching (StitchingStage, the passes of cascaded_stitching)
with I-24 values and four additions (docs/datasets/i24_motion.md):
- the overlap stage with an offset per camera hand-over (
dx + tau * v,dy), costs in sigma units; - a speed gate of the gap stages (
gap_max_dvplus 0.25 m/s per second of gap), one gap stage per traffic state with its own acceleration envelope and lateral limits, and gaps of at mostmax_gap_sec(5 s); - for free-flow tails the head start is predicted from the displacement of the tail's leader and follower in its lane over the gap (the neighbour prediction), where they run through the gap;
- the vehicle class as a cost term: a class mismatch adds one
base_x_error_m, only a length difference ofCLASS_COST_MAX_DL_Mor more rejects (cameras label one vehicle differently).
Studied on the 2022-11-22 development windows and left out: a lane rule (the lane of the fragment ends as a pre-filter; it lowered recall by 0.3-3.4 points at equal precision in every state, because the lateral gates are already below a lane width), and a joint assignment of the ends beyond 5 s (best precision 0.79-0.90 at recall 0.16-0.22).
The candidate pairs are searched over the sorted start times instead of the dense matrix of all tail-head pairs, and the assignment runs per connected group of admissible pairs; gates and costs are the library's expressions, element by element, so that the links are those of the dense pass.
I24StitchParams
dataclass
I24StitchParams(max_overlap_sec: float, overlap_offsets: tuple[Mapping[str, float], ...], sigma_x: tuple[float, float], sigma_y: float, sigma_v: tuple[float, float], gate_sigma_x: float, gate_sigma_y: float, ambiguity_sigma: float, dim_sigmas: Mapping[str, float], dim_gate_sigma: float, max_gap_sec: float, envelopes: Mapping[str, float], lateral: Mapping[str, tuple[float, float, float]], gap_ambiguity_margin: float, gap_base_x_m: float, offsets_for_gaps: bool, field_prediction: bool, field_sigma: tuple[float, float], field_states: tuple[str, ...], gap_max_dv: float | None, class_cost: bool, bridge_trim_s: float)
One parameter set of the I-24 cascade for one direction (read_i24motion_stitch_params).
Attributes:
| Name | Type | Description |
|---|---|---|
max_overlap_sec |
float
|
Longest time overlap [s] of the overlap stage. |
overlap_offsets |
tuple[Mapping[str, float], ...]
|
Offset per camera hand-over ( |
sigma_x |
tuple[float, float]
|
|
sigma_y |
float
|
Spread of the lateral overlap residual [m]. |
sigma_v |
tuple[float, float]
|
|
gate_sigma_x |
float
|
Longitudinal overlap gate [sigma_x]. |
gate_sigma_y |
float
|
Lateral overlap gate [sigma_y]. |
ambiguity_sigma |
float
|
An overlap pair is ambiguous (not linked) if an alternative lies within this many sigma. |
dim_sigmas |
Mapping[str, float]
|
Spread [m] of the dimension differences of one vehicle per column (empty: no dimension term). |
dim_gate_sigma |
float
|
Gate of the dimension differences [sigma]. |
max_gap_sec |
float
|
Longest gap [s] of the gap stages. |
envelopes |
Mapping[str, float]
|
Acceleration envelope [m/s^2] of the gap stages per traffic state of the tail. |
lateral |
Mapping[str, tuple[float, float, float]]
|
|
gap_ambiguity_margin |
float
|
Ambiguity margin of the gap stages [m]. |
gap_base_x_m |
float
|
Longitudinal tolerance of the gap stages [m]. |
offsets_for_gaps |
bool
|
Apply the hand-over offsets also to gap pairs whose head starts in an offset zone. |
field_prediction |
bool
|
Predict the head start from the displacement of the tail's leader and follower in its lane over the gap, where they run through it, instead of the tail's own speed. |
field_sigma |
tuple[float, float]
|
|
field_states |
tuple[str, ...]
|
Traffic states of the tail in which the neighbour prediction applies. |
gap_max_dv |
float | None
|
Speed gate of the gap stages [m/s] (plus 0.25 m/s per second of gap); None: none. |
class_cost |
bool
|
The class as a cost term instead of a gate ( |
bridge_trim_s |
float
|
Time [s] trimmed at both fragment ends of a joint by |
to_json
to_json() -> str
Return the parameter set as JSON (the form of one direction in the parameter file).
Returns:
| Type | Description |
|---|---|
str
|
The JSON text. |
I24Stitching
dataclass
I24Stitching(positions: DataFrame, links: DataFrame)
Result of stitch_i24motion.
Attributes:
| Name | Type | Description |
|---|---|---|
positions |
DataFrame
|
The prepared positions with the stitched vehicle in |
links |
DataFrame
|
One row per assigned pair of every stage (the records of the library cascade: |
read_i24motion_stitch_params
read_i24motion_stitch_params(direction: int, path: Path | str | None = None) -> I24StitchParams
Read the parameter set of one direction from a parameter file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
direction
|
int
|
+1 (EB) or -1 (WB). |
required |
path
|
Path | str | None
|
Parameter file ( |
None
|
Returns:
| Type | Description |
|---|---|
I24StitchParams
|
The parameter set. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
stitch_i24motion
stitch_i24motion(prepared: DataFrame, params: I24StitchParams | None = None) -> I24Stitching
Link the provider fragments of one prepared window into vehicles (experimental).
The stages: the overlap stage, then the gap stages of the library's default cascade up to max_gap_sec, one
copy per traffic state of the tail (STATE_BANDS) with its envelope and lateral limits. Per stage: the end
states of the fragments, the costs of the admissible tail-head pairs, the one-to-one assignment with the
ambiguity check and the join, as trajlab.processing.stitching.stitch_trajectories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prepared
|
DataFrame
|
Prepared positions of one direction ( |
required |
params
|
I24StitchParams | None
|
Parameter set; None: the shipped N2v3_K of the direction. |
None
|
Returns:
| Type | Description |
|---|---|
I24Stitching
|
The stitched positions and the link records. |
detect_i24motion_low_speed_links
detect_i24motion_low_speed_links(stitched: DataFrame) -> pd.DataFrame
Flag the links whose tail ends below LOW_SPEED_LINK_MPS: stitching in standing queues is not validated.
A link is a pair of consecutive provider fragments of one vehicle; the tail speed is the slope of pos_lon
over the last 1 s of the tail fragment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stitched
|
DataFrame
|
|
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per link: |
compute_i24motion_bridges
compute_i24motion_bridges(stitched: DataFrame, *, trim_s: float = 1.5, fit_s: float = 0.5, max_bridge_s: float = 4.0) -> pd.DataFrame
Join the fragments of every stitched vehicle with cubic Hermite bridges (C1 at both joints).
The joint of trajlab.processing.stitching.bridge_joints: trim_s is dropped at both fragment ends of a joint
(the provider's positions settle there), the end states are fitted over fit_s and the gap is filled on the
25-Hz grid. Vehicles of a single fragment are passed through as one block, so that the result is that of
bridge_joints at a fraction of its time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stitched
|
DataFrame
|
|
required |
trim_s
|
float
|
Time [s] dropped at both fragment ends of a joint ( |
1.5
|
fit_s
|
float
|
Window [s] of the end-state fits. |
0.5
|
max_bridge_s
|
float
|
Longest gap [s] that is bridged. |
4.0
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
|
DataFrame
|
each bridge). |