Skip to content

transitlos.stop_scores

Vectorized application of transitlos.scoring to a per-stop table.

Takes the raw per-stop table produced by transitlos.stops.download_and_prepare_stops (columns headway_minutes, headway_cv, avg_speed_kmh, route_type) and adds the mrc_score, speed_score, frequency_score, mode_category, and stop_score columns from transitlos.scoring.

2026-09-28 model rewrite: the prior four-factor (mode_score/speed_score/frequency_score/reliability_score) design is replaced by the finalized three-factor model (mrc_score/speed_score/ frequency_score -- see transitlos.scoring.mrc's module docstring for why mode and reliability/comfort are now one combined axis). stop_score is also no longer independently walk-decayed here: downstream callers now pass stop_score and mode_category into walk_access.walk_decay/ accessibility_score.accessibility_score, since D(t; stop_score)'s scale is itself mode- and stop_score-dependent (see walk_access.py).

Honesty note: headway_cv coming out of transitlos.stops is currently always null (pyGTFSHandler's get_headway_at_stops only exposes a mean headway, not its distribution). Rather than silently treating every stop as perfectly regular (which would make mrc.MR_CV(0) == 1.0 for every stop, erasing the mode-categorical gap), this module only feeds a real, observed headway_cv into mrc_score's optional (b) refinement -- rows with a null headway_cv fall back to the primary (a) mode-categorical default (MR_mode) instead, leaving a reliability_score_is_assumed boolean column so callers can tell which rows had a real CV input.

compute_stop_scores(stops_df, region='global', weights=None, default_headway_cv=None, stop_score_mode='nested')

Add mrc_score/speed_score/frequency_score/stop_score columns.

Parameters:

Name Type Description Default
stops_df Union[DataFrame, 'gpd.GeoDataFrame']

A pandas DataFrame or GeoDataFrame with headway_minutes, headway_cv, avg_speed_kmh, and (optionally) route_type columns (as produced by transitlos.stops.download_and_prepare_stops). Rows with a null headway_minutes or avg_speed_kmh get NaN scores. Rows with a missing/absent route_type fall back to the "bus" mode category (see transitlos.scoring.mrc.mode_category).

required
region str

Region key forwarded to every transitlos.scoring call. Kept for backward compatibility -- every region now shares identical, universal parameters (see scoring/parameters.py).

'global'
weights Optional[tuple[float, float, float]]

Only meaningful when stop_score_mode is "harmonic" or "geometric" (the legacy flat three-way mean) -- forwarded to stop_score. Must be left None for the default stop_score_mode="nested" (see scoring.stop_score's docstring -- the nested default has no weight parameter by construction).

None
stop_score_mode str

Forwarded to scoring.stop_score as mode. Defaults to "nested" (sqrt(MRC*V)*H, 2026-09-29 default). Pass "harmonic"/"geometric" to reproduce the prior flat generalized-power-mean forms, e.g. for before/after comparisons.

'nested'
default_headway_cv Optional[float]

No longer substituted into mrc_score (see module docstring's honesty note -- doing so would silently erase the mode-categorical default for every stop). Kept as an accepted, unused parameter for backward-compatibility only; passing a non-None value has no effect. Use reliability_score_is_assumed to identify rows using the mode-categorical fallback.

None

Returns:

Type Description
Union[DataFrame, 'gpd.GeoDataFrame']

stops_df (same type, a copy) with mode_category, mrc_score,

Union[DataFrame, 'gpd.GeoDataFrame']

speed_score, frequency_score, stop_score, and

Union[DataFrame, 'gpd.GeoDataFrame']

reliability_score_is_assumed columns added.