forked from projectmesa/mesa-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gis: update three examples to use solara viz (projectmesa#226)
This PR updates the remaining three gis examples to use Solara viz, partly addressing projectmesa#154. It depends on projectmesa/mesa-geo#254 to be released, as these examples use raster layers. Also made some small adjustments in ordering components to account for the grid layout, instead of the previous column layout in Solara viz.
- Loading branch information
Showing
19 changed files
with
125 additions
and
151 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
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
Empty file.
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.0a1 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from typing import Tuple | ||
|
||
from mesa.visualization import Slider, SolaraViz, make_plot_measure | ||
from mesa_geo.visualization import make_geospace_leaflet | ||
from rainfall.model import Rainfall | ||
from rainfall.space import LakeCell | ||
|
||
model_params = { | ||
"rain_rate": Slider("rain rate", 500, 0, 500, 5), | ||
"water_height": Slider("water height", 5, 1, 5, 1), | ||
"num_steps": Slider("total number of steps", 20, 1, 100, 1), | ||
"export_data": False, | ||
} | ||
|
||
|
||
def cell_portrayal(cell: LakeCell) -> Tuple[float, float, float, float]: | ||
if cell.water_level == 0: | ||
return cell.elevation, cell.elevation, cell.elevation, 1 | ||
else: | ||
# return a blue color gradient based on the normalized water level | ||
# from the lowest water level colored as RGBA: (74, 141, 255, 1) | ||
# to the highest water level colored as RGBA: (0, 0, 255, 1) | ||
return ( | ||
(1 - cell.water_level_normalized) * 74, | ||
(1 - cell.water_level_normalized) * 141, | ||
255, | ||
1, | ||
) | ||
|
||
|
||
model = Rainfall() | ||
page = SolaraViz( | ||
model, | ||
[ | ||
make_geospace_leaflet(cell_portrayal, zoom=11), | ||
make_plot_measure( | ||
["Total Amount of Water", "Total Contained", "Total Outflow"] | ||
), | ||
], | ||
name="Rainfall Model", | ||
model_params=model_params, | ||
) | ||
|
||
page # noqa |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
mesa-geo~=0.7 | ||
mesa-geo~=0.9.0a1 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from typing import Tuple | ||
|
||
import solara | ||
from mesa.visualization import Slider, SolaraViz, make_plot_measure | ||
from mesa_geo.visualization import make_geospace_leaflet | ||
from urban_growth.model import UrbanGrowth | ||
from urban_growth.space import UrbanCell | ||
|
||
|
||
def cell_portrayal(cell: UrbanCell) -> Tuple[float, float, float, float]: | ||
if cell.urban: | ||
if cell.old_urbanized: | ||
return 0, 0, 255, 1 | ||
else: | ||
return 255, 0, 0, 1 | ||
else: | ||
return 0, 0, 0, 0 | ||
|
||
|
||
def make_plot_urbanized(model): | ||
return solara.Markdown(f"**Percentage Urbanized: {model.pct_urbanized:.2f}%**") | ||
|
||
|
||
model_params = { | ||
"max_coefficient": 100, | ||
"dispersion_coefficient": Slider("dispersion_coefficient", 20, 0, 100, 1), | ||
"spread_coefficient": Slider("spread_coefficient", 27, 0, 100, 1), | ||
"breed_coefficient": Slider("breed_coefficient", 5, 0, 100, 1), | ||
"rg_coefficient": Slider("rg_coefficient", 10, 0, 100, 1), | ||
"slope_coefficient": Slider("slope_coefficient", 50, 0, 100, 1), | ||
"critical_slope": Slider("critical_slope", 25, 0, 100, 1), | ||
"road_influence": False, | ||
} | ||
|
||
model = UrbanGrowth() | ||
page = SolaraViz( | ||
model, | ||
[ | ||
make_geospace_leaflet(cell_portrayal, zoom=12.1), | ||
make_plot_measure(["Percentage Urbanized"]), | ||
make_plot_urbanized, | ||
], | ||
name="Urban Growth Model", | ||
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 |
---|---|---|
@@ -1 +1 @@ | ||
mesa-geo~=0.7 | ||
mesa-geo~=0.9.0a1 |
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.