Index
This module contains neighbourhood calculation methods.
Some embedding methods require a neighbourhood to be defined. This module contains neighbourhood calculation methods - both dedicated to a specific regionalization method and general ones.
¶
Bases: ABC
, Generic[IndexType]
Neighbourhood interface.
This class abstracts away getting the neighbours of a region. It allows to get the neighbours at a certain distance or up to a certain distance. It is worth noting, that the distance here is not a metric distance, but a number of hops. This definition makes most sense semantically for grid systems such as H3 or S2 but should work for arbitrary neighbourhoods as well.
The subclasses only need to implement the get_neighbours
method, but can also override the
get_neighbours_up_to_distance
and get_neighbours_at_distance
methods for performance
reasons. See the H3Neighbourhood
class for an example. The class also provides a
_handle_center
method, which can be used to handle including/excluding the center region.
PARAMETER | DESCRIPTION |
---|---|
include_center |
Whether to include the region itself in the neighbours.
TYPE:
|
Source code in srai/neighbourhoods/_base.py
¶
abstractmethod
Get the direct neighbours of a region using its index.
PARAMETER | DESCRIPTION |
---|---|
index |
Unique identifier of the region. Dependant on the implementation.
TYPE:
|
include_center |
Whether to include the region itself in the neighbours.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
set[IndexType]
|
Set[IndexType]: Indexes of the neighbours. |
Source code in srai/neighbourhoods/_base.py
¶
Get the neighbours of a region up to a certain distance.
PARAMETER | DESCRIPTION |
---|---|
index |
Unique identifier of the region. Dependant on the implementation.
TYPE:
|
distance |
Maximum distance to the neighbours.
TYPE:
|
include_center |
Whether to include the region itself in the neighbours.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
set[IndexType]
|
Set[IndexType]: Indexes of the neighbours. |
Source code in srai/neighbourhoods/_base.py
¶
Get the neighbours of a region at a certain distance.
PARAMETER | DESCRIPTION |
---|---|
index |
Unique identifier of the region. Dependant on the implementation.
TYPE:
|
distance |
Distance to the neighbours.
TYPE:
|
include_center |
Whether to include the region itself in the neighbours.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
set[IndexType]
|
Set[IndexType]: Indexes of the neighbours. |
Source code in srai/neighbourhoods/_base.py
¶
Bases: Neighbourhood[Hashable]
Adjacency Neighbourhood.
This class allows to get the neighbours of any region based on common border. Additionally, a lookup table is implemented to accelerate repeated queries.
By default, a lookup table will be populated lazily based on queries. A dedicated function
generate_neighbourhoods
allows for precalculation of all the neighbourhoods at once.
PARAMETER | DESCRIPTION |
---|---|
regions_gdf |
regions for which a neighbourhood will be calculated.
TYPE:
|
include_center |
Whether to include the region itself in the neighbours.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If regions_gdf doesn't have geometry column. |
Source code in srai/neighbourhoods/adjacency_neighbourhood.py
¶
Get the neighbours of a region up to a certain distance.
PARAMETER | DESCRIPTION |
---|---|
index |
Unique identifier of the region. Dependant on the implementation.
TYPE:
|
distance |
Maximum distance to the neighbours.
TYPE:
|
include_center |
Whether to include the region itself in the neighbours.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
set[IndexType]
|
Set[IndexType]: Indexes of the neighbours. |
Source code in srai/neighbourhoods/_base.py
¶
Get the neighbours of a region at a certain distance.
PARAMETER | DESCRIPTION |
---|---|
index |
Unique identifier of the region. Dependant on the implementation.
TYPE:
|
distance |
Distance to the neighbours.
TYPE:
|
include_center |
Whether to include the region itself in the neighbours.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
set[IndexType]
|
Set[IndexType]: Indexes of the neighbours. |
Source code in srai/neighbourhoods/_base.py
¶
Generate the lookup table for all regions.
Source code in srai/neighbourhoods/adjacency_neighbourhood.py
¶
Get the direct neighbours of any region using its index.
PARAMETER | DESCRIPTION |
---|---|
index |
Unique identifier of the region.
TYPE:
|
include_center |
Whether to include the region itself in the neighbours.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
set[Hashable]
|
Set[Hashable]: Indexes of the neighbours. |
Source code in srai/neighbourhoods/adjacency_neighbourhood.py
¶
Bases: Neighbourhood[str]
H3 Neighbourhood.
This class allows to get the neighbours of an H3 region.
If a regions GeoDataFrame is provided, only the neighbours that are in the regions GeoDataFrame will be returned by the methods of this instance. NOTICE: If a region is a part of the k-th ring of a region and is included in the GeoDataFrame, it will be returned by get_neighbours_at_distance method with distance k even when there is no path of length k between the two regions.
PARAMETER | DESCRIPTION |
---|---|
regions_gdf |
The regions that are being analyzed. The H3Neighbourhood will only look for neighbours among these regions. Defaults to None.
TYPE:
|
include_center |
Whether to include the region itself in the neighbours.
TYPE:
|
Source code in srai/neighbourhoods/h3_neighbourhood.py
¶
Get the direct neighbours of an H3 region using its index.
PARAMETER | DESCRIPTION |
---|---|
index |
H3 index of the region.
TYPE:
|
include_center |
Whether to include the region itself in the neighbours.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
set[str]
|
Set[str]: Indexes of the neighbours. |
Source code in srai/neighbourhoods/h3_neighbourhood.py
¶
Get the neighbours of an H3 region up to a certain distance.
PARAMETER | DESCRIPTION |
---|---|
index |
H3 index of the region.
TYPE:
|
distance |
Distance to the neighbours.
TYPE:
|
include_center |
Whether to include the region itself in the neighbours. If None, the value set in init is used. Defaults to None.
TYPE:
|
unchecked |
Whether to check if the neighbours are in the available indices.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
set[str]
|
Set[str]: Indexes of the neighbours up to the given distance. |
Source code in srai/neighbourhoods/h3_neighbourhood.py
¶
Get the neighbours of an H3 region at a certain distance.
PARAMETER | DESCRIPTION |
---|---|
index |
H3 index of the region.
TYPE:
|
distance |
Distance to the neighbours.
TYPE:
|
include_center |
Whether to include the region itself in the neighbours.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
set[str]
|
Set[str]: Indexes of the neighbours at the given distance. |