Skip to content

Commit 1688142

Browse files
authored
Merge branch 'dev' into main_changes_merge
2 parents d54d194 + 44fb500 commit 1688142

File tree

9 files changed

+47
-23
lines changed

9 files changed

+47
-23
lines changed

Scripts/assignment/emme_assignment.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -478,11 +478,9 @@ def calc_noise(self) -> pandas.Series:
478478
link = morning_network.link(link.i_node, link.j_node)
479479
rlink = link.reverse_link
480480
if reverse_traffic > 0:
481-
speed = (60 * 2 * link.length
482-
/ (link["@car_time_aht"]+rlink["@car_time_aht"]))
481+
speed = (60 * 2 * link.length/(link["@car_time_aht"]+rlink["@car_time_aht"])) if rlink["@car_time_aht"] > 0.0 else 50.0
483482
else:
484-
speed = (0.3*(60*link.length/link["@car_time_aht"])
485-
+ 0.7*link.data2)
483+
speed = (0.3*(60*link.length/link["@car_time_aht"]) + 0.7*link.data2) if link["@car_time_aht"] > 0.0 else 50.0
486484
speed = max(speed, 50.0)
487485

488486
# Calculate start noise

Scripts/cba.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
"train": ("HSL-juna-2", "muu_juna", "HSL-juna-1", "HSL-juna-3"),
3333
"tram": ("ratikka", "pikaratikk"),
3434
}
35+
TRANSIT_AGGREGATIONS_FALLBACK = {
36+
"bus": ("HSL-bussi", "ValluVakio", "ValluPika"),
37+
"trunk": ("HSL-runkob", ),
38+
"train": ("HSL-juna", "muu_juna"),
39+
"tram": ("ratikka", "pikaratikk"),
40+
}
3541

3642
TRANSLATIONS = {
3743
"car_work": "ha_tyo",
@@ -209,13 +215,18 @@ def run_cost_benefit_analysis(scenario_0, scenario_1, year, workbook):
209215
noise_diff = read(NOISE_FILE, scenario_1) - read(NOISE_FILE, scenario_0)
210216
ws[CELL_INDICES["noise"][year]] = sum(noise_diff["population"])
211217

218+
transit_vehicle_kms_tables = [read(TRANSIT_KMS_FILE, scenario_0), read(TRANSIT_KMS_FILE, scenario_1)]
219+
for transit_vehicle_kms in transit_vehicle_kms_tables:
220+
if all(submode in transit_vehicle_kms.index for submodes in TRANSIT_AGGREGATIONS.values() for submode in submodes):
221+
transit_aggs = TRANSIT_AGGREGATIONS
222+
else:
223+
transit_aggs = TRANSIT_AGGREGATIONS_FALLBACK
224+
for mode in transit_aggs:
225+
transit_vehicle_kms.loc[mode] = 0 # Change aggregated mode to 0
226+
for submode in transit_aggs[mode]: # Go through the submodes and add their values to the aggregated mode
227+
transit_vehicle_kms.loc[mode] += transit_vehicle_kms.loc[submode]
212228
# Calculate transit mile differences
213-
transit_mile_diff = (read(TRANSIT_KMS_FILE, scenario_1)
214-
- read(TRANSIT_KMS_FILE, scenario_0))
215-
for mode in TRANSIT_AGGREGATIONS:
216-
transit_mile_diff.loc[mode] = 0
217-
for submode in TRANSIT_AGGREGATIONS[mode]:
218-
transit_mile_diff.loc[mode] += transit_mile_diff.loc[submode]
229+
transit_mile_diff = transit_vehicle_kms_tables[1] - transit_vehicle_kms_tables[0]
219230
ws = workbook["Tuottajahyodyt"]
220231
cols = CELL_INDICES["transit_miles"]["cols"]
221232
rows = CELL_INDICES["transit_miles"]["rows"][year]
@@ -419,6 +430,13 @@ def calc_revenue(demands, costs):
419430
help="Path to Results directory.")
420431
args = parser.parse_args()
421432
log.initialize(args)
433+
434+
matching_vehicle_kms_cols = list(read(VEHICLE_KMS_FILE, args.baseline_scenario).columns) == list(read(VEHICLE_KMS_FILE, args.projected_scenario).columns)
435+
matching_transit_kms_rows = list(read(TRANSIT_KMS_FILE, args.baseline_scenario).index) == list(read(TRANSIT_KMS_FILE, args.projected_scenario).index)
436+
if not (matching_vehicle_kms_cols and matching_transit_kms_rows):
437+
msg = "The data structure of transit_kms.txt or vehicle_kms_vdf.txt is different between scenarios. Check the results folders of scenarios being compared."
438+
log.error(msg)
439+
raise KeyError(msg)
422440
wb = load_workbook(os.path.join(SCRIPT_DIR, "CBA_kehikko.xlsx"))
423441
results = run_cost_benefit_analysis(
424442
args.baseline_scenario, args.projected_scenario, 1, wb)

