Skip to content

Commit

Permalink
update gis schelling to account for mesa-geo updates
Browse files Browse the repository at this point in the history
  • Loading branch information
tpike3 committed Apr 9, 2024
1 parent 5be7b9c commit 5fec771
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def __init__(self, portrayal_method=None, canvas_height=500, canvas_width=500):
self.portrayal_method = portrayal_method
self.canvas_height = canvas_height
self.canvas_width = canvas_width
new_element = "new Simple_Continuous_Module({}, {})".format(
self.canvas_width, self.canvas_height
new_element = (
f"new Simple_Continuous_Module({self.canvas_width}, {self.canvas_height})"
)
self.js_code = "elements.push(" + new_element + ");"

Expand Down
4 changes: 1 addition & 3 deletions examples/virus_on_network/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ def get_resistant_susceptible_ratio(model):
ratio_text = r"$\infty$" if ratio is math.inf else f"{ratio:.2f}"
infected_text = str(number_infected(model))

return "Resistant/Susceptible Ratio: {}<br>Infected Remaining: {}".format(
ratio_text, infected_text
)
return f"Resistant/Susceptible Ratio: {ratio_text}<br>Infected Remaining: {infected_text}"


def make_plot(model):
Expand Down
4 changes: 1 addition & 3 deletions examples/virus_on_network/virus_on_network/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ def get_resistant_susceptible_ratio(model):
ratio_text = "&infin;" if ratio is math.inf else f"{ratio:.2f}"
infected_text = str(number_infected(model))

return "Resistant/Susceptible Ratio: {}<br>Infected Remaining: {}".format(
ratio_text, infected_text
)
return f"Resistant/Susceptible Ratio: {ratio_text}<br>Infected Remaining: {infected_text}"


model_params = {
Expand Down
75 changes: 57 additions & 18 deletions gis/geo_schelling_experimental/GIS_Schelling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,31 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "4f31395d-09c3-4479-8147-0dff9499cd71",
"metadata": {},
"execution_count": 1,
"id": "37528711-4873-42e7-be7f-926130026dd8",
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"outputs": [],
"source": [
"import random\n",
"\n",
"import mesa\n",
"import mesa_geo as mg\n",
"import mesa_geo.geoexperimental as mge\n",
"import geopandas as gpd\n",
"import ipyleaflet\n",
"import xyzservices.providers as xyz"
"import mesa_geo.geoexperimental as mge"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "27cac12c-515e-4ef4-83cc-d06918921c70",
"metadata": {},
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"outputs": [],
"source": [
"class SchellingAgent(mg.GeoAgent):\n",
Expand Down Expand Up @@ -70,9 +75,13 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "9c9a9738-7e8f-458c-b0aa-cfc69c04ee87",
"metadata": {},
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"outputs": [],
"source": [
"class GeoSchelling(mesa.Model):\n",
Expand Down Expand Up @@ -130,9 +139,13 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"id": "0bf74b4c-36ab-416c-a4db-ab5104189d92",
"metadata": {},
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"outputs": [],
"source": [
"def schelling_draw(agent):\n",
Expand Down Expand Up @@ -177,12 +190,34 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"id": "c8a2533e-95ba-4a2b-b21a-56e05fe3b7b2",
"metadata": {},
"outputs": [],
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d4853c72527245678d5cb9d38d4a15ec",
"version_major": 2,
"version_minor": 0
},
"text/html": [
"Cannot show widget. You probably want to rerun the code cell above (<i>Click in the code cell, and press Shift+Enter <kbd>⇧</kbd>+<kbd>↩</kbd></i>)."
],
"text/plain": [
"Cannot show ipywidgets in text"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"page = mge.JupyterViz(\n",
"page = mge.GeoJupyterViz(\n",
" GeoSchelling,\n",
" model_params,\n",
" measures=[\"happy\"],\n",
Expand All @@ -199,7 +234,11 @@
"cell_type": "code",
"execution_count": null,
"id": "eb7fbf17-30a9-4c02-a2b8-c211ab16d32b",
"metadata": {},
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"outputs": [],
"source": []
}
Expand Down
12 changes: 1 addition & 11 deletions gis/geo_schelling_experimental/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@ def __init__(self):
def render(self, model):
return "Happy agents: " + str(model.happy)


"""
model_params = {
"density": mesa.visualization.Slider("Agent density", 0.6, 0.1, 1.0, 0.1),
"minority_pc": mesa.visualization.Slider("Fraction minority", 0.2, 0.00, 1.0, 0.05),
"export_data": mesa.visualization.Checkbox("Export data after simulation", False),
}
"""


def schelling_draw(agent):
"""
Portrayal Method for canvas
Expand Down Expand Up @@ -63,7 +53,7 @@ def schelling_draw(agent):
},
}

page = mge.JupyterViz(
page = mge.GeoJupyterViz(
GeoSchelling,
model_params,
measures=["happy"],
Expand Down

0 comments on commit 5fec771

Please sign in to comment.