Skip to content

Commit

Permalink
feat: weighted connectivity mock
Browse files Browse the repository at this point in the history
  • Loading branch information
vasilstar97 committed Dec 5, 2024
1 parent 2dd9dee commit 3977ff6
Show file tree
Hide file tree
Showing 5 changed files with 281 additions and 0 deletions.
1 change: 1 addition & 0 deletions blocksnet/method/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
from .provision import *
from .spacematrix import *
from .vacant_area import *
from .weighted_connectivity import WeightedConnectivity
58 changes: 58 additions & 0 deletions blocksnet/method/weighted_connectivity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import geopandas as gpd
from .base_method import BaseMethod

CONNECTIVITY_COLUMN = "connectivity"

PLOT_KWARGS = {
"column": CONNECTIVITY_COLUMN,
"legend": True,
"cmap": "cool",
}


class WeightedConnectivity(BaseMethod):
"""
Provides methods for block connectivity assessment taking into account population and services within urban blocks.
Methods
-------
plot(gdf, linewidth=0.1, figsize=(10, 10))
Plots connectivity data on a map.
calculate()
Calculates connectivity for all blocks in the city model.
"""

@staticmethod
def plot(gdf: gpd.GeoDataFrame, linewidth: float = 0.1, figsize: tuple[int, int] = (10, 10)):
"""
Plots connectivity data for blocks on a map.
Parameters
----------
gdf : geopandas.GeoDataFrame
GeoDataFrame containing block geometries and connectivity data.
linewidth : float, optional
Line width for plotting the geometries, by default 0.1.
figsize : tuple of int, optional
Size of the figure to plot, by default (10, 10).
Returns
-------
None
"""
gdf.plot(linewidth=linewidth, figsize=figsize, **PLOT_KWARGS).set_axis_off()

def calculate(self) -> gpd.GeoDataFrame:
"""
Calculates weighted connectivity for all blocks in the city model.
Connectivity is determined by the median value of the accessibility matrix row for each block.
Returns
-------
geopandas.GeoDataFrame
GeoDataFrame containing blocks with calculated connectivity.
"""
blocks_gdf = self.city_model.get_blocks_gdf()[["geometry"]]
blocks_gdf[CONNECTIVITY_COLUMN] = self.city_model.accessibility_matrix.median(axis=1)
return blocks_gdf
1 change: 1 addition & 0 deletions docs/source/examples/methods/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The examples of how to operate the `City` model to perform certain analytics.

accessibility
connectivity
weighted_connectivity
diversity
centrality
spacematrix
Expand Down
3 changes: 3 additions & 0 deletions docs/source/examples/methods/weighted_connectivity.nblink
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"path": "../../../../examples/methods/weighted_connectivity.ipynb"
}
218 changes: 218 additions & 0 deletions examples/methods/weighted_connectivity.ipynb

Large diffs are not rendered by default.

0 comments on commit 3977ff6

Please sign in to comment.