Commit 07bf071b authored by Danijel Schorlemmer's avatar Danijel Schorlemmer
Browse files

Implemented the summing up of probabilities per damage state per building (aggregation)

parent 4da4c24c
Pipeline #35378 passed with stage
in 2 minutes and 2 seconds
...@@ -40,6 +40,7 @@ def damage_calculator( ...@@ -40,6 +40,7 @@ def damage_calculator(
interpolation_method="linear", interpolation_method="linear",
result_filepath="damage_result.csv", result_filepath="damage_result.csv",
use_xml_fragilities=True, use_xml_fragilities=True,
aggregation=True,
): ):
""" """
This function computes the probabilities of occurrence (PoO) of damage states for a scenario This function computes the probabilities of occurrence (PoO) of damage states for a scenario
...@@ -104,7 +105,22 @@ def damage_calculator( ...@@ -104,7 +105,22 @@ def damage_calculator(
row[(i + 1)] for row in damage_by_assets 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(): def main():
...@@ -184,8 +200,14 @@ def main(): ...@@ -184,8 +200,14 @@ def main():
"--overwrite", "--overwrite",
required=False, required=False,
action="store_true", action="store_true",
help="Result file exists. Choose another name or set --overwrite" help="overwrite result file if it already exists",
+ "to overwrite the existing result file.", )
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( parser.add_argument(
"-t", "-t",
...@@ -209,6 +231,7 @@ def main(): ...@@ -209,6 +231,7 @@ def main():
exposure_filepath = args.exposure exposure_filepath = args.exposure
result_filepath = args.results result_filepath = args.results
overwrite_result_file = args.overwrite overwrite_result_file = args.overwrite
aggregation = not args.no_aggregation
taxonomy_map_filepath = args.taxonomy_map taxonomy_map_filepath = args.taxonomy_map
if command == "version": if command == "version":
...@@ -265,6 +288,7 @@ def main(): ...@@ -265,6 +288,7 @@ def main():
interpolation_method, interpolation_method,
result_filepath, result_filepath,
use_xml_fragilities, use_xml_fragilities,
aggregation,
) )
print("Execution time of the script", (datetime.datetime.now() - startTime)) print("Execution time of the script", (datetime.datetime.now() - startTime))
else: else:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment