Skip to content

Commit

Permalink
Fix 3 data path imports in gis models (projectmesa#176)
Browse files Browse the repository at this point in the history
Fix the data path import errors in the geo_schelling, geo_schelling_points and geo_sir models.
  • Loading branch information
EwoutH committed Sep 3, 2024
1 parent 24e41b5 commit 6f917ea
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
8 changes: 7 additions & 1 deletion gis/geo_schelling/model.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import os
import random

import mesa
import mesa_geo as mg

script_directory = os.path.dirname(os.path.abspath(__file__))


class SchellingAgent(mg.GeoAgent):
"""Schelling segregation agent."""
Expand Down Expand Up @@ -67,7 +70,10 @@ def __init__(self, density=0.6, minority_pc=0.2, export_data=False):

# Set up the grid with patches for every NUTS region
ac = mg.AgentCreator(SchellingAgent, model=self)
agents = ac.from_file("data/nuts_rg_60M_2013_lvl_2.geojson")
data_path = os.path.join(
script_directory, "data/nuts_rg_60M_2013_lvl_2.geojson"
)
agents = ac.from_file(filename=data_path)
self.space.add_agents(agents)

# Set up agents
Expand Down
8 changes: 6 additions & 2 deletions gis/geo_schelling_points/geo_schelling_points/model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import random
import uuid

Expand All @@ -7,6 +8,8 @@
from .agents import PersonAgent, RegionAgent
from .space import Nuts2Eu

script_directory = os.path.dirname(os.path.abspath(__file__))


class GeoSchellingPoints(mesa.Model):
def __init__(self, red_percentage=0.5, similarity_threshold=0.5):
Expand All @@ -24,9 +27,10 @@ def __init__(self, red_percentage=0.5, similarity_threshold=0.5):

# Set up the grid with patches for every NUTS region
ac = mg.AgentCreator(RegionAgent, model=self)
regions = ac.from_file(
"data/nuts_rg_60M_2013_lvl_2.geojson", unique_id="NUTS_ID"
data_path = os.path.join(
script_directory, "../data/nuts_rg_60M_2013_lvl_2.geojson"
)
regions = ac.from_file(data_path, unique_id="NUTS_ID")
self.space.add_regions(regions)

for region in regions:
Expand Down
8 changes: 7 additions & 1 deletion gis/geo_sir/model.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import os

import mesa
import mesa_geo as mg
from shapely.geometry import Point

from .agents import NeighbourhoodAgent, PersonAgent

script_directory = os.path.dirname(os.path.abspath(__file__))


class GeoSir(mesa.Model):
"""Model class for a simplistic infection model."""

# Geographical parameters for desired map
geojson_regions = "data/TorontoNeighbourhoods.geojson"
geojson_regions = os.path.join(
script_directory, "data/TorontoNeighbourhoods.geojson"
)
unique_id = "HOODNUM"

def __init__(
Expand Down

0 comments on commit 6f917ea

Please sign in to comment.