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
from .losslib import get_full_gm_field
VERSION_STRING = "losscalculator version 0.1"
def damage_calculator(
exposure_filepath,
fragility_filepath,
......@@ -111,6 +114,12 @@ def main():
+ "of interest and fragility functions that show the probability of "
+ "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(
"-i",
"--interpolation-method",
......@@ -125,9 +134,9 @@ def main():
parser.add_argument(
"-f",
"--fragilities",
required=True,
required=False,
type=str,
help="file path to the fragility-function XML file (Required)",
help="file path to the fragility-function XML file",
)
parser.add_argument(
"-m",
......@@ -141,17 +150,17 @@ def main():
parser.add_argument(
"-g",
"--ground-motion-field",
required=True,
required=False,
type=str,
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(
"-e",
"--exposure",
required=True,
required=False,
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(
"-r",
......@@ -159,8 +168,7 @@ def main():
required=False,
type=str,
default="damage_result.csv",
help="path to the file that we want to write the results to (default set to"
+ "damage_result.csv) ",
help="path to the file to write the results to (default set to" + "damage_result.csv) ",
)
parser.add_argument(
"-o",
......@@ -183,6 +191,7 @@ def main():
args = parser.parse_args()
# read arguments from command line.
command = args.command
interpolation_method = args.interpolation_method
fragility_filepath = args.fragilities
intensity_measure_map = args.intensity_measure_map
......@@ -192,28 +201,53 @@ def main():
overwrite_result_file = args.overwrite
taxonomy_map_filepath = args.taxonomy_map
if os.path.exists(result_filepath):
if not overwrite_result_file:
raise ValueError(
"result_filepath exists. Choose another name or set "
+ "--overwrite to overwrite existing result file."
if command == "version":
print(VERSION_STRING)
elif command == "damage":
# Check for necessary command line options
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:
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))
exit()
if exposure_filepath is None:
print(
"Error: No exposure data provided. Please use the "
+ "-e/--exposure option to provide an exposure file."
)
exit()
if fragility_filepath is None:
print(
"Error: No fragility functions provided. Please use the "
+ "-f/--fragilities option to provide a fragility-function file."
)
exit()
if os.path.exists(result_filepath):
if not overwrite_result_file:
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__":
......
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