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

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. ...@@ -35,7 +35,7 @@ Defines the pathname of the directory with all fragility-function files.
Defines the filepath of the ground-motion field. Defines the filepath of the ground-motion field.
`-p`, `--polygonSource-filepath=filepath` `-p`, `--geometry=filepath`
Defines the filepath of the polygon definitions. Defines the filepath of the polygon definitions.
......
...@@ -57,7 +57,7 @@ def AddRespectiveCellIdToOBMExposureFiles(exposureFile_path, OSMSource_path, Res ...@@ -57,7 +57,7 @@ def AddRespectiveCellIdToOBMExposureFiles(exposureFile_path, OSMSource_path, Res
OSMIdToCellId = {} OSMIdToCellId = {}
for MappingItem in OSMSource: for MappingItem in OSMSource:
if MappingItem[0] in OSMIdToCellId: if MappingItem[0] in OSMIdToCellId:
# Ignore the additional polygon to keep everything unambiguous # Ignore the additional geometry to keep everything unambiguous
pass pass
OSMIdToCellId[MappingItem[0]] = MappingItem[2] OSMIdToCellId[MappingItem[0]] = MappingItem[2]
......
...@@ -31,7 +31,7 @@ def get_exposure_per_tile( ...@@ -31,7 +31,7 @@ def get_exposure_per_tile(
fragility_pathname, fragility_pathname,
taxonomy_conversion_filepath, taxonomy_conversion_filepath,
shakemap_filepath, shakemap_filepath,
polygonSource_filepath, geometry_source_filepath,
cellIdSource_filepath, cellIdSource_filepath,
exposure_type="cell", exposure_type="cell",
interpolation_method="linear", interpolation_method="linear",
...@@ -137,7 +137,7 @@ def get_exposure_per_tile( ...@@ -137,7 +137,7 @@ def get_exposure_per_tile(
exposure_per_tile, exposure_per_tile,
taxonomy_conversion_filepath, taxonomy_conversion_filepath,
shakemap_filepath, shakemap_filepath,
polygonSource_filepath, geometry_source_filepath,
exposure_type, exposure_type,
interpolation_method, interpolation_method,
) )
...@@ -215,7 +215,7 @@ if __name__ == "__main__": ...@@ -215,7 +215,7 @@ if __name__ == "__main__":
) )
parser.add_argument( parser.add_argument(
"-p", "-p",
"--polygons", "--geometry",
required=True, required=True,
type=str, type=str,
help="path to the file that includes the origin-ids of either your tiles " help="path to the file that includes the origin-ids of either your tiles "
...@@ -251,7 +251,7 @@ if __name__ == "__main__": ...@@ -251,7 +251,7 @@ if __name__ == "__main__":
shakemap_filepath = args.ground_motion_field shakemap_filepath = args.ground_motion_field
cellIdSource_filepath = args.cell_ids cellIdSource_filepath = args.cell_ids
exposure_filepath = args.exposure exposure_filepath = args.exposure
polygonSource_filepath = args.polygons geometry_source_filepath = args.geometry
result_filepath = args.results result_filepath = args.results
overwrite_result_file = args.overwrite overwrite_result_file = args.overwrite
...@@ -270,7 +270,7 @@ if __name__ == "__main__": ...@@ -270,7 +270,7 @@ if __name__ == "__main__":
fragility_pathname, fragility_pathname,
taxonomy_conversion_filepath, taxonomy_conversion_filepath,
shakemap_filepath, shakemap_filepath,
polygonSource_filepath, geometry_source_filepath,
cellIdSource_filepath, cellIdSource_filepath,
exposure_type, exposure_type,
interpolation_method, interpolation_method,
......
...@@ -30,7 +30,7 @@ def damageCalculator_TileVersion( ...@@ -30,7 +30,7 @@ def damageCalculator_TileVersion(
exposures, exposures,
taxonomy_conversion_path, taxonomy_conversion_path,
shakemap_path, shakemap_path,
polygonSource_path, geometry_source_path,
exposureType="cell", exposureType="cell",
method="linear", method="linear",
): ):
...@@ -104,11 +104,11 @@ def damageCalculator_TileVersion( ...@@ -104,11 +104,11 @@ def damageCalculator_TileVersion(
>>> shakemap_path >>> shakemap_path
"/home/TileCalculations/shakemap1381_2.csv" "/home/TileCalculations/shakemap1381_2.csv"
- polygonSource_path: (str) - geometry_source_path: (str)
Address to the file including the origin-ids and thir respecive polygons Address to the file including the origin-ids and their respecive polygons
(Could be whether each tile oan OSM building). (Could be whether each tile oan OSM building).
Example extract: Example extract:
>>> polygonSource_path >>> geometry_source_path
"/home/TileCalculations "/home/TileCalculations
/M008_exposure_Attica_GDE_visual_v001_sat_27f_by_cell_reOrder.csv" /M008_exposure_Attica_GDE_visual_v001_sat_27f_by_cell_reOrder.csv"
...@@ -123,7 +123,7 @@ def damageCalculator_TileVersion( ...@@ -123,7 +123,7 @@ def damageCalculator_TileVersion(
- Result_path: (arrays written to file) - Result_path: (arrays written to file)
file containing the damage elements for each asset of the exposure. file containing the damage elements for each asset of the exposure.
Example extract of the result file: 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,, tot_num_buildings,,structural_No-damage,,structural_Slight,,structural_Moderate,,
structural_Extensive,,structural_Complete structural_Extensive,,structural_Complete
"POLYGON ((23.68611111111113 38.3388888888889, 23.6888888888889 38.3388888888889, "POLYGON ((23.68611111111113 38.3388888888889, 23.6888888888889 38.3388888888889,
...@@ -145,9 +145,9 @@ def damageCalculator_TileVersion( ...@@ -145,9 +145,9 @@ def damageCalculator_TileVersion(
taxonomyToFragilitySource = csv.reader(open(taxonomy_conversion_path)) taxonomyToFragilitySource = csv.reader(open(taxonomy_conversion_path))
# Skip the header # Skip the header
next(taxonomyToFragilitySource, None) next(taxonomyToFragilitySource, None)
PolygonSource = csv.reader(open(polygonSource_path), delimiter=";") geometry_source = csv.reader(open(geometry_source_path), delimiter=";")
# Skip the header # Skip the header
next(PolygonSource, None) next(geometry_source, None)
# Read each column of the input "exposure" # Read each column of the input "exposure"
taxonomies = exposures.taxonomy taxonomies = exposures.taxonomy
...@@ -173,9 +173,9 @@ def damageCalculator_TileVersion( ...@@ -173,9 +173,9 @@ def damageCalculator_TileVersion(
taxonomyToFragilityMap = losslib.Taxonomy_to_Fragility( taxonomyToFragilityMap = losslib.Taxonomy_to_Fragility(
gmDict, taxonomyToFragilitySource, fragilityFileDir gmDict, taxonomyToFragilitySource, fragilityFileDir
) )
# Calling the function "OriginId_to_Polygon" to get a dictionary with keys as the origin_id # Calling the function "origin_id_to_geometry" to get a dictionary with keys as the
# and the value as the respective polygon. # origin_id and the value as the respective polygon.
OriginIdToPolygonMap = losslib.OriginId_to_Polygon(PolygonSource, exposureType) 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. # Define number of columns that contain the data in the fragiliy function files.
cls = range(1, 101) cls = range(1, 101)
# Just a trick to have multiple commas between each result element, since we do # Just a trick to have multiple commas between each result element, since we do
...@@ -194,9 +194,9 @@ def damageCalculator_TileVersion( ...@@ -194,9 +194,9 @@ def damageCalculator_TileVersion(
# building is located in, referred as "RespectiveCellid" and the polygon of # building is located in, referred as "RespectiveCellid" and the polygon of
# the buiding. # the buiding.
if exposureType == "OBM": if exposureType == "OBM":
[polygon, RespectiveCellid] = OriginIdToPolygonMap[origin_id] [geometry, RespectiveCellid] = origin_id_to_geometry_map[origin_id]
else: else:
polygon = OriginIdToPolygonMap[origin_id] geometry = origin_id_to_geometry_map[origin_id]
# Read fragility functions as numpy arrays. # Read fragility functions as numpy arrays.
fragility_function = np.loadtxt( fragility_function = np.loadtxt(
...@@ -218,7 +218,7 @@ def damageCalculator_TileVersion( ...@@ -218,7 +218,7 @@ def damageCalculator_TileVersion(
# Append results # Append results
if exposureType == "OBM": if exposureType == "OBM":
arr0 = [ arr0 = [
polygon, geometry,
"", "",
origin_id, origin_id,
"", "",
...@@ -242,7 +242,7 @@ def damageCalculator_TileVersion( ...@@ -242,7 +242,7 @@ def damageCalculator_TileVersion(
] ]
else: else:
arr0 = [ arr0 = [
polygon, geometry,
"", "",
origin_id, origin_id,
"", "",
......
...@@ -31,7 +31,7 @@ def main( ...@@ -31,7 +31,7 @@ def main(
exposures_path, exposures_path,
taxonomy_conversion_path, taxonomy_conversion_path,
shakemap_path, shakemap_path,
polygonSource_path, geometry_source_path,
exposureType, exposureType,
method, method,
): ):
...@@ -46,8 +46,8 @@ def main( ...@@ -46,8 +46,8 @@ def main(
groundMotionField = np.loadtxt(shakemap_path, delimiter=",", skiprows=1) groundMotionField = np.loadtxt(shakemap_path, delimiter=",", skiprows=1)
taxonomyToFragilitySource = csv.reader(open(taxonomy_conversion_path)) taxonomyToFragilitySource = csv.reader(open(taxonomy_conversion_path))
next(taxonomyToFragilitySource, None) next(taxonomyToFragilitySource, None)
PolygonSource = csv.reader(open(polygonSource_path), delimiter=";") geometry_source = csv.reader(open(geometry_source_path), delimiter=";")
next(PolygonSource, None) next(geometry_source, None)
# Read Columns # Read Columns
taxonomies = exposures.taxonomy taxonomies = exposures.taxonomy
...@@ -66,7 +66,7 @@ def main( ...@@ -66,7 +66,7 @@ def main(
if exposureType == "OBM": if exposureType == "OBM":
title = [ title = [
"polygon", "geometry",
"", "",
"origin_id", "origin_id",
"", "",
...@@ -101,7 +101,7 @@ def main( ...@@ -101,7 +101,7 @@ def main(
else: else:
title = [ title = [
"polygon", "geometry",
"", "",
"origin_id", "origin_id",
"", "",
...@@ -140,7 +140,7 @@ def main( ...@@ -140,7 +140,7 @@ def main(
taxonomyToFragilityMap = losslib.Taxonomy_to_Fragility( taxonomyToFragilityMap = losslib.Taxonomy_to_Fragility(
gmDict, taxonomyToFragilitySource, fragilityFileDir 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 # Number of columns that contain the data in the fragiliy function files
cls = range(1, 101) cls = range(1, 101)
a = [0, 2, 4, 6, 8] a = [0, 2, 4, 6, 8]
...@@ -153,9 +153,9 @@ def main( ...@@ -153,9 +153,9 @@ def main(
asset_id = assetids[asset] asset_id = assetids[asset]
origin_id = originids[asset] origin_id = originids[asset]
if exposureType == "OBM": if exposureType == "OBM":
[polygon, relativeCellid] = OriginIdToPolygonMap[origin_id] [polygon, relativeCellid] = origin_id_to_geometry_map[origin_id]
else: else:
polygon = OriginIdToPolygonMap[origin_id] polygon = origin_id_to_geometry_map[origin_id]
# Find new taxonomy names # Find new taxonomy names
fragility_function = np.loadtxt( fragility_function = np.loadtxt(
......
...@@ -174,28 +174,28 @@ def Taxonomy_to_Fragility(gmDict, taxonomyToFragilitySource, fragilityFileDir): ...@@ -174,28 +174,28 @@ def Taxonomy_to_Fragility(gmDict, taxonomyToFragilitySource, fragilityFileDir):
return taxonomyToFragilityMap 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. Creates a dictionary of Origin-ids and their polygons.
The input map 'PolygonSource' contains the mapping for each 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 polygon source Origin-id to a polygon along with its Cell-id if it's an OBM geometry source
as the 'OriginIdToPolygonMap'. as the 'origin_id_to_geometry_map'.
Input: Input:
------ ------
- exposureType: (string) - exposureType: (string)
Either 'OBM' or 'cell' Either 'OBM' or 'cell'
- PolygonSource: (csv.reader) - geometry_source: (csv.reader)
Origin-id to polygons file map with semicolon as the delimiter, Origin-id to geometry file map with semicolon as the delimiter,
following the format: following the format:
['OriginID'; 'Polygon'; 'cell_ID']. 'cell_ID' would only be available if ['OriginID'; 'geometry'; 'cell_ID']. 'cell_ID' would only be available if
your input polygon belongs to the OBM data(single buildings). 'cell_ID' your input geometry belongs to the OBM data(single buildings). 'cell_ID'
here points to the cell that contains the polygon. here points to the cell that contains the geometry.
Example extract: Example extract:
if you have cell polygon source: if you have cell geometry source:
>>> PolygonSource >>> geometry_source
cell_2410244527;POLYGON ((23.6861 38.3389, cell_2410244527;POLYGON ((23.6861 38.3389,
23.6889 38.3389, 23.6889 38.34167, 23.6889 38.3389, 23.6889 38.34167,
23.6861 38.3417, 23.6861 38.3389)) 23.6861 38.3417, 23.6861 38.3389))
...@@ -204,8 +204,8 @@ def OriginId_to_Polygon(PolygonSource, exposureType): ...@@ -204,8 +204,8 @@ def OriginId_to_Polygon(PolygonSource, exposureType):
23.6889 38.3416, 23.6889 38.3389)) 23.6889 38.3416, 23.6889 38.3389))
... ...
if you have OBM polygon source: if you have OBM geometry source:
>>> PolygonSource >>> geometry_source
OSM_517924352;POLYGON((2641289.2688 4582010.1248,2641299.6772 OSM_517924352;POLYGON((2641289.2688 4582010.1248,2641299.6772
4582007.1292,2641304.1745 4582019.8887,2641294.4229 4582007.1292,2641304.1745 4582019.8887,2641294.4229
4582023.4778,2641291.5175 4582013.4736,2641290.5490 4582023.4778,2641291.5175 4582013.4736,2641290.5490
...@@ -215,7 +215,7 @@ def OriginId_to_Polygon(PolygonSource, exposureType): ...@@ -215,7 +215,7 @@ def OriginId_to_Polygon(PolygonSource, exposureType):
4559661.68,2647123.74 4559674.98));cell_2432665360 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. 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 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 only needs to have the same format as this column has in the exposure
...@@ -224,16 +224,16 @@ def OriginId_to_Polygon(PolygonSource, exposureType): ...@@ -224,16 +224,16 @@ def OriginId_to_Polygon(PolygonSource, exposureType):
Output: Output:
------ ------
- OriginIdToPolygonMap: (Dictionary) - origin_id_to_geometry_map: (Dictionary)
contains the origin-id to polygons items. 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: their cell-IDs ) following the format below:
When polygons define cells: When geometry defines cells:
{OriginID_string: [Polygon]} {OriginID_string: [geometry]}
Example extract: Example extract:
>>> OriginIdToPolygonMap >>> origin_id_to_geometry_map
{'cell_2410244527': 'POLYGON ((23.6861 38.33889, {'cell_2410244527': 'POLYGON ((23.6861 38.33889,
23.6889 38.3389, 23.6889 38.3416, 23.6889 38.3389, 23.6889 38.3416,
23.6861 38.3416, 23.6861 38.3389))' 23.6861 38.3416, 23.6861 38.3389))'
...@@ -243,11 +243,11 @@ def OriginId_to_Polygon(PolygonSource, exposureType): ...@@ -243,11 +243,11 @@ def OriginId_to_Polygon(PolygonSource, exposureType):
... } ... }
In case the polygons define buildings: In case the geometry defines buildings:
{OriginID_string: [Polygon, CellID]} {OriginID_string: [geometry, CellID]}
Example extract: Example extract:
>>> OriginIdToPolygonMap >>> origin_id_to_geometry_map
{'OSM_517924352': ['POLYGON((2641289.2688 4582010.1248, {'OSM_517924352': ['POLYGON((2641289.2688 4582010.1248,
2641299.6772 4582007.1292,2641304.1745 4582019.8887, 2641299.6772 4582007.1292,2641304.1745 4582019.8887,
2641294.4229 4582023.4778,2641291.5175 4582013.4736, 2641294.4229 4582023.4778,2641291.5175 4582013.4736,
...@@ -258,37 +258,37 @@ def OriginId_to_Polygon(PolygonSource, exposureType): ...@@ -258,37 +258,37 @@ def OriginId_to_Polygon(PolygonSource, exposureType):
2647133.5 4559661.68 ,2647123.74 4559674.98))', 'cell_2432665360'], ...} 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 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 the id have to have the same format as "origin_id" column of the exposure
input file. input file.
""" """
# Prepare return variable # Prepare return variable
OriginIdToPolygonMap = {} origin_id_to_geometry_map = {}
# to know if the polygons refers to single buildings instead of cells. # 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 polygon # In this case we need to also know the cell_ID that this building geometry
# is located in. # is located in.
if exposureType == "OBM": if exposureType == "OBM":
# Loop through the originId_to_polygon map # Loop through the origin_id_to_geometry map
for polygonMappingItem in PolygonSource: for geometry_mapping_item in geometry_source:
# Check if already one polygon for a given OriginId has been # Check if already one geometry for a given OriginId has been
# selected. # selected.
if polygonMappingItem[0] in OriginIdToPolygonMap: if geometry_mapping_item[0] in origin_id_to_geometry_map:
# Ignore the additional polygon to keep everything unambiguous # Ignore the additional geometry to keep everything unambiguous
pass pass
# Create the entry in the extended map with adding the cell-ID that # Create the entry in the extended map with adding the cell-ID that
# The building belongs to ('polygonMappingItem[2]') # The building belongs to ('geometry_mapping_item[2]')
OriginIdToPolygonMap[polygonMappingItem[0]] = [ origin_id_to_geometry_map[geometry_mapping_item[0]] = [
polygonMappingItem[1], geometry_mapping_item[1],
polygonMappingItem[2], geometry_mapping_item[2],
] ]
else: else:
for polygonMappingItem in PolygonSource: for geometry_mapping_item in geometry_source:
if polygonMappingItem[0] in OriginIdToPolygonMap: if geometry_mapping_item[0] in origin_id_to_geometry_map:
# Implement your duplicate row(polygonMappingItem) handling here # Implement your duplicate row(geometry_mapping_item) handling here
pass pass
OriginIdToPolygonMap[polygonMappingItem[0]] = polygonMappingItem[1] origin_id_to_geometry_map[geometry_mapping_item[0]] = geometry_mapping_item[1]
return OriginIdToPolygonMap return origin_id_to_geometry_map
def get_PoEs(fragility_function, gm_value): def get_PoEs(fragility_function, gm_value):
......
Supports Markdown
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