transitlos.scoring.direction_subset¶
Best stop score per parent station from merged departures, split into two travel directions.
For every parent station all departures of every route are pooled and split into the two opposite directions of travel (the angle of
the line through the station that best separates the shape directions, "uptown" / "downtown"); route ids play no role. The headway of a
direction is computed on the MERGED, sorted departure times -- (sum(gap^2) + (first - start + end - last)^2) / window -- so two buses
that leave at the same moment count once (0,5,0,5 scores like 5,5) and a duplicated timetable changes nothing.
Each departure carries the speed of its trip at the station and the mode tier of its route. The speed (speed_method, 2026-11-17: the
way speed is computed on every map) is measured over a window of window_min minutes (default 15) before and after the station (window_direction: both sides by
default, or only after / before):
"straight"(default): straight-line distance from the station to where the trip is 15 min before plus 15 min after, over the time taken -- a winding line is slower than a direct one at the same running speed;"shape": the same window, distance along the shape.
(Before 2026-11-17 the speed was the whole trip's shape distance / scheduled travel time.)
Near a trip's ends the window is cut at the first / last stop (the time shrinks with it). For each
mode tier (bus = every mode, tram = tram + rail, rail = rail only) and each minimum trip speed (0, 5, 10, ... km/h up to the fastest
trip of the tier, steps of speed_bucket_kmh) the departures that pass are kept, the headway of each direction is recomputed without the slow trips and
the better direction is used; the mean speed of the kept trips and the tier's mode give the three scores. The combination with the
highest stop_score wins, so excluding slow lines sometimes raises a stop's score.
direction_headway_minutes(times, start_sec, end_sec)
¶
Headway (minutes) of one direction from its sorted departure times (seconds): the mean-wait style measure used by the library.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
times
|
ndarray
|
Sorted departure times (s). |
required |
start_sec
|
float
|
Window start (s). |
required |
end_sec
|
float
|
Window end (s). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Headway in minutes (inf with no departure). |
departures_with_direction(feed, analysis_date, start_time, end_time, route_modes, speed_method=SPEED_METHOD, window_min=SPEED_WINDOW_MIN, window_direction=SPEED_WINDOW_DIRECTION)
¶
One row per departure at a parent station: parent_station, departure_time, route_id, rank, speed_kmh, dist_m, time_s, sector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feed
|
A loaded |
required | |
analysis_date
|
Service date. |
required | |
start_time
|
Start of the scoring window. |
required | |
end_time
|
End of the scoring window. |
required | |
route_modes
|
DataFrame
|
|
required |
speed_method
|
str
|
|
SPEED_METHOD
|
window_min
|
float
|
Minutes on each side of the station over which the speed is measured (default 15). |
SPEED_WINDOW_MIN
|
window_direction
|
str
|
|
SPEED_WINDOW_DIRECTION
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per departure; |
best_stop_scores_by_direction(feed, analysis_date, route_modes, start_time=time(6, 0), end_time=time(22, 0), region='global', speed_bucket_kmh=5.0, speed_method=SPEED_METHOD, window_min=SPEED_WINDOW_MIN, window_direction=SPEED_WINDOW_DIRECTION)
¶
Best (mode tier, minimum trip speed) per parent station; see the module docstring.
Returns one row per parent station with parent_station, route_ids, scoring_mode, headway_minutes, avg_speed_kmh,
min_speed_cutoff_kmh, mrc_score, speed_score, frequency_score, stop_score (same columns as the route-based search it replaces).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feed
|
A loaded pyGTFSHandler Feed. |
required | |
analysis_date
|
Union[date, datetime]
|
Service date. |
required |
route_modes
|
DataFrame
|
|
required |
start_time
|
Union[datetime, time]
|
Start of the scoring window. |
time(6, 0)
|
end_time
|
Union[datetime, time]
|
End of the scoring window. |
time(22, 0)
|
region
|
str
|
Scoring region (curve set). |
'global'
|
speed_bucket_kmh
|
float
|
Minimum-speed step (km/h). |
5.0
|
speed_method
|
str
|
|
SPEED_METHOD
|
window_min
|
float
|
Minutes on each side of the station. |
SPEED_WINDOW_MIN
|
window_direction
|
str
|
|
SPEED_WINDOW_DIRECTION
|