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
7a7f812f
Commit
7a7f812f
authored
Feb 13, 2021
by
Tara Evaz Zadeh
Browse files
Fix SA(1.0) and SA(1) labeling mismatch between fragility and GMF file
parent
ff68b063
Pipeline
#19687
passed with stage
in 1 minute and 26 seconds
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
losscalculator/losslib.py
View file @
7a7f812f
...
...
@@ -21,6 +21,7 @@ import numpy as np
from
scipy.interpolate
import
griddata
import
csv
from
scipy
import
interpolate
import
re
def
get_full_GMF
(
ground_motion_field
,
lons
,
lats
,
method
=
"linear"
):
...
...
@@ -107,6 +108,31 @@ def get_full_GMF(ground_motion_field, lons, lats, method="linear"):
return
full_ground_motion_field
def
find_SA_frequency
(
SA_ground_motion
):
"""
Among the ground-motion types, SA-type naming includes an additional number
in parentheses indicating the frequency. This function extracts this
number as float from the given SA ground-motion as a string. The number is given as a list
of a single string, so it is extracted using the index ([o]) and then converted to float.
Input:
------
- SA_ground_motion: (string)
Example extract:
>>> SA_ground_motion
'SA(1)'
Output:
------
- SA_frequency: (float)
Example extract:
>>> SA_frequency
1.0
"""
SA_frequency
=
float
(
re
.
findall
(
r
"\d+\.\d+|\d+"
,
SA_ground_motion
)[
0
])
return
SA_frequency
def
taxonomy_to_fragility
(
ground_motion_type_index_map
,
taxonomy_to_fragility_source
,
fragility_pathname
):
...
...
@@ -163,26 +189,38 @@ def taxonomy_to_fragility(
fragility_function
=
list
(
csv
.
reader
(
open
(
fragility_pathname
+
"/"
+
taxonomy_map_entry
[
1
]
+
".csv"
))
)
# Check if already one fragility function for a given GM type has been
# selected
# Check if already one fragility function for a given GM type has been selected
if
taxonomy_map_entry
[
0
]
in
taxonomy_to_fragility_map
:
# Ignore the additional fragility function to keep everything
# unambiguous
pass
# Create the entry in the extended map with adding the type of ground
# motion 'fragility_function[0][0]'
# Ignore the additional fragility function to keep everything unambiguous
continue
fragility_function_gmt
=
fragility_function
[
0
][
0
]
# Detecting if the ground-motion type in the fragility functions is of type `SA`.
if
re
.
search
(
"SA"
,
fragility_function_gmt
):
# Extracting the SA frequency of the fragility function).
SA_type_in_fragility_function
=
find_SA_frequency
(
fragility_function_gmt
)
# Looping through the ground_motion_type_index_map dictionary keys which are
# the ground-motion types of the ground-motion field file
for
ground_motion_type
in
ground_motion_type_index_map
:
# Considering only ground-motion types of SA kind.
if
ground_motion_type
.
startswith
(
"gmv_SA("
):
SA_type_in_ground_motion_type_index_map
=
find_SA_frequency
(
ground_motion_type
)
# Checking if the SA frequency is the same in both
# fragility function and the ground-motion field file
if
SA_type_in_ground_motion_type_index_map
==
SA_type_in_fragility_function
:
# Taking the column number of the ground-motion type (of the fragility
# function) in the ground-motion field file.
gmtype_column_number
=
ground_motion_type_index_map
[
ground_motion_type
]
break
else
:
# The header of the ground-motion-field file contains a `gmv_` prefix which
# is kept to stay compatible with `OpenQuake`.
gmtype_column_number
=
ground_motion_type_index_map
[
"gmv_"
+
fragility_function_gmt
]
taxonomy_to_fragility_map
[
taxonomy_map_entry
[
0
]]
=
[
taxonomy_map_entry
[
1
],
# The header of the ground-motion-field file contains a `gmv_` prefix before
# ground-motion types as an abbrevation for 'ground-motion value', which is not used
# in the `fragility_function` (for example gmv_SA(0.3) in the ground-motion-field
# file and SA(0.3) in the fragility_function). This prefix is kept so that the
# ground-motion-field file has the same format as the `OpenQuake` program to stay
# compatible with. Thus, this prefix needs to be added to
# the ground_motion type in the `fragility_function` to match its respective
# ground-motion type header in the ground_motion_field file. For more information
# please check the example extracts and also the `documentation.md` file.
ground_motion_type_index_map
[
"gmv_"
+
fragility_function
[
0
][
0
]],
gmtype_column_number
,
]
return
taxonomy_to_fragility_map
...
...
@@ -288,7 +326,7 @@ def origin_id_to_geometry(geometry_source, exposure_type):
# selected.
if
geometry_mapping_item
[
0
]
in
origin_id_to_geometry_map
:
# Ignore the additional geometry to keep everything unambiguous
pass
continue
# Create the entry in the extended map with adding the cell-ID that
# The building belongs to ('geometry_mapping_item[2]')
origin_id_to_geometry_map
[
geometry_mapping_item
[
0
]]
=
[
...
...
@@ -299,7 +337,7 @@ def origin_id_to_geometry(geometry_source, exposure_type):
for
geometry_mapping_item
in
geometry_source
:
if
geometry_mapping_item
[
0
]
in
origin_id_to_geometry_map
:
# Implement your duplicate row(geometry_mapping_item) handling here
pass
continue
origin_id_to_geometry_map
[
geometry_mapping_item
[
0
]]
=
geometry_mapping_item
[
1
]
return
origin_id_to_geometry_map
...
...
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