Scripts/helmet.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ def log_header(msg, log_width=72):
123123
if args.is_agent_model:
124124
model = AgentModelSystem(
125125
forecast_zonedata_path, base_zonedata_path, base_matrices_path,
126-
results_path, ass_model, args.scenario_name, estimation_data_path)
126+
results_path, ass_model, args.scenario_name, event_handler,
127+
estimation_data_path)
127128
else:
128129
model = ModelSystem(
129130
forecast_zonedata_path, base_zonedata_path, base_matrices_path,

Scripts/helmet_validate_inputfiles.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,10 @@ def main(args):
183183
# Check if emmebank has scenarios with different zone numbers
184184
scenarios_with_different_zones = 0
185185
for scen in emmebank.scenarios():
186-
if scen.zone_numbers != zone_numbers:
186+
compared_zone_numbers = scen.zone_numbers
187+
if compared_zone_numbers < 1: # Skip empty scenarios
188+
continue
189+
if compared_zone_numbers != zone_numbers:
187190
scenarios_with_different_zones += 1
188191
if scenarios_with_different_zones > 0:
189192
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.")

Scripts/models/park_and_ride_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,15 @@ def _get_facility_utilities(self) -> np.ndarray:
240240
return np.array([f.cost * facility_cost_w + f.time * facility_time_w + f.extra_utility for f in self._facilities])[None, None, :]
241241

242242
def _calc_extra_utility(self, impedance: Dict[str, Dict[str, Dict[str, np.ndarray]]]):
243-
"""Calculate extra utility for each facility based on the number of shops within 1 km.
243+
"""Calculate extra utility for each facility based on the number of shops within x km.
244244
Does nothing if there are no facilities or if the extra utility has already been calculated.
245245
246246
Args:
247247
impedance (Dict[str, Dict[str, Dict[str, np.ndarray]]]): Impedance matrices
248248
"""
249249
if len(self._facilities) == 0 or self._facilities[0].extra_utility is not None:
250250
return
251-
SHOP_SEARCH_RADIUS = 3.0 # Include shops within 1 km
251+
SHOP_SEARCH_RADIUS = 3.0 # Include shops within x km
252252
try:
253253
shop_weight = destination_choice[self._purpose.name]['park_and_ride']['utility']['facility']['shops']
254254
except KeyError:

Scripts/parameters/assignment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
"hmaf": (800000, 800500),
9898
"hrjasf": (801000, 801500),
9999
"htpaf": (802000, 806000),
100-
"hpaf": (810000, 816000),
100+
"htpaf": (810000, 816000),
101101
}
102102
vdf_temp = ("(put(60/ul2)*(1+{}*put((volau+volad)/{})/"
103103
+ "(ul1-get(2))))*(get(2).le.put(ul1*{}))*length+(get(2).gt."

Scripts/tests/test_data/Network/base_network_test.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ a 310493 25474182 6682152 0 0 49 C
547547
a 310494 25474153 6682117 0 0 49 C
548548
a 310495 25474593 6681914 0 0 49 C
549549
a 310496 25474577 6681880 0 0 49 C
550-
a 321079 25433589.837194 6698120.349799 0 20 428 O
550+
a 321079 25433589.837194 6698120.349799 0 20 444 O
551551
a 321090 25428709.603729 6696148.266151 0 20 734 O
552552
a 321091 25421975.1812 6698283.299535 0 20 734 O
553553
a 321092 25414689.484996 6697591.407689 0 20 734 O
@@ -635,7 +635,7 @@ a 6291 179244 1.1744 hcvkyaf 99 1.0 99 1000 100 .469970
635635
a 19071 300018 2.0896 hcvkaf 99 1.0 99 0 0 0
636636
a 34102 321095 10.3859 hcvkyasf 98 1.0 99 1000 100 0
637637
a 34500 200843 .097100 hcvkyasf 87 1.0 99 1000 100 27.4636
638-
a 35039 224410 .118611 hcvkyaf 140 1.0 5 900 36 0
638+
a 35039 224410 .118611 hcvkyaf 84 1.0 5 900 36 0
639639
a 40222 40226 .133000 hcvkybgde 129 1.0 2 1850 81 45.9068
640640
a 40223 197014 1.0117 hcvkybgde 124 3.0 1 1700 97 201.129
641641
a 40224 50074 .359200 hcvkybgde 124 3.0 1 1700 97 189.548
@@ -1480,7 +1480,7 @@ a 223753 238903 .093600 hcvkybgdeaf 134 2.0 3 1250 54 89.3543
14801480
a 223753 321597 .297300 hcvkybgdeaf 134 2.0 3 1250 54 66.3284
14811481
a 224389 238904 .064800 hcvkybgdeaf 134 2.0 3 1250 54 66.3284
14821482
a 224389 321597 .162600 hcvkybgdeaf 134 2.0 3 1250 54 82.6334
1483-
a 224410 35039 .118611 hcvkyaf 140 1.0 5 900 36 0
1483+
a 224410 35039 .118611 hcvkyaf 84 1.0 5 900 36 0
14841484
a 224410 197084 .040100 hcvkybgdeaf 134 3.0 3 1250 54 89.632
14851485
a 224410 238903 .077100 hcvkybgdeaf 134 2.0 3 1250 54 71.5573
14861486
a 224410 801035 .090100 haf 70 1.0 0 0 0 0

Scripts/utils/calc_noise.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,9 @@ def calc_noise(self, link):
4949
link = self.morning_network.link(link.i_node, link.j_node)
5050
rlink = link.reverse_link
5151
if reverse_traffic > 0:
52-
speed = (60 * 2 * link.length
53-
/ (link[self.car_morning]+rlink[self.car_morning]))
52+
speed = (60 * 2 * link.length/(link[self.car_morning]+rlink[self.car_morning])) if rlink[self.car_morning] > 0 else 50.0
5453
else:
55-
speed = (0.3*(60*link.length/link[self.car_morning])
56-
+ 0.7*link.data2)
54+
speed = (0.3*(60*link.length/link[self.car_morning]) + 0.7*link.data2) if link[self.car_morning] > 0 else 50.0
5755
speed = max(speed, 50.0)
5856

5957
# Calculate start noise

Scripts/utils/validate_network.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,13 @@ def validate(network, fares=None):
139139
timeperiod, link.id)
140140
log.error(msg)
141141
raise ValueError(msg)
142-
142+
143+
if (link.i_node.is_centroid or link.j_node.is_centroid) and link.type not in param.connector_link_types:
144+
msg = "Link {} is a connector and must be one of the connector link types: {}".format(
145+
link.id, param.connector_link_types)
146+
log.error(msg)
147+
raise ValueError(msg)
148+
143149
if link.i_node.is_centroid and link.j_node.is_centroid:
144150
msg = "Link {} is leading directly from centroid node {} to centroid node {}. This is not allowed.".format(link.id,link.i_node.number,link.j_node.number)
145151
log.error(msg)

0 commit comments

Comments
 (0)