Skip to content

Commit a7941c5

Browse files
committed
Raise errors early and more verbose when trying to run only last iteration or use a precalculated transit cost matrix without matrices defined
1 parent 642ef33 commit a7941c5

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

Scripts/helmet.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,30 @@
1515

1616

1717
def main(args):
18+
# Set up filepaths
19+
base_zonedata_path: str = os.path.join(args.baseline_data_path, "2023_zonedata")
20+
base_matrices_path: str = os.path.join(args.baseline_data_path, "base_matrices")
21+
forecast_zonedata_path: str = args.forecast_data_path
22+
results_path: str = args.results_path
23+
emme_project_path: str = args.emme_path
24+
1825
if args.end_assignment_only:
26+
# Raise error if there is no demand matrix in results folder
27+
matrix_path = os.path.join(results_path, args.scenario_name, "Matrices")
28+
demand_matrix_path = os.path.join(results_path, args.scenario_name, "Matrices", "demand_aht.omx")
29+
if not os.path.exists(demand_matrix_path):
30+
msg = "Matrices not found for this scenario. Please uncheck the " \
31+
+ "'Aja vain loppusijoittelu' option in Helmet UI's scenario settings, " \
32+
+ f"or copy the demand matrices from base scenario to [{matrix_path}]."
33+
log.error(msg)
34+
raise FileNotFoundError(msg)
35+
# Else set iterations to 0, so that only the last iteration is run
1936
iterations = 0
2037
elif args.iterations > 0:
2138
iterations = args.iterations
2239
else:
2340
raise ArgumentTypeError(
2441
"Iteration number {} not valid".format(args.iterations))
25-
base_zonedata_path: str = os.path.join(args.baseline_data_path, "2023_zonedata")
26-
base_matrices_path: str = os.path.join(args.baseline_data_path, "base_matrices")
27-
forecast_zonedata_path: str = args.forecast_data_path
28-
results_path: str = args.results_path
29-
emme_project_path: str = args.emme_path
3042
log_extra = {
3143
"status": {
3244
"name": args.scenario_name,
@@ -115,6 +127,16 @@ def main(args):
115127
estimation_data_path)
116128
log_extra["status"]["results"] = model.mode_share
117129

130+
if args.use_fixed_transit_cost:
131+
# Raise error if there is no cost matrix in results folder
132+
cost_matrix_path = os.path.join(results_path, args.scenario_name, "Matrices", "cost_aht.omx")
133+
if not os.path.exists(cost_matrix_path):
134+
msg = "Precalculated transit cost matrix not found. " \
135+
+ "Please uncheck the 'Käytä esilaskettua joukkoliikenteen kustannusmatriisia' " \
136+
+ "option in Helmet UI's scenario settings to calculate transit cost."
137+
log.error(msg)
138+
raise FileNotFoundError(msg)
139+
118140
# Run traffic assignment simulation for N iterations,
119141
# on last iteration model-system will save the results
120142
log_extra["status"]["state"] = "preparing"

Scripts/helmet_validate_inputfiles.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,12 @@ def main(args):
163163
attr_space)
164164
log.error(msg)
165165
raise ValueError(msg)
166+
scenarios_with_different_zones = 0
166167
for scen in emmebank.scenarios():
167168
if scen.zone_numbers != zone_numbers:
168-
log.warn("Scenarios with different zones found in EMME bank!")
169+
scenarios_with_different_zones += 1
170+
if scenarios_with_different_zones > 0:
171+
log.warn(f"{scenarios_with_different_zones} Scenarios with different zones found in EMME bank! Matrices will not be compatible between scenarios with different zones.")
169172
scen = emmebank.scenario(first_scenario_ids[i])
170173
if scen is None:
171174
msg = "Project {} has no scenario {}".format(emp_path, first_scenario_ids[i])

0 commit comments

Comments
 (0)