From 9b9719b40f9328796aba523607d470439086b7df Mon Sep 17 00:00:00 2001 From: Ewout ter Hoeven Date: Wed, 25 Sep 2024 20:05:17 +0200 Subject: [PATCH] intro tutorial: Remove unique_id from Agent init --- docs/tutorials/intro_tutorial.ipynb | 31 ++++++++++++----------------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/docs/tutorials/intro_tutorial.ipynb b/docs/tutorials/intro_tutorial.ipynb index 4471284d..d430a55a 100644 --- a/docs/tutorials/intro_tutorial.ipynb +++ b/docs/tutorials/intro_tutorial.ipynb @@ -126,7 +126,6 @@ "\n", "First, there are the required attributes for any GeoAgent in Mesa-Geo\n", "\n", - "- **unique_id**: Some unique identifier, often an int, this ensure Mesa can keep track of each agent without confusion\n", "- **model**: Model object class that we will build later, this is a pointer to the model instance so the agent can get information from the model as it behaves\n", "- **geometry**: GIS geometric object in this case a GIS Point\n", "- **crs**: A string describing the coordinate reference system the agent is using\n", @@ -160,7 +159,6 @@ "\n", " def __init__(\n", " self,\n", - " unique_id,\n", " model,\n", " geometry,\n", " crs,\n", @@ -170,7 +168,7 @@ " recovery_rate,\n", " death_risk\n", " ):\n", - " super().__init__(unique_id, model, geometry, crs)\n", + " super().__init__(model, geometry, crs)\n", " # Agent attributes\n", " self.atype = agent_type\n", " self.mobility_range = mobility_range\n", @@ -179,7 +177,7 @@ " self.death_risk = death_risk\n", "\n", " def __repr__(self):\n", - " return \"Person \" + str(self.unique_id)\n", + " return f\"Person {self.unique_id}\"\n", "\n", " def step(self): \n", " print (repr(self))\n", @@ -213,7 +211,6 @@ "\n", "The required attributes for any GeoAgent in Mesa-Geo:\n", "\n", - "- **unique_id**: For geographic agents such as a neighborhood mesa-geo will assign a very large integer as the agent id, if desired users can specify their own. \n", "- **model**: Model object class that we will build later, this is a pointer to the model instance so the agent can get information from the model as it behaves\n", "- **geometry**: GIS geometric object in this case a polygon form the geojson defining the perimeter of the neighborhood\n", "- **crs**: A string describing the coordinate reference system the agent is using\n", @@ -243,16 +240,16 @@ " \"\"\"Neighbourhood agent. Changes color according to number of infected inside it.\"\"\"\n", "\n", " def __init__(\n", - " self, unique_id, model, geometry, crs, agent_type=\"safe\", hotspot_threshold=1\n", + " self, model, geometry, crs, agent_type=\"safe\", hotspot_threshold=1\n", " ):\n", - " super().__init__(unique_id, model, geometry, crs)\n", + " super().__init__(model, geometry, crs)\n", " self.atype = agent_type\n", " self.hotspot_threshold = (\n", " hotspot_threshold # When a neighborhood is considered a hot-spot\n", " )\n", "\n", " def __repr__(self):\n", - " return \"Neighbourhood \" + str(self.unique_id)\n", + " return f\"Neighbourhood {self.unique_id}\"\n", " \n", " def step(self):\n", " \"\"\"Advance agent one step.\"\"\"\n", @@ -281,7 +278,7 @@ }, "source": [ "\n", - "First, we name our class in this case GeoSIR and we inherit the model class from Mesa. We store the path to our GeoJSON file in the object geojson regions. As JSONs mirror Pythons dictionary structure, we store the key for the neighbourhood id (\"HOODNUM\") in the variable unique_id. \n", + "First, we name our class in this case GeoSIR and we inherit the model class from Mesa. We store the path to our GeoJSON file in the object geojson regions. As JSONs mirror Pythons dictionary structure, we store the key for the neighbourhood id (\"HOODNUM\") in the variable unique_id (TODO: Update).\n", "\n", "Second, we set up the python initializer to initiate our model class. To do this we will, set up key word arguments or kwargs of the parameters we want for our model. In this case we will use: \n", "- population size (pop_size): An integer that determines the number of person agents\n", @@ -335,7 +332,6 @@ "\n", " # Geographical parameters for desired map\n", " geojson_regions = \"data/TorontoNeighbourhoods.geojson\"\n", - " unique_id = \"HOODNUM\"\n", "\n", " def __init__(\n", " self, pop_size=30, mobility_range=500, init_infection=0.2, exposure_dist=500, max_infection_risk=0.2,\n", @@ -355,9 +351,8 @@ "\n", " # Set up the Neighbourhood patches for every region in file\n", " ac = mg.AgentCreator(NeighbourhoodAgent, model=self)\n", - " neighbourhood_agents = ac.from_file(\n", - " self.geojson_regions, unique_id=self.unique_id\n", - " )\n", + " neighbourhood_agents = ac.from_file(self.geojson_regions)\n", + " # TODO: Check if the HOODNUM still needed, and if so, is read correctly\n", " \n", " #Add neighbourhood agents to space\n", " self.space.add_agents(neighbourhood_agents)\n", @@ -399,9 +394,7 @@ " \n", " x_home, y_home = self.find_home(neighbourhood_agents)\n", " \n", - " this_person = unique_person.create_agent(\n", - " Point(x_home, y_home), \"P\" + str(i), \n", - " )\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", @@ -849,7 +842,7 @@ " \n", " this_person = unique_person.create_agent(\n", " Point(x_home, y_home), \"P\" + str(i), \n", - " )\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", @@ -896,7 +889,9 @@ " # Run until no one is infected\n", " if self.counts[\"infected\"] == 0 :\n", " self.running = False\n" - ] + ], + "outputs": [], + "execution_count": null }, { "cell_type": "markdown",