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
780b670b
Commit
780b670b
authored
Feb 08, 2021
by
Tara Evaz Zadeh
Browse files
Automatically detect ground-motion type and column_num in the gm_file
parent
6282935c
Pipeline
#19354
passed with stage
in 1 minute and 33 seconds
Changes
4
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
examples/example_cell/reference_result.csv
View file @
780b670b
geometry,,origin_id,,asset_id,,lon,,lat,,taxonomy,,gm_value,,PoEs,,PoOs,,
tot_
num_buildings,,structural_no_damage,,structural_slight,,structural_moderate,,structural_extensive,,structural_complete
geometry,,origin_id,,asset_id,,lon,,lat,,taxonomy,,gm_value,,PoEs,,PoOs,,num_buildings,,structural_no_damage,,structural_slight,,structural_moderate,,structural_extensive,,structural_complete
"POLYGON ((23.63055555555556 38.0611111111111, 23.63333333333335 38.0611111111111, 23.63333333333335 38.0638888888889, 23.63055555555556 38.0638888888889, 23.63055555555556 38.0611111111111))",,cell_2423204507,,GDE_Com_940019,,23.631944444400002,,38.0625,,CR/LDUAL+CDH/H:1/15.0,,0.12688663132861894,,"[8.474877104881386e-06, 0.0, 0.0, 0.0]",,"[0.9999915251228951, 8.474877104881386e-06, -0.0, -0.0, 0.0]",,28.3,,28.299760160977932,,0.00023983902206814323,,-0.0,,-0.0,,0.0
"POLYGON ((23.63055555555556 38.0611111111111, 23.63333333333335 38.0611111111111, 23.63333333333335 38.0638888888889, 23.63055555555556 38.0638888888889, 23.63055555555556 38.0611111111111))",,cell_2423204507,,GDE_Com_940036,,23.631944444400002,,38.0625,,CR/LDUAL+CDM/H:1/8.0,,0.12688663132861894,,"[8.474877104881386e-06, 0.0, 0.0, 0.0]",,"[0.9999915251228951, 8.474877104881386e-06, -0.0, -0.0, 0.0]",,12.5,,12.499894064036189,,0.00010593596381101732,,-0.0,,-0.0,,0.0
"POLYGON ((23.63055555555556 38.0611111111111, 23.63333333333335 38.0611111111111, 23.63333333333335 38.0638888888889, 23.63055555555556 38.0638888888889, 23.63055555555556 38.0611111111111))",,cell_2423204507,,GDE_Res_1036159,,23.631944444400002,,38.0625,,CR/LDUAL+CDL/HBET:3-5/SOS/8.0,,0.251555124927799,,"[0.13663294980106422, 0.00180695837185944, 0.0001277873923228429, 1.821617605136137e-05]",,"[0.8633670501989358, 0.1348259914292048, 0.001679170979536597, 0.00010957121627148152, 1.821617605136137e-05]",,36.2,,31.253887217201477,,4.880700889737214,,0.060785989459224817,,0.003966478029027631,,0.0006594255730592816
...
...
losscalculator/damage_calculator.py
View file @
780b670b
...
...
@@ -30,7 +30,7 @@ def get_exposure_per_tile(
exposure_filepath
,
fragility_pathname
,
taxonomy_conversion_filepath
,
ground_motion_filepath
,
ground_motion_
field_
filepath
,
geometry_source_filepath
,
cell_id_source_filepath
,
exposure_type
=
"cell"
,
...
...
@@ -41,10 +41,24 @@ def get_exposure_per_tile(
exposure
=
pd
.
read_csv
(
exposure_filepath
)
lons_whole_area
=
exposure
.
lon
lats_whole_area
=
exposure
.
lat
ground_motion_field
=
np
.
loadtxt
(
ground_motion_filepath
,
delimiter
=
","
,
skiprows
=
1
)
ground_motion_field
=
np
.
loadtxt
(
ground_motion_
field_
filepath
,
delimiter
=
","
,
skiprows
=
1
)
full_ground_motion_field
=
losslib
.
get_full_GMF
(
ground_motion_field
,
lons_whole_area
,
lats_whole_area
,
interpolation_method
)
# Creating an empty dictionary to later fill with ground-motion types and their column
# numbers (as they appear in the ground-motion-field file) as its key and value.
ground_motion_type_index_map
=
{}
with
open
(
ground_motion_field_filepath
)
as
gmf
:
# Extracting the ground-motion types available in the ground-motion-field file. Note
# the ground-motion-field file format:
# `[lon, lat, gmValueofType1, ..., gmValueofTypeN]`
gm_types
=
gmf
.
readline
().
strip
().
split
(
","
)[
2
:]
for
i
in
range
(
len
(
gm_types
)):
# Appending each `gm_type` and its column number (as it appears in the
# ground-motion-field file) to the `ground_motion_type_index_map` as the dictionary
# key and value, respectively.
ground_motion_type_index_map
[
gm_types
[
i
]]
=
i
+
2
cell_ids
=
pd
.
read_csv
(
cell_id_source_filepath
)
with
open
(
result_filepath
,
"a+"
,
newline
=
""
)
as
write_obj
:
csv_writer
=
csv
.
writer
(
write_obj
)
...
...
@@ -129,8 +143,9 @@ def get_exposure_per_tile(
fragility_pathname
,
exposure_per_tile
,
taxonomy_conversion_filepath
,
ground_motion_filepath
,
ground_motion_
field_
filepath
,
geometry_source_filepath
,
ground_motion_type_index_map
,
exposure_type
,
interpolation_method
,
)
...
...
@@ -241,7 +256,7 @@ if __name__ == "__main__":
exposure_type
=
args
.
exposure_type
fragility_pathname
=
args
.
fragilities
taxonomy_conversion_filepath
=
args
.
taxonomy_map
ground_motion_filepath
=
args
.
ground_motion_field
ground_motion_
field_
filepath
=
args
.
ground_motion_field
cell_id_source_filepath
=
args
.
cell_ids
exposure_filepath
=
args
.
exposure
geometry_source_filepath
=
args
.
geometry
...
...
@@ -262,7 +277,7 @@ if __name__ == "__main__":
exposure_filepath
,
fragility_pathname
,
taxonomy_conversion_filepath
,
ground_motion_filepath
,
ground_motion_
field_
filepath
,
geometry_source_filepath
,
cell_id_source_filepath
,
exposure_type
,
...
...
losscalculator/damage_calculator_tile_version.py
View file @
780b670b
...
...
@@ -28,8 +28,9 @@ def damageCalculator_TileVersion(
fragility_pathname
,
exposure
,
taxonomy_conversion_path
,
ground_motion_filepath
,
ground_motion_
field_
filepath
,
geometry_source_path
,
ground_motion_type_index_map
,
exposure_type
=
"cell"
,
method
=
"linear"
,
):
...
...
@@ -97,10 +98,10 @@ def damageCalculator_TileVersion(
>>> taxonomy_conversion_path
"/home/TileCalculations/taxonomy_mapping_Europe.csv"
- ground_motion_filepath: (str)
- ground_motion_
field_
filepath: (str)
Address to the ground-motion values file.
Example extract:
>>> ground_motion_filepath
>>> ground_motion_
field_
filepath
"/home/TileCalculations/shakemap1381_2.csv"
- geometry_source_path: (str)
...
...
@@ -157,14 +158,11 @@ def damageCalculator_TileVersion(
origin_ids
=
exposure
.
origin_id
# Begin Computation
# Define a dictionary with keys as the ground-motion type and value as the column
# number of the ground-motion type in the shakemap file.
gmDict
=
{
"PGA"
:
2
,
"SA(0.3)"
:
3
,
"SA(0.6)"
:
4
,
"SA(1.0)"
:
5
,
"SA(1)"
:
5
}
# Calling the function "taxonomy_to_fragility" to get a dictionary with keys as the
# taxonomy and the values as both the fragility function name (excluding the ".csv" part)
# and the column number of the respective ground-motion type in `ground-motion-field` file.
taxonomy_to_fragility_map
=
losslib
.
taxonomy_to_fragility
(
g
mDict
,
taxonomy_to_fragility_source
,
fragility_pathname
g
round_motion_type_index_map
,
taxonomy_to_fragility_source
,
fragility_pathname
)
# Calling the function "origin_id_to_geometry" to get a dictionary with keys as the
# origin_id and the value as the respective polygon.
...
...
losscalculator/losslib.py
View file @
780b670b
...
...
@@ -107,7 +107,9 @@ def get_full_GMF(ground_motion_field, lons, lats, method="linear"):
return
full_ground_motion_field
def
taxonomy_to_fragility
(
gmDict
,
taxonomy_to_fragility_source
,
fragility_pathname
):
def
taxonomy_to_fragility
(
ground_motion_type_index_map
,
taxonomy_to_fragility_source
,
fragility_pathname
):
"""
Creates an extended map of taxonomies to fragility function.
The input map 'taxonomy_to_fragility_source' contains the mapping for each
...
...
@@ -116,12 +118,12 @@ def taxonomy_to_fragility(gmDict, taxonomy_to_fragility_source, fragility_pathna
Input:
------
- g
mDict
: (dictionary)
- g
round_motion_type_index_map
: (dictionary)
key: ground-motion type; value: column number in the ground-motion
field file
Example extract:
>>> g
mDict
{'PGA': 2, 'SA(0.3)': 3, 'SA(0.6)': 4, 'SA(1)': 5}
>>> g
round_motion_type_index_map
{'
gmv_
PGA': 2, '
gmv_
SA(0.3)': 3, '
gmv_
SA(0.6)': 4, '
gmv_
SA(1)': 5}
- taxonomy_to_fragility_source: (csv.reader)
taxonomy to fragility-function file map following the format:
...
...
@@ -155,23 +157,32 @@ def taxonomy_to_fragility(gmDict, taxonomy_to_fragility_source, fragility_pathna
# Prepare return variable
taxonomy_to_fragility_map
=
{}
# Loop through the taxonomy-to-fragility-function map
for
mapping_item
in
taxonomy_to_fragility_source
:
for
taxonomy_map_entry
in
taxonomy_to_fragility_source
:
# Open the fragility-function file corresponding to the taxonomy in
# '
mapping_item
[1]'
fragility
F
unction
=
list
(
csv
.
reader
(
open
(
fragility_pathname
+
"/"
+
mapping_item
[
1
]
+
".csv"
))
# '
taxonomy_map_entry
[1]'
fragility
_f
unction
=
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
if
mapping_item
[
0
]
in
taxonomy_to_fragility_map
:
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 'fragilityFunction[0][0]'
taxonomy_to_fragility_map
[
mapping_item
[
0
]]
=
[
mapping_item
[
1
],
gmDict
[
fragilityFunction
[
0
][
0
]],
# motion 'fragility_function[0][0]'
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
]],
]
return
taxonomy_to_fragility_map
...
...
@@ -309,9 +320,10 @@ def get_PoEs(fragility_function, gm_value):
2.152E-02
- fragility_function: (Numpy nd-array of shape (5,100) in our case;
An array of 5 records with values of Intensity measure levels, values
of slight, moderate, extensive and complete damage probabilities of
exceedance, as the first to 5th records respectively.)
An array with different levels of a ground_motion type as its first record
and probabilities of exceeding slight, moderate, extensive and complete damage states
corresponding to each level as the 2nd to 5th record.
Example extract:
>>> fragility_function
array([
...
...
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