diff --git a/losscalculator/damage_calculator.py b/losscalculator/damage_calculator.py index 65f083276ebaab2d773ca5103185113d3755630e..f18eb5b33e5de074c5230ed9ad9a1406e817de74 100644 --- a/losscalculator/damage_calculator.py +++ b/losscalculator/damage_calculator.py @@ -40,6 +40,7 @@ def damage_calculator( interpolation_method="linear", result_filepath="damage_result.csv", use_xml_fragilities=True, + aggregation=True, ): """ This function computes the probabilities of occurrence (PoO) of damage states for a scenario @@ -104,7 +105,22 @@ def damage_calculator( row[(i + 1)] for row in damage_by_assets ] - exposure.to_csv(result_filepath, index=False) + if aggregation: + aggregated = exposure.groupby(["id", "building_geometry", "tile_id", "tile_geometry"])[ + [ + "number", + "structural", + "night", + "structural_no_damage", + "structural_slight", + "structural_moderate", + "structural_extensive", + "structural_complete", + ] + ].sum() + aggregated.to_csv(result_filepath) + else: + exposure.to_csv(result_filepath, index=False) def main(): @@ -184,8 +200,14 @@ def main(): "--overwrite", required=False, action="store_true", - help="Result file exists. Choose another name or set --overwrite" - + "to overwrite the existing result file.", + help="overwrite result file if it already exists", + ) + parser.add_argument( + "-a", + "--no-aggregation", + required=False, + action="store_true", + help="do not aggregate the results for each building (detailed results for debugging)", ) parser.add_argument( "-t", @@ -209,6 +231,7 @@ def main(): exposure_filepath = args.exposure result_filepath = args.results overwrite_result_file = args.overwrite + aggregation = not args.no_aggregation taxonomy_map_filepath = args.taxonomy_map if command == "version": @@ -265,6 +288,7 @@ def main(): interpolation_method, result_filepath, use_xml_fragilities, + aggregation, ) print("Execution time of the script", (datetime.datetime.now() - startTime)) else: