AdjacencyCalculator
todo
This module provides all necessary tools to get accesibility matrix from transport graph
- class blocksnet.preprocessing.adjacency_calculator.BlockRow(*, geometry: Polygon, index: int)[source]
Bases:
BaseRow- geometry: Polygon
- class blocksnet.preprocessing.adjacency_calculator.AdjacencyCalculator(*, blocks: GeoDataFrame[BlockRow], graph: MultiDiGraph)[source]
Bases:
BaseModelClass Accessibility calculates accessibility matrix between city blocks. It takes a lot of RAM to calculate one since we have thousands of city blocks.
Methods
get_matrix
- blocks: GeoDataFrame[BlockRow]
- graph: MultiDiGraph
- static _get_nx2nk_idmap(graph: Graph) dict[source]
This method gets ids from nx graph to place as attribute in nk graph
Attributes
graph: networkx graph
Returns
- idmap: dict
map of old and new ids
- static _get_nk_attrs(graph: Graph) dict[source]
This method gets attributes from nx graph to set as attributes in nk graph
Attributes
graph: networkx graph
Returns
- idmap: dict
map of old and new attributes
- classmethod _convert_nx2nk(graph_nx: MultiDiGraph, idmap: dict | None = None, weight: str = 'weight') Graph[source]
This method converts networkx graph to networkit graph to fasten calculations.
Attributes
graph_nx: networkx graph idmap: dict
map of ids in old nx and new nk graphs
- weight: str
value to be used as a edge’s weight
Returns
- graph_nk: nk.Graph
the same graph but now presented in is networkit package Graph class.
- _get_nk_distances(nk_dists: Algorithm, loc: Series) Series[source]
This method calculates distances between blocks using nk SPSP algorithm. The function is called inside apply function.
Attributes
- nk_dists: nk.base.Algorithm
Compressed nk graph to compute distances between nodes using SPSP algorithm
- loc: pd.Series
Row in the df
Returns
pd.Series with computed distances