Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add basic plotting functions to the library #204

Merged
merged 45 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
8d02735
chore: removed geovoronoi example
RaczeQ Mar 10, 2023
68e8c4f
chore: changed pdm.lock file
RaczeQ Mar 10, 2023
a504078
feat: start working on plotly wrapper function
RaczeQ Mar 10, 2023
3ff0b41
fix(AdministrativeBoundaryRegionizer): add warning
RaczeQ Mar 13, 2023
debe7c3
chore: add constant values usage in tests
RaczeQ Mar 13, 2023
709ef17
feat: modify plotly plotting function
RaczeQ Mar 13, 2023
cbb4ba7
fix(Neighbourhood): change distances calculation
RaczeQ Mar 13, 2023
613b600
feat: add new plot function
RaczeQ Mar 13, 2023
86350b7
feat: add new test for AdministrativeBoundaryRegionizer
RaczeQ Mar 14, 2023
8398cdb
feat: add new neighbourhood tests
RaczeQ Mar 14, 2023
1a25012
feat: add new plotting functions
RaczeQ Mar 14, 2023
32116b3
Merge branch 'main' into 200-add-basic-plotting-functions-to-the-library
RaczeQ Mar 14, 2023
b8fac5c
feat: add new dependencies section
RaczeQ Mar 15, 2023
cfa3b4b
chore: add new flags to isort
RaczeQ Mar 15, 2023
961faf1
chore: modify test notebook
RaczeQ Mar 15, 2023
67e355e
ci: exclude plotting module from coverage
RaczeQ Mar 15, 2023
acfb825
chore: merge remote-tracking branch 'origin/main' into 200-add-basic-…
RaczeQ Mar 21, 2023
5c6aa7b
feat: added plotly and folium functions
RaczeQ Mar 21, 2023
8c4e2d2
feat: added parameter to folium plots
RaczeQ Mar 21, 2023
67ac2f6
feat: modified folium colourscales
RaczeQ Mar 22, 2023
eb6175b
feat: modify voronoi regionizer notebook
RaczeQ Mar 22, 2023
aa69da3
feat: modified regionizers notebooks
RaczeQ Mar 22, 2023
0e770e3
feat: added adjacency neighbourhood example
RaczeQ Mar 22, 2023
4c874ae
Merge branch 'main' into 200-add-basic-plotting-functions-to-the-library
RaczeQ Mar 23, 2023
82e7973
chore: change pdm lock file
RaczeQ Mar 23, 2023
19afefb
fix(AdministrativeBoundaryRegionizer): clipping
RaczeQ Mar 23, 2023
0ed62a5
fix: changes points and polygons clipping
RaczeQ Mar 23, 2023
17a1116
chore: changed docstrings
RaczeQ Mar 23, 2023
70631a9
feat: modified intersection joiner example
RaczeQ Mar 23, 2023
e5a4e56
feat: added new plotting function
RaczeQ Mar 23, 2023
efb771c
chore: added optional imports info to plotting
RaczeQ Mar 23, 2023
63bc240
chore: modify examples to use new plotting module
RaczeQ Mar 23, 2023
0249c44
chore: delete test.ipynb
RaczeQ Mar 23, 2023
8bb96a9
chore: added plotting import test
RaczeQ Mar 26, 2023
2dfa58e
Merge branch 'main' into 200-add-basic-plotting-functions-to-the-library
RaczeQ Mar 26, 2023
3d7fa6a
chore: changed default plotly renderer to None
RaczeQ Mar 26, 2023
9983a01
Merge branch 'main' into 200-add-basic-plotting-functions-to-the-library
RaczeQ Mar 26, 2023
7261993
chore: updated changelog
RaczeQ Mar 26, 2023
55de1f2
Merge branch 'main' into 200-add-basic-plotting-functions-to-the-library
RaczeQ Mar 27, 2023
021e730
chore: apply linter changes
RaczeQ Mar 27, 2023
0bf16aa
chore: update CHANGELOG.md
RaczeQ Mar 27, 2023
ddb8ca6
chore: apply CR suggestions
RaczeQ Mar 27, 2023
be312ab
Merge branch 'main' into 200-add-basic-plotting-functions-to-the-library
RaczeQ Mar 28, 2023
1d32346
chore: apply CR suggestion
RaczeQ Mar 29, 2023
a2a1eea
chore: merge branch '200-add-basic-plotting-functions-to-the-library'…
RaczeQ Mar 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/ci-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: "3.10"
- name: Install required osmium dependencies
run: sudo apt-get install build-essential cmake libboost-dev libexpat1-dev zlib1g-dev libbz2-dev
- uses: actions/cache@v3
Expand All @@ -72,8 +72,6 @@ jobs:
run: pdm export --no-default -G docs -G visualization -f requirements -o requirements.txt
- name: Install dependencies
run: pip install --no-deps -r requirements.txt
- name: Install geovoronoi dependency
run: pip install geovoronoi==0.4.0
- name: Install nbconvert dependency
run: pip install jupyter nbconvert nbformat
- name: Install srai
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/ci-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: "3.10"
- name: Install required osmium dependencies
run: sudo apt-get install build-essential cmake libboost-dev libexpat1-dev zlib1g-dev libbz2-dev
- uses: actions/cache@v3
Expand All @@ -58,8 +58,6 @@ jobs:
run: pdm export --no-default -G docs -G visualization -f requirements -o requirements.txt
- name: Install dependencies
run: pip install --no-deps -r requirements.txt
- name: Install geovoronoi dependency
run: pip install geovoronoi==0.4.0
- name: Install nbconvert dependency
run: pip install jupyter nbconvert nbformat
- name: Install srai
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- H3Neighbourhood
- AdjacencyNeighbourhood
- (CI) Changelog Enforcer
- Utility plotting module based on Folium and Plotly

