pycensus.resolution¶
Spatial resolution class of a census dataset: low, normal or high.
Every source (and geometry level of a source) carries one of three classes, so that callers can refuse data that are too coarse for a use:
low: the finest unit is the municipality or something larger (LAU, NUTS, county, province, state, nation).normal: municipal units only where municipalities (or counties) are small -- under 10,000 residents -- and sub-municipal units wherever they are larger.high:normaland, in addition, every unit of the dataset with more than 5,000 residents covers 1 km2 or less.
Rules of use (user, 2026-11-17):
- regressions never use
lowdatasets; - the census tab of the maps uses only
highdatasets.
The class is computed from the data, never typed by hand: :func:classify takes the dataset's units (population +
geometry) and the municipalities of the same territory, and returns the class together with the units that broke the
rule, so an exception can be inspected rather than hidden.
Example
from pycensus.resolution import classify result = classify(units, municipalities) # doctest: +SKIP result.resolution, len(result.high_failures) # doctest: +SKIP ('high', 0)
ResolutionResult(resolution, normal_failures=list(), high_failures=list())
dataclass
¶
Outcome of :func:classify.
Attributes:
| Name | Type | Description |
|---|---|---|
resolution |
str
|
|
normal_failures |
List[str]
|
ids of municipalities with at least |
high_failures |
List[str]
|
ids of the dataset's units with more than |
at_least(resolution, required)
¶
Whether resolution is at least required (high >= normal >= low).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolution
|
str
|
The dataset's class. |
required |
required
|
str
|
The minimum class a use accepts. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the dataset may be used. |
usable_for(resolution, use)
¶
Apply the rules of use: "regression" needs normal or better, "census_tab" needs high.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolution
|
str
|
The dataset's class. |
required |
use
|
str
|
|
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the dataset may be used for |
Raises:
| Type | Description |
|---|---|
ValueError
|
for an unknown use. |
classify(units, municipalities=None, pop_col='population', id_col='GEOID', muni_pop_col='population', muni_id_col='GEOID', is_municipal=None, cover_share=0.9)
¶
Classify a dataset's units as low, normal or high.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
units
|
GeoDataFrame of the dataset's finest units, with a population column. |
required | |
municipalities
|
GeoDataFrame of the municipalities of the same territory, with their population. Needed for the
|
None
|
|
pop_col
|
str
|
Population column of |
'population'
|
id_col
|
str
|
Id column of |
'GEOID'
|
muni_pop_col
|
str
|
Population column of |
'population'
|
muni_id_col
|
str
|
Id column of |
'GEOID'
|
is_municipal
|
Optional[bool]
|
|
None
|
cover_share
|
float
|
a large municipality counts as "not split" when one unit covers at least this share of its area. |
0.9
|
Returns:
| Type | Description |
|---|---|
ResolutionResult
|
class: |