Skip to content

Commit

Permalink
set output_dir parameter for agents-networks gis example
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-boyu authored and EwoutH committed Sep 3, 2024
1 parent f24626e commit 679b677
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions gis/agents_and_networks/scripts/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def make_parser():
"lakes_file": f"data/{args.campus}/hydrop.zip",
"rivers_file": f"data/{args.campus}/hydrol.zip",
"driveway_file": f"data/{args.campus}/{data_file_prefix}_Rds.zip",
"output_dir": "outputs",
"show_walkway": True,
"show_lakes_and_rivers": True,
"show_driveway": True,
Expand Down
11 changes: 8 additions & 3 deletions gis/agents_and_networks/src/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def __init__(
lakes_file=script_directory / "../../data/ub/hydrop.zip",
rivers_file=script_directory / "../../data/ub/hydrol.zip",
driveway_file=script_directory / "../../data/data/ub/UB_Rds.zip",
output_dir=script_directory / "../../outputs",
num_commuters=50,
commuter_min_friends=5,
commuter_max_friends=10,
Expand Down Expand Up @@ -97,7 +98,9 @@ def __init__(
Commuter.CHANCE_NEW_FRIEND = chance_new_friend

self._load_buildings_from_file(buildings_file, crs=model_crs, campus=campus)
self._load_road_vertices_from_file(walkway_file, crs=model_crs, campus=campus)
self._load_road_vertices_from_file(
walkway_file, crs=model_crs, campus=campus, output_dir=output_dir
)
self._set_building_entrance()
self.got_to_destination = 0
self._create_commuters()
Expand Down Expand Up @@ -167,14 +170,16 @@ def _load_buildings_from_file(
self.space.add_buildings(buildings)

def _load_road_vertices_from_file(
self, walkway_file: str, crs: str, campus: str
self, walkway_file: str, crs: str, campus: str, output_dir: str
) -> None:
walkway_df = (
gpd.read_file(walkway_file)
.set_crs(self.data_crs, allow_override=True)
.to_crs(crs)
)
self.walkway = CampusWalkway(campus=campus, lines=walkway_df["geometry"])
self.walkway = CampusWalkway(
campus=campus, lines=walkway_df["geometry"], output_dir=output_dir
)
if self.show_walkway:
walkway_creator = mg.AgentCreator(Walkway, model=self)
walkway = walkway_creator.from_GeoDataFrame(walkway_df)
Expand Down
4 changes: 2 additions & 2 deletions gis/agents_and_networks/src/space/road_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ class CampusWalkway(RoadNetwork):
list[mesa.space.FloatCoordinate],
]

def __init__(self, campus, lines) -> None:
def __init__(self, campus, lines, output_dir) -> None:
super().__init__(lines)
self.campus = campus
self._path_cache_result = f"outputs/{campus}_path_cache_result.pkl"
self._path_cache_result = f"{output_dir}/{campus}_path_cache_result.pkl"
try:
with open(self._path_cache_result, "rb") as cached_result:
self._path_select_cache = pickle.load(cached_result)
Expand Down

0 comments on commit 679b677

Please sign in to comment.