Skip to content

Commit 437f7a1

Browse files
authored
Merge pull request NHERI-SimCenter#408 from zsarnoczay/master
Minor updates to rWHALE result aggregation functionality
2 parents 23f1bd2 + a624b6d commit 437f7a1

2 files changed

Lines changed: 68 additions & 46 deletions

File tree

modules/Workflow/rWHALE.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,14 +266,28 @@ def main( # noqa: C901, D103
266266
comm.Barrier()
267267

268268
# aggregate results
269+
if inputs.get('outputs', False):
270+
requested_outputs = []
271+
for output_type in ['AIM', 'EDP', 'DM', 'DV']:
272+
if inputs['outputs'].get(output_type, False):
273+
if inputs['outputs'][output_type]:
274+
requested_outputs.append(output_type)
275+
else:
276+
requested_outputs = ['AIM', 'EDP', 'DM', 'DV']
277+
requested_outputs.append('every_realization')
278+
269279
if (
270280
asset_type == 'Buildings' # noqa: PLR1714
271281
or asset_type == 'TransportationNetwork'
272282
or asset_type == 'WaterDistributionNetwork'
273283
or asset_type == 'PowerNetwork'
274284
):
275285
if procID == 0:
276-
WF.aggregate_results(asst_data=asst_data, asset_type=asset_type)
286+
WF.aggregate_results(
287+
asst_data=asst_data,
288+
asset_type=asset_type,
289+
out_types = requested_outputs
290+
)
277291

278292
elif asset_type == 'WaterNetworkPipelines':
279293
# Provide the headers and out types

modules/Workflow/whale/main.py

Lines changed: 53 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2944,8 +2944,7 @@ def aggregate_results( # noqa: C901, PLR0912, PLR0915
29442944
self,
29452945
asst_data,
29462946
asset_type='',
2947-
# out_types = ['IM', 'BIM', 'EDP', 'DM', 'DV', 'every_realization'],
2948-
out_types=['AIM', 'EDP', 'DMG', 'DV', 'every_realization'], # noqa: B006
2947+
out_types=['AIM', 'EDP', 'DM', 'DV', 'every_realization'], # noqa: B006
29492948
headers=None,
29502949
):
29512950
"""Short description
@@ -3127,7 +3126,7 @@ def aggregate_results( # noqa: C901, PLR0912, PLR0915
31273126
# deter_pointer[asset_id].update({
31283127
# "R2Dres":r2d_res_i
31293128
# })
3130-
if 'DMG' in out_types:
3129+
if 'DM' in out_types:
31313130
dmg_out_file_i = 'DMG_grp.json'
31323131

31333132
if dmg_out_file_i not in os.listdir(asset_dir):
@@ -3189,16 +3188,25 @@ def aggregate_results( # noqa: C901, PLR0912, PLR0915
31893188

31903189
if 'DV' in out_types:
31913190
dv_out_file_i = 'DV_repair_grp.json'
3191+
dl_summary_file = 'DL_summary_stats.json'
31923192

31933193
if dv_out_file_i not in os.listdir(asset_dir):
31943194
show_warning(
31953195
f"Couldn't find DV file for {assetTypeHierarchy[-1]} {asset_id}"
31963196
)
31973197

3198+
elif dl_summary_file not in os.listdir(asset_dir):
3199+
show_warning(
3200+
f"Couldn't find DL summary file for {assetTypeHierarchy[-1]} {asset_id}"
3201+
)
3202+
31983203
else:
31993204
with open(asset_dir / dv_out_file_i, encoding='utf-8') as f: # noqa: PTH123
32003205
dv_data_i = json.load(f)
32013206

3207+
with open(asset_dir / dl_summary_file, encoding='utf-8') as f: # noqa: PTH123
3208+
dl_summary = json.load(f)
3209+
32023210
# extract DV unit info
32033211
dv_units = dv_data_i['Units']
32043212
del dv_data_i['Units']
@@ -3244,48 +3252,48 @@ def aggregate_results( # noqa: C901, PLR0912, PLR0915
32443252

32453253
if 'DV' in R2D_res_out_types:
32463254
r2d_res_dv = dict() # noqa: C408
3247-
cost_columns = [
3248-
col
3249-
for col in dv_data_i.columns
3250-
if col.startswith('Cost')
3251-
]
3252-
if len(cost_columns) != 0:
3253-
cost_data = dv_data_i[cost_columns].mean()
3254-
cost_data_std = dv_data_i[cost_columns].std()
3255-
cost_key = cost_data.idxmax()
3256-
meanKey = ( # noqa: N806
3257-
f'R2Dres_mean_RepairCost_{dv_units[cost_key]}'
3258-
)
3259-
stdKey = ( # noqa: N806
3260-
f'R2Dres_std_RepairCost_{dv_units[cost_key]}'
3261-
)
3262-
r2d_res_dv.update(
3263-
{
3264-
meanKey: cost_data[cost_key],
3265-
stdKey: cost_data_std[cost_key],
3266-
}
3267-
)
3268-
time_columns = [
3269-
col
3270-
for col in dv_data_i.columns
3271-
if col.startswith('Time')
3272-
]
3273-
if len(time_columns) != 0:
3274-
time_data = dv_data_i[time_columns].mean()
3275-
time_data_std = dv_data_i[time_columns].std()
3276-
time_key = time_data.idxmax()
3277-
meanKey = ( # noqa: N806
3278-
f'R2Dres_mean_RepairTime_{dv_units[time_key]}'
3279-
)
3280-
stdKey = ( # noqa: N806
3281-
f'R2Dres_std_RepairTime_{dv_units[time_key]}'
3282-
)
3283-
r2d_res_dv.update(
3284-
{
3285-
meanKey: time_data[time_key],
3286-
stdKey: time_data_std[time_key],
3287-
}
3288-
)
3255+
3256+
if 'repair_cost' in dl_summary:
3257+
repair_cost_data = dl_summary['repair_cost']
3258+
3259+
elif 'repair_cost-' in dl_summary:
3260+
repair_cost_data = dl_summary['repair_cost-']
3261+
3262+
else:
3263+
repair_cost_data = None
3264+
3265+
if repair_cost_data:
3266+
3267+
cost_unit = [unit for dv_output, unit in dv_units.items() if dv_output.startswith('Cost')][0]
3268+
3269+
r2d_res_dv.update({
3270+
f'R2Dres_mean_RepairCost_{cost_unit}': repair_cost_data['mean'],
3271+
f'R2Dres_std_RepairCost_{cost_unit}': repair_cost_data['std']
3272+
})
3273+
3274+
if cost_unit == 'loss_ratio' and np.abs(replacement_cost-1.0)>1e-5:
3275+
r2d_res_dv.update({
3276+
f'R2Dres_mean_RepairCost': repair_cost_data['mean'] * replacement_cost,
3277+
f'R2Dres_std_RepairCost': repair_cost_data['std'] * replacement_cost
3278+
})
3279+
3280+
if 'repair_time' in dl_summary:
3281+
repair_time_data = dl_summary['repair_time']
3282+
3283+
elif 'repair_time-sequential' in dl_summary:
3284+
repair_time_data = dl_summary['repair_time-sequential']
3285+
3286+
else:
3287+
repair_time_data = None
3288+
3289+
if repair_time_data:
3290+
3291+
time_unit = [unit for dv_output, unit in dv_units.items() if dv_output.startswith('Time')][0]
3292+
3293+
r2d_res_dv.update({
3294+
f'R2Dres_mean_RepairTime_{time_unit}': repair_time_data['mean'],
3295+
f'R2Dres_std_RepairTime_{time_unit}': repair_time_data['std']
3296+
})
32893297

32903298
r2d_res_i = deter_pointer[asset_id].get('R2Dres', {})
32913299
r2d_res_i.update(r2d_res_dv)

0 commit comments

Comments
 (0)