-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gis: update four examples to use solara viz
- Loading branch information
Showing
26 changed files
with
277 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import sys | ||
|
||
from mesa.visualization import Slider, SolaraViz, make_plot_measure | ||
from mesa_geo.visualization import make_geospace_leaflet | ||
from src.model.model import AgentsAndNetworks | ||
from src.visualization.utils import agent_draw, make_plot_clock | ||
|
||
|
||
def parse_args(): | ||
campus = "ub" | ||
if "--campus" in sys.argv: | ||
campus = sys.argv[sys.argv.index("--campus") + 1] | ||
return campus | ||
|
||
|
||
if __name__ == "__main__": | ||
campus = parse_args() | ||
|
||
if campus == "ub": | ||
data_file_prefix = "UB" | ||
elif campus == "gmu": | ||
data_file_prefix = "Mason" | ||
else: | ||
raise ValueError("Invalid campus name. Choose from ub or gmu.") | ||
|
||
campus_params = { | ||
"ub": {"data_crs": "epsg:4326", "commuter_speed": 0.5, "zoom": 14}, | ||
"gmu": {"data_crs": "epsg:2283", "commuter_speed": 0.4, "zoom": 16}, | ||
} | ||
model_params = { | ||
"campus": campus, | ||
"data_crs": campus_params[campus]["data_crs"], | ||
"buildings_file": f"data/{campus}/{data_file_prefix}_bld.zip", | ||
"walkway_file": f"data/{campus}/{data_file_prefix}_walkway_line.zip", | ||
"lakes_file": f"data/{campus}/hydrop.zip", | ||
"rivers_file": f"data/{campus}/hydrol.zip", | ||
"driveway_file": f"data/{campus}/{data_file_prefix}_Rds.zip", | ||
"output_dir": "outputs", | ||
"show_walkway": True, | ||
"show_lakes_and_rivers": True, | ||
"show_driveway": True, | ||
"num_commuters": Slider( | ||
"Number of Commuters", value=50, min=10, max=150, step=10 | ||
), | ||
"commuter_speed": Slider( | ||
"Commuter Walking Speed (m/s)", | ||
value=campus_params[campus]["commuter_speed"], | ||
min=0.1, | ||
max=1.5, | ||
step=0.1, | ||
), | ||
} | ||
model = AgentsAndNetworks() | ||
page = SolaraViz( | ||
model, | ||
[make_geospace_leaflet(agent_draw, zoom=campus_params[campus]["zoom"]), | ||
make_plot_clock, | ||
make_plot_measure(["status_home", "status_work", "status_traveling"]), | ||
make_plot_measure(["friendship_home", "friendship_work"]), | ||
], | ||
name="Agents and Networks", | ||
model_params=model_params, | ||
) | ||
|
||
page # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
-e . | ||
|
||
# external requirements | ||
mesa-geo~=0.7 | ||
mesa-geo~=0.9.0a0 | ||
geopandas | ||
numpy | ||
pandas | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import solara | ||
from mesa.visualization import Slider, SolaraViz, make_plot_measure | ||
from mesa_geo.visualization import make_geospace_leaflet | ||
from model import GeoSchelling | ||
|
||
|
||
def make_plot_happiness(model): | ||
return solara.Markdown(f"**Happy agents: {model.happy}**") | ||
|
||
|
||
model_params = { | ||
"density": Slider("Agent density", 0.6, 0.1, 1.0, 0.1), | ||
"minority_pc": Slider("Fraction minority", 0.2, 0.00, 1.0, 0.05), | ||
"export_data": False, | ||
} | ||
|
||
|
||
def schelling_draw(agent): | ||
""" | ||
Portrayal Method for canvas | ||
""" | ||
portrayal = {} | ||
if agent.atype is None: | ||
portrayal["color"] = "Grey" | ||
elif agent.atype == 0: | ||
portrayal["color"] = "Red" | ||
else: | ||
portrayal["color"] = "Blue" | ||
return portrayal | ||
|
||
|
||
model = GeoSchelling() | ||
page = SolaraViz( | ||
model, | ||
[ | ||
make_geospace_leaflet(schelling_draw, zoom=4), | ||
make_plot_happiness, | ||
make_plot_measure(["happy"]), | ||
], | ||
model_params=model_params, | ||
name="GeoSchelling", | ||
) | ||
|
||
page # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
mesa-geo~=0.7 | ||
mesa-geo~=0.9.0a0 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.