### Changed

Expand Down
5 changes: 4 additions & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ coverage:
default:
target: auto
informational: true
threshold: 1% # the leniency in hitting the target
threshold: 1% # the leniency in hitting the target
patch:
default:
informational: true

comment:
require_changes: true

ignore:
- "srai/plotting" # disable coverage for plotting module
34 changes: 23 additions & 11 deletions examples/embedders/count_embedder.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
"source": [
"from shapely import geometry\n",
"import geopandas as gpd\n",
"from srai.constants import WGS84_CRS\n",
"from srai.constants import WGS84_CRS, REGIONS_INDEX\n",
"from srai.loaders.osm_loaders import OSMOnlineLoader\n",
"from srai.regionizers import H3Regionizer\n",
"from srai.joiners import IntersectionJoiner\n",
"from srai.embedders import CountEmbedder"
"from srai.embedders import CountEmbedder\n",
"from srai.plotting.folium_wrapper import plot_regions, plot_numeric_data"
]
},
{
Expand Down Expand Up @@ -75,8 +76,8 @@
"source": [
"regionizer = H3Regionizer(resolution=8, buffer=True)\n",
"regions_gdf = regionizer.transform(bbox_gdf)\n",
"ax = bbox_gdf.plot()\n",
"regions_gdf.plot(ax=ax, color=\"red\", alpha=0.5)"
"folium_map = bbox_gdf.explore(tiles=\"CartoDB positron\")\n",
"plot_regions(regions_gdf, map=folium_map)"
]
},
{
Expand Down Expand Up @@ -108,11 +109,8 @@
"metadata": {},
"outputs": [],
"source": [
"ax = regions_gdf.plot()\n",
"features_gdf.plot(\n",
" ax=ax,\n",
" color=\"red\",\n",
")"
"folium_map = plot_regions(regions_gdf, tiles_style=\"CartoDB positron\", colormap=[\"lightgray\"])\n",
"features_gdf.explore(m=folium_map)"
]
},
{
Expand Down Expand Up @@ -140,7 +138,10 @@
"metadata": {},
"outputs": [],
"source": [
"joint_gdf.plot()"
"from plotly.express import colors\n",
"\n",
"folium_map = plot_regions(regions_gdf, tiles_style=\"CartoDB positron\", colormap=[\"rgba(0,0,0,0)\"])\n",
"joint_gdf.reset_index().explore(m=folium_map, column=REGIONS_INDEX, cmap=colors.qualitative.Bold)"
]
},
{
Expand Down Expand Up @@ -181,6 +182,17 @@
"embedding_expected_features"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plot_numeric_data(\n",
" regions_gdf, embedding_expected_features, \"amenity_pub\", tiles_style=\"CartoDB positron\"\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -208,7 +220,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.16"
"version": "3.8.10"
},
"vscode": {
"interpreter": {
Expand Down
28 changes: 17 additions & 11 deletions examples/embedders/gtfs2vec_embedder.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
"metadata": {},
"outputs": [],
"source": [
"from srai.embedders import GTFS2VecEmbedder\n",
"import pandas as pd\n",
"from shapely.geometry import Polygon\n",
"import geopandas as gpd\n",
"from pytorch_lightning import seed_everything"
"from shapely.geometry import Polygon\n",
"from pytorch_lightning import seed_everything\n",
"\n",
"from srai.embedders import GTFS2VecEmbedder\n",
"from srai.constants import REGIONS_INDEX"
]
},
{
Expand Down Expand Up @@ -47,9 +49,8 @@
" ],\n",
" },\n",
" geometry=gpd.points_from_xy([1, 2, 5], [1, 2, 2]),\n",
" index=[1, 2, 3],\n",
" index=pd.Index(name=\"stop_id\", data=[1, 2, 3]),\n",
")\n",
"features_gdf.index.name = \"stop_id\"\n",
"features_gdf"
]
},
Expand All @@ -60,18 +61,23 @@
"outputs": [],
"source": [
"regions_gdf = gpd.GeoDataFrame(\n",
" {\n",
" \"region_id\": [\"ff1\", \"ff2\", \"ff3\"],\n",
" },\n",
" geometry=[\n",
" Polygon([(0, 0), (0, 3), (3, 3), (3, 0)]),\n",
" Polygon([(4, 0), (4, 3), (7, 3), (7, 0)]),\n",
" Polygon([(8, 0), (8, 3), (11, 3), (11, 0)]),\n",
" ],\n",
").set_index(\"region_id\")\n",
" index=pd.Index(name=REGIONS_INDEX, data=[\"ff1\", \"ff2\", \"ff3\"]),\n",
")\n",
"regions_gdf"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -91,7 +97,7 @@
"joint_gdf = gpd.GeoDataFrame()\n",
"joint_gdf.index = pd.MultiIndex.from_tuples(\n",
" [(\"ff1\", 1), (\"ff1\", 2), (\"ff2\", 3)],\n",
" names=[\"region_id\", \"stop_id\"],\n",
" names=[REGIONS_INDEX, \"stop_id\"],\n",
")\n",
"joint_gdf"
]
Expand Down Expand Up @@ -153,7 +159,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.14"
"version": "3.8.10"
},
"vscode": {
"interpreter": {
Expand Down
80 changes: 61 additions & 19 deletions examples/joiners/intersection_joiner.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"source": [
"import geopandas as gpd\n",
"from shapely import geometry\n",
"import matplotlib.pyplot as plt"
"import matplotlib.pyplot as plt\n",
"from srai.constants import WGS84_CRS, REGIONS_INDEX, FEATURES_INDEX\n",
"from srai.plotting.folium_wrapper import plot_regions"
]
},
{
Expand All @@ -32,7 +34,8 @@
" geometry.Polygon([(-2, -1), (-2, -2), (-1, -2), (-1, -1)]),\n",
" geometry.Polygon([(-2, 0.5), (-2, -0.5), (-1, -0.5), (-1, 0.5)]),\n",
" ],\n",
" crs=\"epsg:4326\",\n",
" crs=WGS84_CRS,\n",
" index=gpd.pd.Index(name=REGIONS_INDEX, data=[1, 2, 3, 4]),\n",
")\n",
"\n",
"features = gpd.GeoDataFrame(\n",
Expand All @@ -42,15 +45,41 @@
" geometry.Point((0, 0)),\n",
" geometry.Point((-0.5, -0.5)),\n",
" ],\n",
" crs=\"epsg:4326\",\n",
")\n",
"\n",
"print(regions)\n",
"print(features)\n",
"\n",
"ax = regions.plot()\n",
"features.plot(ax=ax, color=\"red\", alpha=0.5)\n",
"plt.show()"
" crs=WGS84_CRS,\n",
" index=gpd.pd.Index(name=FEATURES_INDEX, data=[1, 2, 3, 4]),\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"regions"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"features"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"folium_map = plot_regions(regions, colormap=[\"royalblue\"])\n",
"features.explore(\n",
" m=folium_map,\n",
" style_kwds=dict(color=\"red\", opacity=0.8, fillColor=\"red\", fillOpacity=0.5),\n",
" marker_kwds=dict(radius=3),\n",
")"
]
},
{
Expand All @@ -72,13 +101,26 @@
"joiner = IntersectionJoiner()\n",
"joint = joiner.transform(regions, features)\n",
"\n",
"print(joint)\n",
"\n",
"ax = regions.plot(alpha=0.3)\n",
"ax = features.plot(ax=ax, color=\"red\", alpha=0.3)\n",
"joint.plot(ax=ax, color=\"green\", alpha=0.5)\n",
"\n",
"plt.show()"
"joint"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"folium_map = plot_regions(regions, colormap=[\"royalblue\"])\n",
"features.explore(\n",
" m=folium_map,\n",
" style_kwds=dict(color=\"red\", opacity=0.5, fillColor=\"red\", fillOpacity=0.5),\n",
" marker_kwds=dict(radius=3),\n",
")\n",
"joint.explore(\n",
" m=folium_map,\n",
" style_kwds=dict(color=\"yellow\", opacity=1.0, fillColor=\"yellow\", fillOpacity=1.0),\n",
" marker_kwds=dict(radius=3),\n",
")"
]
}
],
Expand All @@ -98,7 +140,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.14"
"version": "3.8.10"
},
"vscode": {
"interpreter": {
Expand Down
13 changes: 6 additions & 7 deletions examples/loaders/geoparquet_loader.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
"metadata": {},
"outputs": [],
"source": [
"from pathlib import Path\n",
"\n",
"import geopandas as gpd\n",
"from shapely.geometry import box\n",
"\n",
"from srai.loaders import GeoparquetLoader"
"from srai.loaders import GeoparquetLoader\n",
"from srai.constants import WGS84_CRS"
]
},
{
Expand Down Expand Up @@ -46,7 +45,7 @@
"metadata": {},
"outputs": [],
"source": [
"base_gdf.plot()"
"base_gdf.explore()"
]
},
{
Expand Down Expand Up @@ -79,7 +78,7 @@
"source": [
"# Create Texas bounding box\n",
"bbox = box(minx=-106.645646, maxx=-93.508292, miny=25.837377, maxy=36.500704)\n",
"bbox_gdf = gpd.GeoDataFrame({\"geometry\": [bbox]}, crs=\"EPSG:4326\")\n",
"bbox_gdf = gpd.GeoDataFrame({\"geometry\": [bbox]}, crs=WGS84_CRS)\n",
"\n",
"cut_gdf = gpql.load(file_path=\"example_files/example.parquet\", area=bbox_gdf)\n",
"cut_gdf"
Expand All @@ -91,7 +90,7 @@
"metadata": {},
"outputs": [],
"source": [
"cut_gdf.plot()"
"cut_gdf.explore()"
]
}
],
Expand All @@ -111,7 +110,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.14"
"version": "3.8.10"
},
"vscode": {
"interpreter": {
Expand Down
Loading