Skip to content

Commit

Permalink
rename make_geospace_leaflet to make_geospace_component
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-boyu committed Dec 25, 2024
1 parent 92c869a commit 5436194
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
4 changes: 2 additions & 2 deletions docs/tutorials/intro_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"import mesa\n",
"from mesa.visualization import SolaraViz, make_plot_component\n",
"import mesa_geo as mg\n",
"from mesa_geo.visualization import make_geospace_leaflet"
"from mesa_geo.visualization import make_geospace_component"
]
},
{
Expand Down Expand Up @@ -1060,7 +1060,7 @@
" name=\"GeoSIR\",\n",
" model_params=model_params,\n",
" components=[\n",
" make_geospace_leaflet(SIR_draw, zoom=12, scroll_wheel_zoom=False),\n",
" make_geospace_component(SIR_draw, zoom=12, scroll_wheel_zoom=False),\n",
" make_plot_component([\"infected\", \"susceptible\", \"recovered\", \"dead\"]),\n",
" make_plot_component([\"safe\", \"hotspot\"]),\n",
" ],\n",
Expand Down
14 changes: 12 additions & 2 deletions mesa_geo/visualization/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Import specific classes or functions from the modules
from .components.geospace_leaflet import MapModule, make_geospace_leaflet
from .components.geospace_component import (
MapModule,
make_geospace_component,
make_geospace_leaflet,
)
from .geojupyter_viz import GeoJupyterViz
from .leaflet_viz import LeafletViz

__all__ = ["GeoJupyterViz", "LeafletViz", "MapModule", "make_geospace_leaflet"]
__all__ = [
"GeoJupyterViz",
"LeafletViz",
"MapModule",
"make_geospace_component",
"make_geospace_leaflet",
]
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import dataclasses
import warnings
from dataclasses import dataclass

import geopandas as gpd
Expand All @@ -18,6 +19,20 @@ def make_geospace_leaflet(
view=None,
tiles=xyzservices.providers.OpenStreetMap.Mapnik,
**kwargs,
):
warnings.warn(
"make_geospace_leaflet is deprecated, use make_geospace_component instead",
DeprecationWarning,
stacklevel=2,
)
return make_geospace_component(agent_portrayal, view, tiles, **kwargs)


def make_geospace_component(
agent_portrayal,
view=None,
tiles=xyzservices.providers.OpenStreetMap.Mapnik,
**kwargs,
):
def MakeSpaceMatplotlib(model):
return GeoSpaceLeaflet(model, agent_portrayal, view, tiles, **kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
from mesa.visualization.solara_viz import SolaraViz

import mesa_geo.visualization as mgv
from mesa_geo.visualization import make_geospace_leaflet
from mesa_geo.visualization import make_geospace_component


def test_geospace_leaflet(mocker):
mock_geospace_leaflet = mocker.spy(
mgv.components.geospace_leaflet, "GeoSpaceLeaflet"
def test_geospace_component(mocker):
mock_geospace_component = mocker.spy(
mgv.components.geospace_component, "GeoSpaceLeaflet"
)

model = mesa.Model()
Expand All @@ -22,8 +22,10 @@ def test_geospace_leaflet(mocker):
}
# initialize with space drawer unspecified (use default)
# component must be rendered for code to run
solara.render(SolaraViz(model, components=[make_geospace_leaflet(agent_portrayal)]))
solara.render(
SolaraViz(model, components=[make_geospace_component(agent_portrayal)])
)
# should call default method with class instance and agent portrayal
mock_geospace_leaflet.assert_called_with(
mock_geospace_component.assert_called_with(
model, agent_portrayal, None, xyzservices.providers.OpenStreetMap.Mapnik
)

0 comments on commit 5436194

Please sign in to comment.