Skip to content
GitLab
Menu
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
b1f36533
Commit
b1f36533
authored
Dec 10, 2021
by
Marius Kriegerowski
Browse files
Removed code duplication
parent
25685dc5
Pipeline
#36840
passed with stage
in 3 minutes and 7 seconds
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
losscalculator/damage_calculator.py
View file @
b1f36533
...
...
@@ -38,8 +38,8 @@ def damage_calculator(
exposure_format
,
fragility_source
,
intensity_measure_map_filepath
,
taxonomy_map_filepath
,
gm_field
:
GMField
,
taxonomy_map_filepath
:
str
=
None
,
interpolation_method
=
"linear"
,
result_filepath
=
"damage_result.csv"
,
output_format
=
"gpkg"
,
...
...
@@ -374,8 +374,8 @@ def main():
exposure_format
,
fragility_source
,
intensity_measure_map
,
taxonomy_map_filepath
,
gm_field
,
taxonomy_map_filepath
,
interpolation_method
,
result_filepath
,
output_format
,
...
...
losscalculator/fragility_model.py
View file @
b1f36533
...
...
@@ -25,6 +25,16 @@ import numpy as np
from
scipy.stats
import
lognorm
DEFAULT_INTENSITY_MEASURE_MAP
=
{
"SA(0.3)"
:
"gmv_SA(0.3)"
,
"SA(0.6)"
:
"gmv_SA(0.6)"
,
"SA(1.0)"
:
"gmv_SA(1.0)"
,
"SA(1)"
:
"gmv_SA(1.0)"
,
"PGA"
:
"gmv_PGA"
,
"MMI"
:
"gmv_MMI"
,
}
class
FragilityModel
:
"""
General class to handle a complete fragility model as a set of fragility functions
...
...
@@ -254,27 +264,14 @@ class FragilityModel:
self
.
fragility_functions
[
taxonomy
]
=
parameters
# Read the intensity measure map into a dictionary
if
intensity_measure_map_filepath
is
not
None
:
with
open
(
intensity_measure_map_filepath
,
mode
=
"r"
)
as
input_file
:
reader
=
csv
.
reader
(
input_file
)
next
(
reader
)
self
.
intensity_measure_map
=
{
rows
[
0
]:
rows
[
1
]
for
rows
in
reader
}
if
intensity_measure_map_filepath
is
None
:
self
.
intensity_measure_map
=
DEFAULT_INTENSITY_MEASURE_MAP
else
:
self
.
intensity_measure_map
=
{
"SA(0.3)"
:
"gmv_SA(0.3)"
,
"SA(0.6)"
:
"gmv_SA(0.6)"
,
"SA(1.0)"
:
"gmv_SA(1.0)"
,
"SA(1)"
:
"gmv_SA(1.0)"
,
"PGA"
:
"gmv_PGA"
,
"MMI"
:
"gmv_MMI"
,
}
self
.
intensity_measure_map
=
self
.
read_mapping_file
(
intensity_measure_map_filepath
)
# Read the taxonomy map if filename provided
if
taxonomy_map_filepath
is
not
None
:
with
open
(
taxonomy_map_filepath
,
mode
=
"r"
)
as
input_file
:
reader
=
csv
.
reader
(
input_file
)
next
(
reader
)
self
.
taxonomy_map
=
{
rows
[
0
]:
rows
[
1
]
for
rows
in
reader
}
self
.
taxonomy_map
=
self
.
read_mapping_file
(
taxonomy_map_filepath
)
im_types_dict
=
{}
for
index
,
value
in
enumerate
(
im_types
):
...
...
@@ -409,3 +406,11 @@ class FragilityModel:
poos
=
list
(
-
1
*
np
.
diff
(
poes
))
poos
.
append
(
poes
[
-
1
])
return
poes
[
1
:
5
],
poos
,
im_value
,
im_type
@
staticmethod
def
read_mapping_file
(
filepath
:
str
)
->
dict
[
str
,
str
]:
"""Reads a mapping table from `filepath` into a dictionary."""
with
open
(
filepath
,
mode
=
"r"
)
as
input_file
:
reader
=
csv
.
reader
(
input_file
)
next
(
reader
)
return
{
rows
[
0
]:
rows
[
1
]
for
rows
in
reader
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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