Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Dynamic Exposure
Global Dynamic Exposure
losscalculator
Commits
b3279ca4
Commit
b3279ca4
authored
Nov 17, 2021
by
Danijel Schorlemmer
Browse files
Introduce a command parameter for the losscalculator
parent
52f4b95c
Pipeline
#35338
passed with stage
in 2 minutes and 30 seconds
Changes
1
Pipelines
4
Hide whitespace changes
Inline
Side-by-side
losscalculator/damage_calculator.py
View file @
b3279ca4
...
...
@@ -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
=
Tru
e
,
required
=
Fals
e
,
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
=
Tru
e
,
required
=
Fals
e
,
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
=
Tru
e
,
required
=
Fals
e
,
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__"
:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment