Skip to content

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: normal and, 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 low datasets;
  • the census tab of the maps uses only high datasets.

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

"low", "normal" or "high".

normal_failures List[str]

ids of municipalities with at least NORMAL_MUNICIPAL_POP residents that the dataset does not split (one unit covers most of the municipality).

high_failures List[str]

ids of the dataset's units with more than HIGH_UNIT_POP residents and more than HIGH_MAX_AREA_KM2 of area.

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

"regression" or "census_tab".

required

Returns:

Type Description
bool

True if the dataset may be used for use.

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 normal test unless is_municipal settles it.

None
pop_col str

Population column of units.

'population'
id_col str

Id column of units.

'GEOID'
muni_pop_col str

Population column of municipalities.

'population'
muni_id_col str

Id column of municipalities.

'GEOID'
is_municipal Optional[bool]

True when the units are municipalities or larger (the class is then low without any geometric test); None to decide from the geometry.

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:ResolutionResult.