Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update make_plot_measure method name from mesa viz #264

Merged
merged 2 commits into from
Nov 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 20 additions & 26 deletions docs/tutorials/intro_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"from shapely.geometry import Point\n",
"\n",
"import mesa\n",
"from mesa.visualization import SolaraViz, make_plot_measure\n",
"from mesa.visualization import SolaraViz, make_plot_component\n",
"import mesa_geo as mg\n",
"from mesa_geo.visualization import make_geospace_leaflet"
]
Expand All @@ -122,7 +122,6 @@
"has_explanation": false
},
"source": [
"\n",
"The first thing we are going to do is create the person agent class. This class has several attributes necessary to make a more holistic model. \n",
"\n",
"First, there are the required attributes for any GeoAgent in Mesa-Geo\n",
Expand All @@ -143,7 +142,7 @@
"\n",
"The **`__repr__`** function is a Python primitive that will print out information as directed by the code. In this case we will print out the agent ID\n",
"\n",
"The **step** function is a Mesa primitive that the scheduler looks for and describes what action the agent takes each step"
"The **step** function is a Mesa primitive that describes what action the agent takes each step"
]
},
{
Expand Down Expand Up @@ -225,7 +224,7 @@
"\n",
"We will also use the **`__repr__`** function to print out the agent ID\n",
"\n",
"Then the **step** function, which is a primitive that the Mesa scheduler looks for and describes what action the agent takes each step"
"Then the **step** function, which is a primitive that describes what action the agent takes each step"
]
},
{
Expand Down Expand Up @@ -287,7 +286,7 @@
"\n",
"**Creating the NeighbourhoodAgents**\n",
"\n",
"In this case we will use the `torontoneighbourhoods.geojson` file located in the data folder to to create the NeighbourhoodAgents. Next, we will add them to the environment with the space.add_agents function. Then we will iterate through each of the NeighbourhoodAgents to add them to the schedule. \n",
"In this case we will use the `torontoneighbourhoods.geojson` file located in the data folder to to create the NeighbourhoodAgents. Next, we will add them to the environment with the space.add_agents function.\n",
"\n",
"\n",
"**Creating the PersonAgents**\n",
Expand All @@ -308,11 +307,11 @@
"\n",
"**Step Function**\n",
"\n",
"The final piece is to initialize a step function. This function a Mesa primitive calls the RandomActiviationByType scheduler we set up and then iterates through each agent calling their step function. \n",
"The final piece is to initialize a step function. This function is a Mesa primitive that iterates through each agent calling their step function.\n",
"\n",
"**The Model**\n",
"\n",
"We know have the pieces of our Model. A GIS layer of polygons that creates NeighbourhoodAgents from our GeoJSON file. A diverse population of GIS Point objects, with different infection, recovery and death risks. A model class that initializes these agents, a scheduler to call these agents, a GIS space and step function to execute the simulation\n"
"We know have the pieces of our Model. A GIS layer of polygons that creates NeighbourhoodAgents from our GeoJSON file. A diverse population of GIS Point objects, with different infection, recovery and death risks. A model class that initializes these agents, a GIS space and step function to execute the simulation"
]
},
{
Expand Down Expand Up @@ -340,7 +339,6 @@
" max_recovery_time=5,\n",
" ):\n",
" super().__init__()\n",
" self.schedule = mesa.time.RandomActivationByType(self)\n",
" self.space = mg.GeoSpace(warn_crs_conversion=False)\n",
"\n",
" # SIR model parameters\n",
Expand All @@ -358,11 +356,7 @@
" # Add neighbourhood agents to space\n",
" self.space.add_agents(neighbourhood_agents)\n",
"\n",
" # Add neighbourhood agents to scheduler\n",
" for agent in neighbourhood_agents:\n",
" self.schedule.add(agent)\n",
"\n",
" # Generate random location, add agent to grid and scheduler\n",
" # Generate random location, add agent to grid\n",
" for i in range(pop_size):\n",
" # assess if they are infected\n",
" if self.random.random() < self.initial_infection:\n",
Expand Down Expand Up @@ -396,7 +390,6 @@
"\n",
" this_person = unique_person.create_agent(Point(x_home, y_home))\n",
" self.space.add_agents(this_person)\n",
" self.schedule.add(this_person)\n",
"\n",
" def find_home(self, neighbourhood_agents):\n",
" \"\"\"Find start location of agent\"\"\"\n",
Expand All @@ -420,7 +413,10 @@
"\n",
" def step(self):\n",
" \"\"\"Run one step of the model.\"\"\"\n",
" self.schedule.step()"
" # Activate PersonAgents in random order\n",
" self.agents_by_type[PersonAgent].shuffle_do(\"step\")\n",
" # For NeighbourhoodAgents the order doesn't matter, since they update independently from each other\n",
" self.agents_by_type[NeighbourhoodAgent].do(\"step\")"
]
},
{
Expand Down Expand Up @@ -766,8 +762,6 @@
" max_recovery_time=5,\n",
" ):\n",
" super().__init__()\n",
" # Scheduler\n",
" self.schedule = mesa.time.RandomActivationByType(self)\n",
" # Space\n",
" self.space = mg.GeoSpace(warn_crs_conversion=False)\n",
" # Data Collection\n",
Expand Down Expand Up @@ -801,11 +795,7 @@
" # Add neighbourhood agents to space\n",
" self.space.add_agents(neighbourhood_agents)\n",
"\n",
" # Add neighbourhood agents to scheduler\n",
" for agent in neighbourhood_agents:\n",
" self.schedule.add(agent)\n",
"\n",
" # Generate random location, add agent to grid and scheduler\n",
" # Generate random location, add agent to grid\n",
" for i in range(pop_size):\n",
" # assess if they are infected\n",
" if self.random.random() < self.initial_infection:\n",
Expand Down Expand Up @@ -839,7 +829,6 @@
"\n",
" this_person = unique_person.create_agent(Point(x_home, y_home))\n",
" self.space.add_agents(this_person)\n",
" self.schedule.add(this_person)\n",
"\n",
" def find_home(self, neighbourhood_agents):\n",
" \"\"\"Find start location of agent\"\"\"\n",
Expand Down Expand Up @@ -876,7 +865,12 @@
" \"\"\"Run one step of the model.\"\"\"\n",
"\n",
" self.reset_counts() # added\n",
" self.schedule.step()\n",
" \n",
" # Activate PersonAgents in random order\n",
" self.agents_by_type[PersonAgent].shuffle_do(\"step\")\n",
" # For NeighbourhoodAgents the order doesn't matter, since they update independently from each other\n",
" self.agents_by_type[NeighbourhoodAgent].do(\"step\")\n",
" \n",
" self.datacollector.collect(self) # added\n",
"\n",
" # Run until no one is infected\n",
Expand Down Expand Up @@ -1067,8 +1061,8 @@
" model_params=model_params,\n",
" components=[\n",
" make_geospace_leaflet(SIR_draw, zoom=12, scroll_wheel_zoom=False),\n",
" make_plot_measure([\"infected\", \"susceptible\", \"recovered\", \"dead\"]),\n",
" make_plot_measure([\"safe\", \"hotspot\"]),\n",
" make_plot_component([\"infected\", \"susceptible\", \"recovered\", \"dead\"]),\n",
" make_plot_component([\"safe\", \"hotspot\"]),\n",
" ],\n",
")\n",
"# This is required to render the visualization in the Jupyter notebook\n",
Expand Down
Loading