From e962521f71694065b66bcd93e3c587617f19ac3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Le=C5=9Bniara?= Date: Mon, 27 Mar 2023 19:25:40 +0200 Subject: [PATCH 1/3] docs: add missing link to Highway2VecEmbedder (#214) --- examples/embedders/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/embedders/README.md b/examples/embedders/README.md index be85ff88..6fa3de50 100644 --- a/examples/embedders/README.md +++ b/examples/embedders/README.md @@ -4,3 +4,4 @@ Examples illustrating the usage of every Joiner. - [CountEmbedder](count_embedder.ipynb) - [GTFS2VecEmbedder](gtfs2vec_embedder.ipynb) +- [Highway2VecEmbedder](highway2vec_embedder.ipynb) From 0bf16aada27aa7f6ec5db0e95ddea4e6bae10071 Mon Sep 17 00:00:00 2001 From: Kamil Raczycki Date: Tue, 28 Mar 2023 00:16:15 +0200 Subject: [PATCH 2/3] chore: update CHANGELOG.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kacper Leśniara --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e0baca5..5086cfaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - H3Neighbourhood - AdjacencyNeighbourhood - (CI) Changelog Enforcer -- Utility plotting module base on Folium and Plotly +- Utility plotting module based on Folium and Plotly ### Changed From ddb8ca686055d5bacd46a93552c2b4189b10a0c2 Mon Sep 17 00:00:00 2001 From: Kamil Raczycki Date: Tue, 28 Mar 2023 00:40:15 +0200 Subject: [PATCH 3/3] chore: apply CR suggestions --- srai/plotting/folium_wrapper.py | 25 +++++++++++++------ srai/plotting/plotly_wrapper.py | 6 ++++- .../administrative_boundary_regionizer.py | 4 +-- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/srai/plotting/folium_wrapper.py b/srai/plotting/folium_wrapper.py index c3f247d6..717549e3 100644 --- a/srai/plotting/folium_wrapper.py +++ b/srai/plotting/folium_wrapper.py @@ -38,7 +38,9 @@ def plot_regions( Args: regions_gdf (gpd.GeoDataFrame): Region indexes and geometries to plot. - tiles_style (str, optional): Map style background. Defaults to "OpenStreetMap". + tiles_style (str, optional): Map style background. For more styles, look at tiles param at + https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoDataFrame.explore.html. + Defaults to "OpenStreetMap". height (Union[str, float], optional): Height of the plot. Defaults to "100%". width (Union[str, float], optional): Width of the plot. Defaults to "100%". colormap (Union[str, List[str]], optional): Colormap to apply to the regions. @@ -49,8 +51,7 @@ def plot_regions( Returns: folium.Map: Generated map. """ - regions_gdf_copy = regions_gdf.copy() - return regions_gdf_copy.reset_index().explore( + return regions_gdf.reset_index().explore( column=REGIONS_INDEX, tooltip=REGIONS_INDEX, tiles=tiles_style, @@ -82,7 +83,9 @@ def plot_numeric_data( embedding_df (Union[pd.DataFrame, gpd.GeoDataFrame]): Region indexes and numerical data to plot. data_column (str): Name of the column used to colour the regions. - tiles_style (str, optional): Map style background. Defaults to "OpenStreetMap". + tiles_style (str, optional): Map style background. For more styles, look at tiles param at + https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoDataFrame.explore.html. + Defaults to "OpenStreetMap". height (Union[str, float], optional): Height of the plot. Defaults to "100%". width (Union[str, float], optional): Width of the plot. Defaults to "100%". colormap (Union[str, List[str]], optional): Colormap to apply to the regions. @@ -133,7 +136,9 @@ def plot_neighbours( regions_gdf (gpd.GeoDataFrame): Region indexes and geometries to plot. region_id (IndexType): Center `region_id` around which the neighbourhood should be plotted. neighbours_ids (Set[IndexType]): List of neighbours to highlight. - tiles_style (str, optional): Map style background. Defaults to "OpenStreetMap". + tiles_style (str, optional): Map style background. For more styles, look at tiles param at + https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoDataFrame.explore.html. + Defaults to "OpenStreetMap". height (Union[str, float], optional): Height of the plot. Defaults to "100%". width (Union[str, float], optional): Width of the plot. Defaults to "100%". map (folium.Map, optional): Existing map instance on which to draw the plot. @@ -171,6 +176,7 @@ def plot_all_neighbourhood( regions_gdf: gpd.GeoDataFrame, region_id: IndexType, neighbourhood: Neighbourhood[IndexType], + neighbourhood_max_distance: int = 100, tiles_style: str = "OpenStreetMap", height: Union[str, float] = "100%", width: Union[str, float] = "100%", @@ -185,7 +191,12 @@ def plot_all_neighbourhood( region_id (IndexType): Center `region_id` around which the neighbourhood should be plotted. neighbourhood (Neighbourhood[IndexType]): `Neighbourhood` class required for finding neighbours. - tiles_style (str, optional): Map style background. Defaults to "OpenStreetMap". + neighbourhood_max_distance (int, optional): Max distance for rendering neighbourhoods. + Neighbours farther away won't be coloured, and will be left as "other" regions. + Defaults to 100. + tiles_style (str, optional): Map style background. For more styles, look at tiles param at + https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoDataFrame.explore.html. + Defaults to "OpenStreetMap". height (Union[str, float], optional): Height of the plot. Defaults to "100%". width (Union[str, float], optional): Width of the plot. Defaults to "100%". colormap (Union[str, List[str]], optional): Colormap to apply to the neighbourhoods. @@ -207,7 +218,7 @@ def plot_all_neighbourhood( neighbours_ids = neighbourhood.get_neighbours_at_distance(region_id, distance).intersection( regions_gdf.index ) - while neighbours_ids: + while neighbours_ids and distance <= neighbourhood_max_distance: regions_gdf_copy.loc[list(neighbours_ids), "region"] = distance distance += 1 neighbours_ids = neighbourhood.get_neighbours_at_distance(region_id, distance).intersection( diff --git a/srai/plotting/plotly_wrapper.py b/srai/plotting/plotly_wrapper.py index 57337a97..7cc73c79 100644 --- a/srai/plotting/plotly_wrapper.py +++ b/srai/plotting/plotly_wrapper.py @@ -147,6 +147,7 @@ def plot_all_neighbourhood( regions_gdf: gpd.GeoDataFrame, region_id: IndexType, neighbourhood: Neighbourhood[IndexType], + neighbourhood_max_distance: int = 100, return_plot: bool = False, mapbox_style: str = "open-street-map", mapbox_accesstoken: Optional[str] = None, @@ -165,6 +166,9 @@ def plot_all_neighbourhood( region_id (IndexType): Center `region_id` around which the neighbourhood should be plotted. neighbourhood (Neighbourhood[IndexType]): `Neighbourhood` class required for finding neighbours. + neighbourhood_max_distance (int, optional): Max distance for rendering neighbourhoods. + Neighbours farther away won't be coloured, and will be left as "other" regions. + Defaults to 100. return_plot (bool, optional): Flag whether to return the Figure object or not. If `True`, the plot won't be displayed automatically. Defaults to False. mapbox_style (str, optional): Map style background. Defaults to "open-street-map". @@ -190,7 +194,7 @@ def plot_all_neighbourhood( neighbours_ids = neighbourhood.get_neighbours_at_distance(region_id, distance).intersection( regions_gdf.index ) - while neighbours_ids: + while neighbours_ids and distance <= neighbourhood_max_distance: regions_gdf_copy.loc[list(neighbours_ids), "region"] = distance distance += 1 neighbours_ids = neighbourhood.get_neighbours_at_distance(region_id, distance).intersection( diff --git a/srai/regionizers/administrative_boundary_regionizer.py b/srai/regionizers/administrative_boundary_regionizer.py index d681d9db..e2b749d3 100644 --- a/srai/regionizers/administrative_boundary_regionizer.py +++ b/srai/regionizers/administrative_boundary_regionizer.py @@ -168,8 +168,8 @@ def transform(self, gdf: gpd.GeoDataFrame) -> gpd.GeoDataFrame: regions_to_keep = [ region_id for region_id, row in regions_gdf.iterrows() - if self._check_intersects_with_points(row["geometry"]) - or self._calculate_intersection_area_fraction(row["geometry"]) > 0.01 + if self._check_intersects_with_points(row[GEOMETRY_COLUMN]) + or self._calculate_intersection_area_fraction(row[GEOMETRY_COLUMN]) > 0.01 ] regions_gdf = regions_gdf.loc[regions_to_keep]