popframe.preprocessing.level_filler

Classes

LevelFiller(*, towns)

A class for automatically assigning administrative levels to towns based on population thresholds.

TownRow(*, geometry, index, name, population)

A model representing a town's data row in a GeoDataFrame.

class popframe.preprocessing.level_filler.TownRow(*, geometry: Point, index: int, name: str, population: int, level: str = 'Нет уровня')[source]

Bases: BaseRow

A model representing a town’s data row in a GeoDataFrame.

Attributes

geometryshapely.geometry.Point

The geographic location of the town.

namestr

The name of the town.

populationint

The population of the town. Must be greater than zero.

levelstr, optional

The administrative level of the town, defaults to “Нет уровня” (no level).

geometry: Point
name: str
population: int
level: str
model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

class popframe.preprocessing.level_filler.LevelFiller(*, towns: GeoDataFrame[TownRow])[source]

Bases: BaseModel

A class for automatically assigning administrative levels to towns based on population thresholds.

Attributes

townsGeoDataFrame[TownRow]

A GeoDataFrame containing town data that includes name, population, and level.

population_thresholdsdict

A class-level attribute defining population ranges for different administrative levels.

Methods

_assign_level(row) -> str

A static method that assigns the correct administrative level to a town based on its population.

validate_towns(gdf)

A Pydantic validator that ensures town levels are correctly assigned before processing the GeoDataFrame.

fill_levels() -> GeoDataFrame[TownRow]

Fills in the levels for all towns in the GeoDataFrame based on population and returns the updated GeoDataFrame.

towns: GeoDataFrame[TownRow]
population_thresholds: ClassVar[dict[str, tuple[int, int]]] = {'Большое сельское поселение': (1000, 3000), 'Большой город': (100000, 250000), 'Крупнейший город': (1000000, 3000000), 'Крупное сельское поселение': (3000, 5000), 'Крупный город': (250000, 1000000), 'Малое сельское поселение': (0, 200), 'Малый город': (5000, 50000), 'Сверхкрупный город': (3000000, inf), 'Среднее сельское поселение': (200, 1000), 'Средний город': (50000, 100000)}
static _assign_level(row) str[source]

Assigns a level to a town based on its population.

Parameters

rowpd.Series

A row from the GeoDataFrame containing town data.

Returns

str

The administrative level of the town.

classmethod validate_towns(gdf)[source]

Validates and assigns levels to towns in the provided GeoDataFrame.

Parameters

gdfGeoDataFrame

A GeoDataFrame containing town data.

Returns

GeoDataFrame[TownRow]

A validated GeoDataFrame with assigned administrative levels.

fill_levels() GeoDataFrame[TownRow][source]

Fills in the administrative levels for the towns based on their population.

Returns

GeoDataFrame[TownRow]

An updated GeoDataFrame with filled levels for each town.

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.