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
a086fcaf
Commit
a086fcaf
authored
Jan 15, 2021
by
Tara Evaz Zadeh
Browse files
Replaced the word polygon with geometry
parent
f763cb33
Pipeline
#18274
passed with stage
in 1 minute and 25 seconds
Changes
6
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
a086fcaf
...
...
@@ -35,7 +35,7 @@ Defines the pathname of the directory with all fragility-function files.
Defines the filepath of the ground-motion field.
`-p`
,
`--
polygonSource-filepath
=filepath`
`-p`
,
`--
geometry
=filepath`
Defines the filepath of the polygon definitions.
...
...
losscalculator/add_cellids_to_OBM_exposure_files.py
View file @
a086fcaf
...
...
@@ -57,7 +57,7 @@ def AddRespectiveCellIdToOBMExposureFiles(exposureFile_path, OSMSource_path, Res
OSMIdToCellId
=
{}
for
MappingItem
in
OSMSource
:
if
MappingItem
[
0
]
in
OSMIdToCellId
:
# Ignore the additional
polygon
to keep everything unambiguous
# Ignore the additional
geometry
to keep everything unambiguous
pass
OSMIdToCellId
[
MappingItem
[
0
]]
=
MappingItem
[
2
]
...
...
losscalculator/damage_calculator.py
View file @
a086fcaf
...
...
@@ -31,7 +31,7 @@ def get_exposure_per_tile(
fragility_pathname
,
taxonomy_conversion_filepath
,
shakemap_filepath
,
polygonS
ource_filepath
,
geometry_s
ource_filepath
,
cellIdSource_filepath
,
exposure_type
=
"cell"
,
interpolation_method
=
"linear"
,
...
...
@@ -137,7 +137,7 @@ def get_exposure_per_tile(
exposure_per_tile
,
taxonomy_conversion_filepath
,
shakemap_filepath
,
polygonS
ource_filepath
,
geometry_s
ource_filepath
,
exposure_type
,
interpolation_method
,
)
...
...
@@ -215,7 +215,7 @@ if __name__ == "__main__":
)
parser
.
add_argument
(
"-p"
,
"--
polygons
"
,
"--
geometry
"
,
required
=
True
,
type
=
str
,
help
=
"path to the file that includes the origin-ids of either your tiles "
...
...
@@ -251,7 +251,7 @@ if __name__ == "__main__":
shakemap_filepath
=
args
.
ground_motion_field
cellIdSource_filepath
=
args
.
cell_ids
exposure_filepath
=
args
.
exposure
polygonS
ource_filepath
=
args
.
polygons
geometry_s
ource_filepath
=
args
.
geometry
result_filepath
=
args
.
results
overwrite_result_file
=
args
.
overwrite
...
...
@@ -270,7 +270,7 @@ if __name__ == "__main__":
fragility_pathname
,
taxonomy_conversion_filepath
,
shakemap_filepath
,
polygonS
ource_filepath
,
geometry_s
ource_filepath
,
cellIdSource_filepath
,
exposure_type
,
interpolation_method
,
...
...
losscalculator/damage_calculator_tile_version.py
View file @
a086fcaf
...
...
@@ -30,7 +30,7 @@ def damageCalculator_TileVersion(
exposures
,
taxonomy_conversion_path
,
shakemap_path
,
polygonS
ource_path
,
geometry_s
ource_path
,
exposureType
=
"cell"
,
method
=
"linear"
,
):
...
...
@@ -104,11 +104,11 @@ def damageCalculator_TileVersion(
>>> shakemap_path
"/home/TileCalculations/shakemap1381_2.csv"
-
polygonS
ource_path: (str)
Address to the file including the origin-ids and thir respecive polygons
-
geometry_s
ource_path: (str)
Address to the file including the origin-ids and th
e
ir respecive polygons
(Could be whether each tile oan OSM building).
Example extract:
>>>
polygonS
ource_path
>>>
geometry_s
ource_path
"/home/TileCalculations
/M008_exposure_Attica_GDE_visual_v001_sat_27f_by_cell_reOrder.csv"
...
...
@@ -123,7 +123,7 @@ def damageCalculator_TileVersion(
- Result_path: (arrays written to file)
file containing the damage elements for each asset of the exposure.
Example extract of the result file:
polygon
,,origin_id,,asset_id,,lon,,lat,,taxonomy,,gmfValue,,PoEs,,PoOs,,
geometry
,,origin_id,,asset_id,,lon,,lat,,taxonomy,,gmfValue,,PoEs,,PoOs,,
tot_num_buildings,,structural_No-damage,,structural_Slight,,structural_Moderate,,
structural_Extensive,,structural_Complete
"POLYGON ((23.68611111111113 38.3388888888889, 23.6888888888889 38.3388888888889,
...
...
@@ -145,9 +145,9 @@ def damageCalculator_TileVersion(
taxonomyToFragilitySource
=
csv
.
reader
(
open
(
taxonomy_conversion_path
))
# Skip the header
next
(
taxonomyToFragilitySource
,
None
)
PolygonS
ource
=
csv
.
reader
(
open
(
polygonS
ource_path
),
delimiter
=
";"
)
geometry_s
ource
=
csv
.
reader
(
open
(
geometry_s
ource_path
),
delimiter
=
";"
)
# Skip the header
next
(
PolygonS
ource
,
None
)
next
(
geometry_s
ource
,
None
)
# Read each column of the input "exposure"
taxonomies
=
exposures
.
taxonomy
...
...
@@ -173,9 +173,9 @@ def damageCalculator_TileVersion(
taxonomyToFragilityMap
=
losslib
.
Taxonomy_to_Fragility
(
gmDict
,
taxonomyToFragilitySource
,
fragilityFileDir
)
# Calling the function "
O
rigin
I
d_to_
Polygon
" to get a dictionary with keys as the
origin_id
# and the value as the respective polygon.
O
rigin
IdToPolygonM
ap
=
losslib
.
O
rigin
I
d_to_
Polygon
(
PolygonS
ource
,
exposureType
)
# Calling the function "
o
rigin
_i
d_to_
geometry
" to get a dictionary with keys as the
#
origin_id
and the value as the respective polygon.
o
rigin
_id_to_geometry_m
ap
=
losslib
.
o
rigin
_i
d_to_
geometry
(
geometry_s
ource
,
exposureType
)
# Define number of columns that contain the data in the fragiliy function files.
cls
=
range
(
1
,
101
)
# Just a trick to have multiple commas between each result element, since we do
...
...
@@ -194,9 +194,9 @@ def damageCalculator_TileVersion(
# building is located in, referred as "RespectiveCellid" and the polygon of
# the buiding.
if
exposureType
==
"OBM"
:
[
polygon
,
RespectiveCellid
]
=
O
rigin
IdToPolygonM
ap
[
origin_id
]
[
geometry
,
RespectiveCellid
]
=
o
rigin
_id_to_geometry_m
ap
[
origin_id
]
else
:
polygon
=
O
rigin
IdToPolygonM
ap
[
origin_id
]
geometry
=
o
rigin
_id_to_geometry_m
ap
[
origin_id
]
# Read fragility functions as numpy arrays.
fragility_function
=
np
.
loadtxt
(
...
...
@@ -218,7 +218,7 @@ def damageCalculator_TileVersion(
# Append results
if
exposureType
==
"OBM"
:
arr0
=
[
polygon
,
geometry
,
""
,
origin_id
,
""
,
...
...
@@ -242,7 +242,7 @@ def damageCalculator_TileVersion(
]
else
:
arr0
=
[
polygon
,
geometry
,
""
,
origin_id
,
""
,
...
...
losscalculator/loss_calculator.py
View file @
a086fcaf
...
...
@@ -31,7 +31,7 @@ def main(
exposures_path
,
taxonomy_conversion_path
,
shakemap_path
,
polygonS
ource_path
,
geometry_s
ource_path
,
exposureType
,
method
,
):
...
...
@@ -46,8 +46,8 @@ def main(
groundMotionField
=
np
.
loadtxt
(
shakemap_path
,
delimiter
=
","
,
skiprows
=
1
)
taxonomyToFragilitySource
=
csv
.
reader
(
open
(
taxonomy_conversion_path
))
next
(
taxonomyToFragilitySource
,
None
)
PolygonS
ource
=
csv
.
reader
(
open
(
polygonS
ource_path
),
delimiter
=
";"
)
next
(
PolygonS
ource
,
None
)
geometry_s
ource
=
csv
.
reader
(
open
(
geometry_s
ource_path
),
delimiter
=
";"
)
next
(
geometry_s
ource
,
None
)
# Read Columns
taxonomies
=
exposures
.
taxonomy
...
...
@@ -66,7 +66,7 @@ def main(
if
exposureType
==
"OBM"
:
title
=
[
"
polygon
"
,
"
geometry
"
,
""
,
"origin_id"
,
""
,
...
...
@@ -101,7 +101,7 @@ def main(
else
:
title
=
[
"
polygon
"
,
"
geometry
"
,
""
,
"origin_id"
,
""
,
...
...
@@ -140,7 +140,7 @@ def main(
taxonomyToFragilityMap
=
losslib
.
Taxonomy_to_Fragility
(
gmDict
,
taxonomyToFragilitySource
,
fragilityFileDir
)
O
rigin
IdToPolygonM
ap
=
losslib
.
O
rigin
I
d_to_
Polygon
(
PolygonS
ource
,
exposureType
)
o
rigin
_id_to_geometry_m
ap
=
losslib
.
o
rigin
_i
d_to_
geometry
(
geometry_s
ource
,
exposureType
)
# Number of columns that contain the data in the fragiliy function files
cls
=
range
(
1
,
101
)
a
=
[
0
,
2
,
4
,
6
,
8
]
...
...
@@ -153,9 +153,9 @@ def main(
asset_id
=
assetids
[
asset
]
origin_id
=
originids
[
asset
]
if
exposureType
==
"OBM"
:
[
polygon
,
relativeCellid
]
=
O
rigin
IdToPolygonM
ap
[
origin_id
]
[
polygon
,
relativeCellid
]
=
o
rigin
_id_to_geometry_m
ap
[
origin_id
]
else
:
polygon
=
O
rigin
IdToPolygonM
ap
[
origin_id
]
polygon
=
o
rigin
_id_to_geometry_m
ap
[
origin_id
]
# Find new taxonomy names
fragility_function
=
np
.
loadtxt
(
...
...
losscalculator/losslib.py
View file @
a086fcaf
...
...
@@ -174,28 +174,28 @@ def Taxonomy_to_Fragility(gmDict, taxonomyToFragilitySource, fragilityFileDir):
return
taxonomyToFragilityMap
def
O
rigin
I
d_to_
Polygon
(
PolygonS
ource
,
exposureType
):
def
o
rigin
_i
d_to_
geometry
(
geometry_s
ource
,
exposureType
):
"""
Creates a dictionary of Origin-ids and their polygons.
The input map '
PolygonS
ource' contains the mapping for each
Origin-id to a polygon along with its Cell-id if it's an OBM
polygon
source
as the '
O
rigin
IdToPolygonM
ap'.
The input map '
geometry_s
ource' contains the mapping for each
Origin-id to a polygon along with its Cell-id if it's an OBM
geometry
source
as the '
o
rigin
_id_to_geometry_m
ap'.
Input:
------
- exposureType: (string)
Either 'OBM' or 'cell'
-
PolygonS
ource: (csv.reader)
Origin-id to
polygons
file map with semicolon as the delimiter,
-
geometry_s
ource: (csv.reader)
Origin-id to
geometry
file map with semicolon as the delimiter,
following the format:
['OriginID'; '
Polygon
'; 'cell_ID']. 'cell_ID' would only be available if
your input
polygon
belongs to the OBM data(single buildings). 'cell_ID'
here points to the cell that contains the
polygon
.
['OriginID'; '
geometry
'; 'cell_ID']. 'cell_ID' would only be available if
your input
geometry
belongs to the OBM data(single buildings). 'cell_ID'
here points to the cell that contains the
geometry
.
Example extract:
if you have cell
polygon
source:
>>>
PolygonS
ource
if you have cell
geometry
source:
>>>
geometry_s
ource
cell_2410244527;POLYGON ((23.6861 38.3389,
23.6889 38.3389, 23.6889 38.34167,
23.6861 38.3417, 23.6861 38.3389))
...
...
@@ -204,8 +204,8 @@ def OriginId_to_Polygon(PolygonSource, exposureType):
23.6889 38.3416, 23.6889 38.3389))
...
if you have OBM
polygon
source:
>>>
PolygonS
ource
if you have OBM
geometry
source:
>>>
geometry_s
ource
OSM_517924352;POLYGON((2641289.2688 4582010.1248,2641299.6772
4582007.1292,2641304.1745 4582019.8887,2641294.4229
4582023.4778,2641291.5175 4582013.4736,2641290.5490
...
...
@@ -215,7 +215,7 @@ def OriginId_to_Polygon(PolygonSource, exposureType):
4559661.68,2647123.74 4559674.98));cell_2432665360
...
please note that it doesn't matter if your input
polygonS
ource has more
please note that it doesn't matter if your input
geometry_s
ource has more
columns than needed. But the first columns should be as sited above.
The first column does not necessarily have to start with OSM or cell. It
only needs to have the same format as this column has in the exposure
...
...
@@ -224,16 +224,16 @@ def OriginId_to_Polygon(PolygonSource, exposureType):
Output:
------
-
O
rigin
IdToPolygonM
ap: (Dictionary)
-
o
rigin
_id_to_geometry_m
ap: (Dictionary)
contains the origin-id to polygons items.
(If the
polygons
show single buildings, the dictionary also considers
(If the
geometry
show single buildings, the dictionary also considers
their cell-IDs ) following the format below:
When
polygons
define cells:
{OriginID_string: [
Polygon
]}
When
geometry
define
s
cells:
{OriginID_string: [
geometry
]}
Example extract:
>>>
O
rigin
IdToPolygonM
ap
>>>
o
rigin
_id_to_geometry_m
ap
{'cell_2410244527': 'POLYGON ((23.6861 38.33889,
23.6889 38.3389, 23.6889 38.3416,
23.6861 38.3416, 23.6861 38.3389))'
...
...
@@ -243,11 +243,11 @@ def OriginId_to_Polygon(PolygonSource, exposureType):
... }
In case the
polygons
define buildings:
{OriginID_string: [
Polygon
, CellID]}
In case the
geometry
define
s
buildings:
{OriginID_string: [
geometry
, CellID]}
Example extract:
>>>
O
rigin
IdToPolygonM
ap
>>>
o
rigin
_id_to_geometry_m
ap
{'OSM_517924352': ['POLYGON((2641289.2688 4582010.1248,
2641299.6772 4582007.1292,2641304.1745 4582019.8887,
2641294.4229 4582023.4778,2641291.5175 4582013.4736,
...
...
@@ -258,37 +258,37 @@ def OriginId_to_Polygon(PolygonSource, exposureType):
2647133.5 4559661.68 ,2647123.74 4559674.98))', 'cell_2432665360'], ...}
Please Note that the first columns of the
polygonS
ource does not have to
Please Note that the first columns of the
geometry_s
ource does not have to
have the same format as either "OSM_517924352" or "cell_2410244527", but
the id have to have the same format as "origin_id" column of the exposure
input file.
"""
# Prepare return variable
O
rigin
IdToPolygonM
ap
=
{}
# to know if the
polygons
refers to single buildings instead of cells.
# In this case we need to also know the cell_ID that this building
polygon
o
rigin
_id_to_geometry_m
ap
=
{}
# to know if the
geometry
refers to single buildings instead of cells.
# In this case we need to also know the cell_ID that this building
geometry
# is located in.
if
exposureType
==
"OBM"
:
# Loop through the origin
I
d_to_
polygon
map
for
polygonM
apping
I
tem
in
PolygonS
ource
:
# Check if already one
polygon
for a given OriginId has been
# Loop through the origin
_i
d_to_
geometry
map
for
geometry_m
apping
_i
tem
in
geometry_s
ource
:
# Check if already one
geometry
for a given OriginId has been
# selected.
if
polygonM
apping
I
tem
[
0
]
in
O
rigin
IdToPolygonM
ap
:
# Ignore the additional
polygon
to keep everything unambiguous
if
geometry_m
apping
_i
tem
[
0
]
in
o
rigin
_id_to_geometry_m
ap
:
# Ignore the additional
geometry
to keep everything unambiguous
pass
# Create the entry in the extended map with adding the cell-ID that
# The building belongs to ('
polygonM
apping
I
tem[2]')
O
rigin
IdToPolygonMap
[
polygonM
apping
I
tem
[
0
]]
=
[
polygonM
apping
I
tem
[
1
],
polygonM
apping
I
tem
[
2
],
# The building belongs to ('
geometry_m
apping
_i
tem[2]')
o
rigin
_id_to_geometry_map
[
geometry_m
apping
_i
tem
[
0
]]
=
[
geometry_m
apping
_i
tem
[
1
],
geometry_m
apping
_i
tem
[
2
],
]
else
:
for
polygonM
apping
I
tem
in
PolygonS
ource
:
if
polygonM
apping
I
tem
[
0
]
in
O
rigin
IdToPolygonM
ap
:
# Implement your duplicate row(
polygonM
apping
I
tem) handling here
for
geometry_m
apping
_i
tem
in
geometry_s
ource
:
if
geometry_m
apping
_i
tem
[
0
]
in
o
rigin
_id_to_geometry_m
ap
:
# Implement your duplicate row(
geometry_m
apping
_i
tem) handling here
pass
O
rigin
IdToPolygonMap
[
polygonM
apping
I
tem
[
0
]]
=
polygonM
apping
I
tem
[
1
]
return
O
rigin
IdToPolygonM
ap
o
rigin
_id_to_geometry_map
[
geometry_m
apping
_i
tem
[
0
]]
=
geometry_m
apping
_i
tem
[
1
]
return
o
rigin
_id_to_geometry_m
ap
def
get_PoEs
(
fragility_function
,
gm_value
):
...
...
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