transitlos.map.col_select¶
Simplified column list + relevance ordering + election-party rules for the stats panel / dropdowns of a MapLibre page.
Build time (column_select_script): from the finest grid (level_of_service + population weights) compute, per candidate column,
* r2 weighted R^2 against level_of_service (best of raw / log, like the Regression tab) -> dropdown order of regression / opacity-by,
* anova |difference in mean level_of_service between the high and low half| (like the Census tab) -> order of the other selectors,
* simple the simplified column set: every derived / global-schema column, plus the single most relevant (highest R^2) column of each
local topic (elections, housing price, rent, race ...; two for race); election parties: only the 4 most voted parties per election
when they hold > 5% of the votes.
Run time (COLUMN_SELECT_JS): window.__colVisible(col) (simplified unless the "Extended census" checkbox is on, plus the scope rule: at
nation scope no state / municipal election parties and, outside the US, only the left / right proxies), used by the Census and Regression
tabs and by the custom dropdowns (which are also ordered by relevance). Pass simplified_columns to override the heuristic.
column_stats(gdf, fields, score_col='level_of_service')
¶
{field: {r2, anova}} for every numeric field present on gdf.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
Finest map level. |
required | |
fields
|
Iterable[str]
|
Columns to rate. |
required |
score_col
|
str
|
Score column. |
'level_of_service'
|
top_parties(gdf, max_parties=4, min_share=0.05)
¶
Party columns to keep: per election (prefix) the max_parties most voted parties whose vote share is above min_share.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
Finest map level. |
required | |
max_parties
|
int
|
Parties kept per election. |
4
|
min_share
|
float
|
Smallest vote share kept. |
0.05
|
template(us)
¶
The fixed simplified template: (concept, [candidate columns, canonical name first], ...); the first candidate present wins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
us
|
bool
|
US map (US column names). |
required |
main_religions(finest, fields, top=4, min_share=0.03)
¶
The main religions of the place: the religion share columns with the highest population-weighted mean (up to top, each >= 3%).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
finest
|
Finest map level. |
required | |
fields
|
List[str]
|
Available columns. |
required |
top
|
int
|
Most religions kept. |
4
|
min_share
|
float
|
Smallest mean share kept. |
0.03
|
template_columns(fields, us)
¶
Resolve the template against the available fields -> (columns in template order, {concept: column or None}).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fields
|
List[str]
|
Available columns. |
required |
us
|
bool
|
US map. |
required |
column_select_script(finest, fields, is_us, global_logical=None, strip=None, simplified=None, score_col='level_of_service')
¶
simplified overrides the fixed template; relevance (R^2 / ANOVA) only orders the dropdowns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
finest
|
Finest map level. |
required | |
fields
|
List[str]
|
Available columns. |
required |
is_us
|
bool
|
US map. |
required |
global_logical
|
Global logical name per column. |
None
|
|
strip
|
Function removing source prefixes. |
None
|
|
simplified
|
Optional[List[str]]
|
Columns of the simplified list (overrides the template). |
None
|
score_col
|
str
|
Score column. |
'level_of_service'
|
Returns:
| Type | Description |
|---|---|
str
|
|