UrbanAccessAnalyzer.scoring¶
POI quality scoring: from raw attributes to a calibrated [0, 1] access score.
Consolidates three previously separate, duplicated modules: scoring.py and
quality.py were byte-for-byte near-duplicates (a "POI scoring" vs.
"transit stop quality" naming fork of the same elasticity/calibration code),
and poi_utils.py internally duplicated score_by_values/
score_by_area under both "quality_" and "score_" names. Per the
package's naming convention, everything here is called score/
access_score -- never "quality".
Methodology:
- :func:
score_by_valuesand :func:score_by_areaproduce a simple[0, 1]ordinal score from a categorical value or a continuous area, respectively, given an explicit priority ordering. - :func:
elasticity_based_scorecomputes a continuous decay score using the economic notion of elasticity: score(v) = (v / reference) ** elasticity for constant elasticity, or the exponential of the integral ofelasticity(x)/xfor a value- or interval-dependent elasticity (matching how price elasticity of demand extends to non-constant elasticities). This gives a principled decay curve (e.g. for distance or headway) instead of an arbitrary hand-picked shape. - :func:
build_adaptive_gridsbuilds a non-uniform grid per input variable so that adjacent grid points never differ by more thandeltain a given (possibly expensive/non-vectorizable) score function -- used to precompute a lookup table instead of recomputing the function per row. - :func:
calibrate_scoring_funclinearly rescales an arbitrary score function's output range to a target[min_score, max_score]given calibration anchor points.
condense_rows(df, row_values=None, columns=None)
¶
Collapse multiple boolean/tag columns into a single value per row.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame (attribute columns to condense, e.g. one column
per OSM tag like |
required |
row_values
|
Optional[list]
|
Priority order of values; the first matching value (by
this order) found in any of |
None
|
columns
|
Optional[list]
|
Columns to consider; defaults to every column except
|
None
|
Returns:
| Type | Description |
|---|---|
list
|
List of condensed values, one per row ( |
list
|
matched). |
score_by_values(values, value_priority)
¶
Map categorical values to a [0, 1] score by explicit priority order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Union[list, Series]
|
Categorical values to score (e.g. amenity subtype). |
required |
value_priority
|
list
|
Values in priority order, best first; must be unique and contain no null. |
required |
Returns:
| Type | Description |
|---|---|
list
|
List of scores in |
list
|
|
list
|
in |
list
|
worst possible score, not |
list
|
convention that non-computed/unreachable values on a bounded 0-1 |
list
|
"higher is better" scale collapse to 0, while non-computed values on |
list
|
an unbounded "lower is better" scale (e.g. a distance) should stay |
list
|
|
list
|
i.e. unreached, distance). |
Raises:
| Type | Description |
|---|---|
Exception
|
If |
score_by_area(gdf, area_steps, large_is_better=True)
¶
Score geometries by which area threshold bin they fall into.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
Union[GeoDataFrame, GeoSeries]
|
Input geometries (any CRS; reprojected to local UTM to measure area). |
required |
area_steps
|
list[float]
|
Area breakpoints (m²), any order (sorted internally). |
required |
large_is_better
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
list
|
List of scores in |
list
|
"higher is better" score: geometries that don't clear any threshold |
list
|
(never assigned a bucket) score |
list
|
func: |
polygons_to_points(poi, street_edges)
¶
Convert polygon/line POIs to points by intersecting with street edges.
Points and multipoints pass through unchanged. Polygons are reduced to
their boundary; everything else is intersected with the union of
street_edges, which pulls out the point(s) where the POI actually
touches the walkable network (used before snapping POIs onto a graph).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
poi
|
GeoDataFrame
|
POI geometries (any mix of Point/Polygon/MultiPolygon/etc.). |
required |
street_edges
|
GeoDataFrame
|
Street edge geometries to intersect non-point POIs with. |
required |
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
GeoDataFrame of Point geometries (exploded, empty intersections |
GeoDataFrame
|
dropped), with a |
GeoDataFrame
|
|
build_adaptive_grids(func, variables, delta=0.1, max_iters=30)
¶
Build non-uniform grids so func changes by at most delta between adjacent points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable
|
Broadcastable callable, |
required |
variables
|
List[Union[List[float], tuple, ndarray]]
|
Per-variable spec: a continuous |
required |
delta
|
float
|
Maximum allowed change in |
0.1
|
max_iters
|
int
|
Maximum refinement iterations. |
30
|
Returns:
| Type | Description |
|---|---|
List[ndarray]
|
List of 1-D numpy arrays, one refined grid per variable. |
elasticity_from_linear_decay(decay, point)
¶
Convert a linear decay rate at a reference point into an equivalent elasticity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
decay
|
float
|
Linear decay rate (fraction lost per unit of |
required |
point
|
float
|
The point at which |
required |
Returns:
| Type | Description |
|---|---|
float
|
The elasticity value |
float
|
matches the given linear decay at |
elasticity_based_score(value, reference, elasticity, steps=200)
¶
Compute a decay score via elasticity-based integration, vectorized.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Union[float, List[float], ndarray]
|
Current value(s) of the variable (e.g. distance, headway). |
required |
reference
|
float
|
Reference value where score == 1.0. |
required |
elasticity
|
Union[float, Callable[[float], float], List[Sequence[float]]]
|
Constant elasticity (float, analytic solution), a
piecewise elasticity |
required |
steps
|
int
|
Integration steps, used only for the callable case. |
200
|
Returns:
| Type | Description |
|---|---|
Union[float, ndarray]
|
Score(s) in |
Union[float, ndarray]
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
calibrate_scoring_func(score_func, *, min_score=0.1, max_score=1.0, min_point=None, max_point=None, variable_steps=None)
¶
Linearly rescale a multi-parameter score function to [min_score, max_score].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
score_func
|
Callable[..., Union[float, ndarray]]
|
Function accepting positional arguments; may return a
scalar or vectorized |
required |
min_score
|
float
|
Output value at the calibration minimum. |
0.1
|
max_score
|
float
|
Output value at the calibration maximum. |
1.0
|
min_point
|
Optional[Sequence[T]]
|
Explicit argument tuple defining the minimum; if omitted,
inferred as the minimum over |
None
|
max_point
|
Optional[Sequence[T]]
|
Explicit argument tuple defining the maximum; if omitted,
inferred as the maximum over |
None
|
variable_steps
|
Optional[List[Any]]
|
Per-argument value lists used to search for the
calibration min/max when |
None
|
Returns:
| Type | Description |
|---|---|
Callable[..., Union[float, ndarray]]
|
A new function with |
Callable[..., Union[float, ndarray]]
|
rescaled score. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no calibration points can be determined, or if the calibration min and max coincide. |
Exception
|
If every evaluated score is zero while |