Skip to content

Triplegs

Triplegs summarizes one movement segment between consecutive staypoints. Each row describes a door-to-door segment rather than its raw point geometry, making it suitable for mode classification and trip aggregation.

Catalogue

API Description Example
Triplegs One row per tripleg (a movement segment between two staypoints). Movement between stops
Triplegs.calculate_modal_split Aggregate this mode-labeled table into a modal-split table. Movement between stops
Triplegs.from_positionfixes Derive triplegs from positionfixes + already-generated staypoints. The same pipeline, step by step
Triplegs.generate_trips Group consecutive triplegs into trips. Trips and tours
Triplegs.predict_transport_mode Classify each tripleg's transport mode from its average speed. Movement between stops

Required data

Validated triplegs contain tripleg_id, started_at, finished_at, length_km, and duration_s, plus a user ID when the data represents multiple people. Generated triplegs also include mean speed information.

classified = triplegs.predict_transport_mode()
trips = classified.generate_trips(active_staypoints)

generate_trips() requires staypoints with an activity flag. Create that flag first with Staypoints.create_activity_flag().

API

Triplegs

Bases: BaseDataFrame

One row per tripleg (a movement segment between two staypoints).

.df is the per-tripleg summary table: tripleg_id, started_at, finished_at, length_km, duration_s, mean_speed_kmh, plus uid_col when present. Reconstructing each tripleg's point-by-point geometry (e.g. for a LineString) is not built in this pass.

Parameters:

Name Type Description Default
df dataframe

Source data; any Narwhals-compatible eager backend.

required
uid_col str

User-ID column name.

None
validate bool

When True (default), check that required columns are present.

True

calculate_modal_split(freq=None, metric='count', per_user=False, normalize=False)

Aggregate this mode-labeled table into a modal-split table.

See fastmob.preprocessing.calculate_modal_split.

Returns:

Type Description
DataFrame

Modal split aggregated by the requested frequency and metric.

Examples:

>>> modal_split = classified_triplegs.calculate_modal_split(metric="count")

from_positionfixes(positionfixes, staypoints, gap_threshold_min=15.0, **stop_kwargs) staticmethod

Derive triplegs from positionfixes + already-generated staypoints.

See fastmob.core.positionfixes_dataframe.Positionfixes.generate_triplegs.

Returns:

Type Description
Triplegs

Movement segments derived from the raw fixes and stops.

Examples:

>>> triplegs = Triplegs.from_positionfixes(positionfixes, staypoints)

generate_trips(staypoints, gap_threshold_min=15.0)

Group consecutive triplegs into trips.

See fastmob.core.trips_dataframe.Trips.from_triplegs.

Examples:

>>> trips = triplegs.generate_trips(activity_staypoints)

predict_transport_mode(method='simple-coarse', categories=None)

Classify each tripleg's transport mode from its average speed.

See fastmob.preprocessing.predict_transport_mode.

Parameters:

Name Type Description Default
method str

Classification method. Default is "simple-coarse".

'simple-coarse'
categories dict or None

Custom speed-to-mode categories.

None

Returns:

Type Description
Triplegs

Copy with a mode column.

Examples:

>>> classified = triplegs.predict_transport_mode()

Worked example: Movement between stops · The same pipeline, step by step · Trips and tours