blocksnet.method.land_use_prediction
Classes
|
A class used to predict land use based on various methods including cosine similarity. |
- class blocksnet.method.land_use_prediction.LandUsePrediction(*, city_model: City, verbose: bool = True)[source]
Bases:
BaseMethod
A class used to predict land use based on various methods including cosine similarity.
- plot(gdf: gpd.GeoDataFrame, linewidth=0.1, figsize=(10, 10)):
Plots the GeoDataFrame with predicted land use.
- _get_land_uses_services():
Retrieves land use service types for the city model.
- _get_blocks_gdf():
Retrieves block geometries and their service capacities as a GeoDataFrame.
- _get_unique_per_landuse(landuse_items):
Finds unique service tags for each land use.
- _intersects(set1, set2):
Checks if two sets have any common elements.
- _predict_block_landuse_cosine_similarity(block_vector, landuse_vectors, return_prob=False):
Predicts land use for a block using cosine similarity.
- _predict_block_landuse(codes_in_block, landuse_items, use_cos_similarity=True):
Predicts the land use for a block.
- calculate(use_cos_similarity=True):
Calculates the land use prediction for all blocks.
- static plot(gdf: GeoDataFrame, linewidth: float = 0.1, figsize: tuple[int, int] = (10, 10))[source]
Plots the GeoDataFrame with predicted land use.
- Parameters:
gdf (gpd.GeoDataFrame) – GeoDataFrame containing the geometries and predicted land use.
linewidth (float, optional) – Size of the polygon border to plot, by default 0.1.
figsize (tuple, optional) – Size of the figure to plot, by default (10, 10).
- _get_land_uses_services() dict[str, list[str]] [source]
Retrieves land use service types for the city model.
- Returns:
Dictionary with land use names as keys and lists of service types as values.
- Return type:
dict
- _get_blocks_gdf() GeoDataFrame [source]
Retrieves block geometries and their service capacities as a GeoDataFrame.
- Returns:
GeoDataFrame with block geometries and boolean values representing the presence of each service type.
- Return type:
gpd.GeoDataFrame
- static _get_unique_per_landuse(landuse_items) dict[blocksnet.models.land_use.LandUse, set[str]] [source]
Finds unique service tags for each land use.
- Parameters:
landuse_items (dict) – Dictionary containing service codes or service tags for each land use.
- Returns:
Dictionary with land use categories as keys and sets of unique service tags as values.
- Return type:
dict
- static _intersects(set1, set2) bool [source]
Checks if two sets have any common elements.
- Parameters:
set1 (np.array | list | set) – First collection of elements.
set2 (np.array | list | set) – Second collection of elements.
- Returns:
True if there are common elements, False otherwise.
- Return type:
bool
- static _predict_block_landuse_cosine_similarity(block_vector, landuse_vectors, return_prob=False) str | None [source]
Predicts land use for a block using cosine similarity.
- Parameters:
block_vector (list | np.array) – Collection of booleans representing services present in a block.
landuse_vectors (dict) – Dictionary containing vectors representing services present in each land use.
return_prob (bool, optional) – If True, also returns the probability of the prediction, by default False.
- Returns:
Predicted land use category or None if no prediction is made.
- Return type:
str or None
- _predict_block_landuse(codes_in_block, landuse_items, use_cos_similarity=True)[source]
Predicts the land use for a block.
- Parameters:
codes_in_block (list | np.array) – List of service tags or service codes present in a block.
landuse_items (dict) – Dictionary containing service codes or service tags for each land use.
use_cos_similarity (bool, optional) – Use cosine similarity to predict unpredicted land uses for blocks, by default True.
- Returns:
Predicted land use category or None if no prediction is made.
- Return type:
str or None
- calculate(use_cos_similarity=True)[source]
Calculates the land use prediction for all blocks.
- Parameters:
use_cos_similarity (bool, optional) – Use cosine similarity to predict unpredicted land uses for blocks, by default True.
- Returns:
GeoDataFrame containing the geometries and predicted land use for all blocks.
- Return type:
gpd.GeoDataFrame
- model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.