Commit b3279ca4 authored by Danijel Schorlemmer's avatar Danijel Schorlemmer
Browse files

Introduce a command parameter for the losscalculator

parent 52f4b95c
Pipeline #35338 passed with stage
in 2 minutes and 30 seconds
...@@ -28,6 +28,9 @@ from .fragility_model import FragilityModel ...@@ -28,6 +28,9 @@ from .fragility_model import FragilityModel
from .losslib import get_full_gm_field from .losslib import get_full_gm_field
VERSION_STRING = "losscalculator version 0.1"
def damage_calculator( def damage_calculator(
exposure_filepath, exposure_filepath,
fragility_filepath, fragility_filepath,
...@@ -111,6 +114,12 @@ def main(): ...@@ -111,6 +114,12 @@ def main():
+ "of interest and fragility functions that show the probability of " + "of interest and fragility functions that show the probability of "
+ "exceeding a set of damage states, given an intensity measure level." + "exceeding a set of damage states, given an intensity measure level."
) )
parser.add_argument(
"command",
type=str,
help="'damage' to run a damage assessment, "
+ "'version' to output the version information.",
)
parser.add_argument( parser.add_argument(
"-i", "-i",
"--interpolation-method", "--interpolation-method",
...@@ -125,9 +134,9 @@ def main(): ...@@ -125,9 +134,9 @@ def main():
parser.add_argument( parser.add_argument(
"-f", "-f",
"--fragilities", "--fragilities",
required=True, required=False,
type=str, type=str,
help="file path to the fragility-function XML file (Required)", help="file path to the fragility-function XML file",
) )
parser.add_argument( parser.add_argument(
"-m", "-m",
...@@ -141,17 +150,17 @@ def main(): ...@@ -141,17 +150,17 @@ def main():
parser.add_argument( parser.add_argument(
"-g", "-g",
"--ground-motion-field", "--ground-motion-field",
required=True, required=False,
type=str, type=str,
help="path to the ground-motion values file. This file should include all the " help="path to the ground-motion values file. This file should include all the "
+ " intensity measure types that you have in your fragility functions (Required)", + " intensity measure types that you have in your fragility functions",
) )
parser.add_argument( parser.add_argument(
"-e", "-e",
"--exposure", "--exposure",
required=True, required=False,
type=str, type=str,
help="path to the file that includes the exposure assets (Required)", help="path to the file that includes the exposure assets",
) )
parser.add_argument( parser.add_argument(
"-r", "-r",
...@@ -159,8 +168,7 @@ def main(): ...@@ -159,8 +168,7 @@ def main():
required=False, required=False,
type=str, type=str,
default="damage_result.csv", default="damage_result.csv",
help="path to the file that we want to write the results to (default set to" help="path to the file to write the results to (default set to" + "damage_result.csv) ",
+ "damage_result.csv) ",
) )
parser.add_argument( parser.add_argument(
"-o", "-o",
...@@ -183,6 +191,7 @@ def main(): ...@@ -183,6 +191,7 @@ def main():
args = parser.parse_args() args = parser.parse_args()
# read arguments from command line. # read arguments from command line.
command = args.command
interpolation_method = args.interpolation_method interpolation_method = args.interpolation_method
fragility_filepath = args.fragilities fragility_filepath = args.fragilities
intensity_measure_map = args.intensity_measure_map intensity_measure_map = args.intensity_measure_map
...@@ -192,28 +201,53 @@ def main(): ...@@ -192,28 +201,53 @@ def main():
overwrite_result_file = args.overwrite overwrite_result_file = args.overwrite
taxonomy_map_filepath = args.taxonomy_map taxonomy_map_filepath = args.taxonomy_map
if os.path.exists(result_filepath): if command == "version":
if not overwrite_result_file: print(VERSION_STRING)
raise ValueError( elif command == "damage":
"result_filepath exists. Choose another name or set " # Check for necessary command line options
+ "--overwrite to overwrite existing result file." if gm_field_filepath is None:
print(
"Error: No ground-motion field provided. Please use the "
+ "-g/--ground-motion-field option to provide a ground-motion field file."
) )
else: exit()
os.remove(result_filepath) if exposure_filepath is None:
print(
startTime = datetime.datetime.now() "Error: No exposure data provided. Please use the "
print(startTime) + "-e/--exposure option to provide an exposure file."
)
damage_calculator( exit()
exposure_filepath, if fragility_filepath is None:
fragility_filepath, print(
intensity_measure_map, "Error: No fragility functions provided. Please use the "
taxonomy_map_filepath, + "-f/--fragilities option to provide a fragility-function file."
gm_field_filepath, )
interpolation_method, exit()
result_filepath, if os.path.exists(result_filepath):
) if not overwrite_result_file:
print("Execution time of the script", (datetime.datetime.now() - startTime)) print(
"Error: The result file exists. Please choose another file name or set "
+ "--overwrite to overwrite the existing result file."
)
exit()
else:
os.remove(result_filepath)
startTime = datetime.datetime.now()
print(startTime)
damage_calculator(
exposure_filepath,
fragility_filepath,
intensity_measure_map,
taxonomy_map_filepath,
gm_field_filepath,
interpolation_method,
result_filepath,
)
print("Execution time of the script", (datetime.datetime.now() - startTime))
else:
print("Command unknown. Exiting.")
if __name__ == "__main__": if __name__ == "__main__":
......
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