Skip to content

Commit 679b677

Browse files
wang-boyuEwoutH
authored andcommitted
set output_dir parameter for agents-networks gis example
1 parent f24626e commit 679b677

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

gis/agents_and_networks/scripts/run.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def make_parser():
3939
"lakes_file": f"data/{args.campus}/hydrop.zip",
4040
"rivers_file": f"data/{args.campus}/hydrol.zip",
4141
"driveway_file": f"data/{args.campus}/{data_file_prefix}_Rds.zip",
42+
"output_dir": "outputs",
4243
"show_walkway": True,
4344
"show_lakes_and_rivers": True,
4445
"show_driveway": True,

gis/agents_and_networks/src/model/model.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def __init__(
6969
lakes_file=script_directory / "../../data/ub/hydrop.zip",
7070
rivers_file=script_directory / "../../data/ub/hydrol.zip",
7171
driveway_file=script_directory / "../../data/data/ub/UB_Rds.zip",
72+
output_dir=script_directory / "../../outputs",
7273
num_commuters=50,
7374
commuter_min_friends=5,
7475
commuter_max_friends=10,
@@ -97,7 +98,9 @@ def __init__(
9798
Commuter.CHANCE_NEW_FRIEND = chance_new_friend
9899

99100
self._load_buildings_from_file(buildings_file, crs=model_crs, campus=campus)
100-
self._load_road_vertices_from_file(walkway_file, crs=model_crs, campus=campus)
101+
self._load_road_vertices_from_file(
102+
walkway_file, crs=model_crs, campus=campus, output_dir=output_dir
103+
)
101104
self._set_building_entrance()
102105
self.got_to_destination = 0
103106
self._create_commuters()
@@ -167,14 +170,16 @@ def _load_buildings_from_file(
167170
self.space.add_buildings(buildings)
168171

169172
def _load_road_vertices_from_file(
170-
self, walkway_file: str, crs: str, campus: str
173+
self, walkway_file: str, crs: str, campus: str, output_dir: str
171174
) -> None:
172175
walkway_df = (
173176
gpd.read_file(walkway_file)
174177
.set_crs(self.data_crs, allow_override=True)
175178
.to_crs(crs)
176179
)
177-
self.walkway = CampusWalkway(campus=campus, lines=walkway_df["geometry"])
180+
self.walkway = CampusWalkway(
181+
campus=campus, lines=walkway_df["geometry"], output_dir=output_dir
182+
)
178183
if self.show_walkway:
179184
walkway_creator = mg.AgentCreator(Walkway, model=self)
180185
walkway = walkway_creator.from_GeoDataFrame(walkway_df)

gis/agents_and_networks/src/space/road_network.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ class CampusWalkway(RoadNetwork):
6464
list[mesa.space.FloatCoordinate],
6565
]
6666

67-
def __init__(self, campus, lines) -> None:
67+
def __init__(self, campus, lines, output_dir) -> None:
6868
super().__init__(lines)
6969
self.campus = campus
70-
self._path_cache_result = f"outputs/{campus}_path_cache_result.pkl"
70+
self._path_cache_result = f"{output_dir}/{campus}_path_cache_result.pkl"
7171
try:
7272
with open(self._path_cache_result, "rb") as cached_result:
7373
self._path_select_cache = pickle.load(cached_result)

0 commit comments

Comments
 (0)