-
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 three examples to use solara viz
- Loading branch information
Showing
20 changed files
with
167 additions
and
192 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,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
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,46 @@ | ||
import solara | ||
from geo_schelling_points.agents import PersonAgent, RegionAgent | ||
from geo_schelling_points.model import GeoSchellingPoints | ||
from mesa.visualization import Slider, SolaraViz, make_plot_measure | ||
from mesa_geo.visualization import make_geospace_leaflet | ||
|
||
|
||
def make_plot_happiness(model): | ||
return solara.Markdown(f"**Happy agents: {model.happy}**") | ||
|
||
|
||
model_params = { | ||
"red_percentage": Slider("% red", 0.5, 0.00, 1.0, 0.05), | ||
"similarity_threshold": Slider("% similar wanted", 0.5, 0.00, 1.0, 0.05), | ||
} | ||
|
||
|
||
def schelling_draw(agent): | ||
portrayal = {} | ||
if isinstance(agent, RegionAgent): | ||
if agent.red_cnt > agent.blue_cnt: | ||
portrayal["color"] = "Red" | ||
elif agent.red_cnt < agent.blue_cnt: | ||
portrayal["color"] = "Blue" | ||
else: | ||
portrayal["color"] = "Grey" | ||
elif isinstance(agent, PersonAgent): | ||
portrayal["radius"] = 1 | ||
portrayal["shape"] = "circle" | ||
portrayal["color"] = "Red" if agent.is_red else "Blue" | ||
return portrayal | ||
|
||
|
||
model = GeoSchellingPoints() | ||
page = SolaraViz( | ||
model, | ||
[ | ||
make_geospace_leaflet(schelling_draw, zoom=4), | ||
make_plot_happiness, | ||
make_plot_measure(["happy", "unhappy"]), | ||
], | ||
model_params=model_params, | ||
name="GeoSchellingPoints", | ||
) | ||
|
||
page # noqa |
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
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.0a0 |
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,42 @@ | ||
from geo_sir.agents import PersonAgent | ||
from geo_sir.model import GeoSir | ||
from mesa.visualization import Slider, SolaraViz, make_plot_measure | ||
from mesa_geo.visualization import make_geospace_leaflet | ||
|
||
model_params = { | ||
"pop_size": Slider("Population size", 30, 10, 100, 10), | ||
"init_infected": Slider("Fraction initial infection", 0.2, 0.00, 1.0, 0.05), | ||
"exposure_distance": Slider("Exposure distance", 500, 100, 1000, 100), | ||
} | ||
|
||
|
||
def infected_draw(agent): | ||
""" | ||
Portrayal Method for canvas | ||
""" | ||
portrayal = {} | ||
if isinstance(agent, PersonAgent): | ||
portrayal["radius"] = "2" | ||
if agent.atype in ["hotspot", "infected"]: | ||
portrayal["color"] = "Red" | ||
elif agent.atype in ["safe", "susceptible"]: | ||
portrayal["color"] = "Green" | ||
elif agent.atype in ["recovered"]: | ||
portrayal["color"] = "Blue" | ||
elif agent.atype in ["dead"]: | ||
portrayal["color"] = "Black" | ||
return portrayal | ||
|
||
|
||
model = GeoSir() | ||
page = SolaraViz( | ||
model, | ||
[ | ||
make_geospace_leaflet(infected_draw, zoom=12), | ||
make_plot_measure(["infected", "susceptible", "recovered", "dead"]), | ||
], | ||
name="Basic agent-based SIR model", | ||
model_params=model_params, | ||
) | ||
|
||
page # noqa |
Empty file.
File renamed without changes.
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 |
---|---|---|
@@ -1 +1 @@ | ||
mesa-geo~=0.7 | ||
mesa-geo~=0.9.0a0 |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.