Commit a086fcaf authored by Tara Evaz Zadeh's avatar Tara Evaz Zadeh

Replaced the word polygon with geometry

parent f763cb33
Pipeline #18274 passed with stage
in 1 minute and 25 seconds
......@@ -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.
......
......@@ -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]
......
......@@ -31,7 +31,7 @@ def get_exposure_per_tile(
fragility_pathname,
taxonomy_conversion_filepath,
shakemap_filepath,
polygonSource_filepath,
geometry_source_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,
polygonSource_filepath,
geometry_source_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
polygonSource_filepath = args.polygons
geometry_source_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,
polygonSource_filepath,
geometry_source_filepath,
cellIdSource_filepath,
exposure_type,
interpolation_method,
......
......@@ -30,7 +30,7 @@ def damageCalculator_TileVersion(
exposures,
taxonomy_conversion_path,
shakemap_path,
polygonSource_path,
geometry_source_path,
exposureType="cell",
method="linear",
):
......@@ -104,11 +104,11 @@ def damageCalculator_TileVersion(
>>> shakemap_path
"/home/TileCalculations/shakemap1381_2.csv"
- polygonSource_path: (str)
Address to the file including the origin-ids and thir respecive polygons
- geometry_source_path: (str)
Address to the file including the origin-ids and their respecive polygons
(Could be whether each tile oan OSM building).
Example extract:
>>> polygonSource_path
>>> geometry_source_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)
PolygonSource = csv.reader(open(polygonSource_path), delimiter=";")
geometry_source = csv.reader(open(geometry_source_path), delimiter=";")
# Skip the header
next(PolygonSource, None)
next(geometry_source, 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 "OriginId_to_Polygon" to get a dictionary with keys as the origin_id
# and the value as the respective polygon.
OriginIdToPolygonMap = losslib.OriginId_to_Polygon(PolygonSource, exposureType)
# Calling the function "origin_id_to_geometry" to get a dictionary with keys as the
# origin_id and the value as the respective polygon.
origin_id_to_geometry_map = losslib.origin_id_to_geometry(geometry_source, 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] = OriginIdToPolygonMap[origin_id]
[geometry, RespectiveCellid] = origin_id_to_geometry_map[origin_id]
else:
polygon = OriginIdToPolygonMap[origin_id]
geometry = origin_id_to_geometry_map[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,
"",
......
......@@ -31,7 +31,7 @@ def main(
exposures_path,
taxonomy_conversion_path,
shakemap_path,
polygonSource_path,
geometry_source_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)
PolygonSource = csv.reader(open(polygonSource_path), delimiter=";")
next(PolygonSource, None)
geometry_source = csv.reader(open(geometry_source_path), delimiter=";")
next(geometry_source, 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
)
OriginIdToPolygonMap = losslib.OriginId_to_Polygon(PolygonSource, exposureType)
origin_id_to_geometry_map = losslib.origin_id_to_geometry(geometry_source, 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] = OriginIdToPolygonMap[origin_id]
[polygon, relativeCellid] = origin_id_to_geometry_map[origin_id]
else:
polygon = OriginIdToPolygonMap[origin_id]
polygon = origin_id_to_geometry_map[origin_id]
# Find new taxonomy names
fragility_function = np.loadtxt(
......
......@@ -174,28 +174,28 @@ def Taxonomy_to_Fragility(gmDict, taxonomyToFragilitySource, fragilityFileDir):
return taxonomyToFragilityMap
def OriginId_to_Polygon(PolygonSource, exposureType):
def origin_id_to_geometry(geometry_source, exposureType):
"""
Creates a dictionary of Origin-ids and their polygons.
The input map 'PolygonSource' contains the mapping for each
Origin-id to a polygon along with its Cell-id if it's an OBM polygon source
as the 'OriginIdToPolygonMap'.
The input map 'geometry_source' contains the mapping for each
Origin-id to a polygon along with its Cell-id if it's an OBM geometry source
as the 'origin_id_to_geometry_map'.
Input:
------
- exposureType: (string)
Either 'OBM' or 'cell'
- PolygonSource: (csv.reader)
Origin-id to polygons file map with semicolon as the delimiter,
- geometry_source: (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:
>>> PolygonSource
if you have cell geometry source:
>>> geometry_source
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:
>>> PolygonSource
if you have OBM geometry source:
>>> geometry_source
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 polygonSource has more
please note that it doesn't matter if your input geometry_source 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:
------
- OriginIdToPolygonMap: (Dictionary)
- origin_id_to_geometry_map: (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 defines cells:
{OriginID_string: [geometry]}
Example extract:
>>> OriginIdToPolygonMap
>>> origin_id_to_geometry_map
{'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 defines buildings:
{OriginID_string: [geometry, CellID]}
Example extract:
>>> OriginIdToPolygonMap
>>> origin_id_to_geometry_map
{'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 polygonSource does not have to
Please Note that the first columns of the geometry_source 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
OriginIdToPolygonMap = {}
# 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
origin_id_to_geometry_map = {}
# 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 originId_to_polygon map
for polygonMappingItem in PolygonSource:
# Check if already one polygon for a given OriginId has been
# Loop through the origin_id_to_geometry map
for geometry_mapping_item in geometry_source:
# Check if already one geometry for a given OriginId has been
# selected.
if polygonMappingItem[0] in OriginIdToPolygonMap:
# Ignore the additional polygon to keep everything unambiguous
if geometry_mapping_item[0] in origin_id_to_geometry_map:
# 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 ('polygonMappingItem[2]')
OriginIdToPolygonMap[polygonMappingItem[0]] = [
polygonMappingItem[1],
polygonMappingItem[2],
# The building belongs to ('geometry_mapping_item[2]')
origin_id_to_geometry_map[geometry_mapping_item[0]] = [
geometry_mapping_item[1],
geometry_mapping_item[2],
]
else:
for polygonMappingItem in PolygonSource:
if polygonMappingItem[0] in OriginIdToPolygonMap:
# Implement your duplicate row(polygonMappingItem) handling here
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
OriginIdToPolygonMap[polygonMappingItem[0]] = polygonMappingItem[1]
return OriginIdToPolygonMap
origin_id_to_geometry_map[geometry_mapping_item[0]] = geometry_mapping_item[1]
return origin_id_to_geometry_map
def get_PoEs(fragility_function, gm_value):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment