diff --git a/gis/geo_schelling/model.py b/gis/geo_schelling/model.py index 9700910d..d98da193 100644 --- a/gis/geo_schelling/model.py +++ b/gis/geo_schelling/model.py @@ -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.""" @@ -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 diff --git a/gis/geo_schelling_points/geo_schelling_points/model.py b/gis/geo_schelling_points/geo_schelling_points/model.py index b8544934..b5a0e512 100644 --- a/gis/geo_schelling_points/geo_schelling_points/model.py +++ b/gis/geo_schelling_points/geo_schelling_points/model.py @@ -1,3 +1,4 @@ +import os import random import uuid @@ -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): @@ -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: diff --git a/gis/geo_sir/model.py b/gis/geo_sir/model.py index 2a2a0dac..543f64d1 100644 --- a/gis/geo_sir/model.py +++ b/gis/geo_sir/model.py @@ -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__(