Session 3: Assignment#
Perform building damage analysis with given earthquake and tornado hazards. Then compare the damages.
Please follow the instruction at each cell.
1. Create a local dataset of building inventory from CSV#
Please use “shelby_police_fire_stations.csv” file
# Import modlues
from pyincore import FragilityService, HazardService, IncoreClient, Dataset, MappingSet
from pyincore.analyses.buildingdamage import BuildingDamage
import pandas as pd
import geopandas as gpd
import json
# Connect to IN-CORE serivce by creating IncoreClient
client = IncoreClient()
Connection successful to IN-CORE services. pyIncore version detected: 0.9.3
# Initalize a FragilityService
fragility_services = FragilityService(client)
# TODO: Load CSV (shelby_police_fire_stations.csv) into GeoDataFrame
df = pd.read_csv('shelby_police_fire_stations.csv')
gdf = gpd.GeoDataFrame(df, crs='epsg:4326', geometry=gpd.points_from_xy(df.lon, df.lat))
# TODO: Export GeoDataFarme to ESRI Shapefile (stations.shp)
gdf.to_file("stations.shp")
# TODO: add GUID (output: stations_guid.shp)
from pyincore import GeoUtil
GeoUtil.add_guid("stations.shp", "stations_guid.shp")
True
# TODO: create a dataset boject with ESRI shapefile
local_buildings = Dataset.from_file("stations_guid.shp", data_type="ergo:buildingInventoryVer7")
2. Perform Building Damage analysis with an Earthquake#
Perform building damage analysis with the following input parameters and datasets
Hazard type: earthquake
Hazard ID: 5b902cb273c3371e1236b36b
Mapping ID: 5b47b350337d4a3629076f2c
# TODO: Define the variables that used for input parameters and datasets
hazard_type = "earthquake"
hazard_id = "5b902cb273c3371e1236b36b"
mapping_id = "5b47b350337d4a3629076f2c"
result_name = "stations_dmg"
# TODO: create fragility mapping object with id
eq_mapping_set = MappingSet(fragility_services.get_mapping(mapping_id))
# Create building damage
bldg_dmg_eq = BuildingDamage(client)
# TODO: Set up building damage analysis
bldg_dmg_eq.set_input_dataset("buildings", local_buildings)
bldg_dmg_eq.set_input_dataset("dfr3_mapping_set", eq_mapping_set)
bldg_dmg_eq.set_parameter("result_name", result_name)
bldg_dmg_eq.set_parameter("hazard_type", hazard_type)
bldg_dmg_eq.set_parameter("hazard_id", hazard_id)
bldg_dmg_eq.set_parameter("num_cpu", 1)
True
# TODO: run analysis
bldg_dmg_eq.run_analysis()
True
# TODO: Display the output of damage table by using DataFrame
eq_bldg_dmg_table = bldg_dmg_eq.get_output_dataset("ds_result").get_dataframe_from_csv()
eq_bldg_dmg_table
guid | LS_0 | LS_1 | LS_2 | DS_0 | DS_1 | DS_2 | DS_3 | |
---|---|---|---|---|---|---|---|---|
0 | 2cfb735a-a648-46af-8ef2-81758207b707 | 0.755346 | 0.222489 | 9.364605e-03 | 0.244654 | 0.532857 | 0.213125 | 9.364605e-03 |
1 | c8767706-f6da-409a-989f-f4061315b704 | 0.594377 | 0.090310 | 2.535863e-03 | 0.405623 | 0.504068 | 0.087774 | 2.535863e-03 |
2 | 2a24ea2e-49d8-4ef4-bc4d-f2593ce5581d | 0.792943 | 0.261558 | 1.302004e-02 | 0.207057 | 0.531385 | 0.248538 | 1.302004e-02 |
3 | 88c670b7-6ae3-4f46-8fcb-0390f26dbf37 | 0.979347 | 0.194344 | 3.000000e-10 | 0.020653 | 0.785002 | 0.194344 | 3.000000e-10 |
4 | 962c1fbd-0161-4e05-b68c-b67b20410832 | 0.618612 | 0.101007 | 3.077337e-03 | 0.381388 | 0.517605 | 0.097930 | 3.077337e-03 |
5 | bc2cf058-636f-4e48-a9d0-3294a74adc38 | 0.667402 | 0.126122 | 4.546865e-03 | 0.332598 | 0.541281 | 0.121575 | 4.546865e-03 |
6 | 142b316d-04c6-427b-b8a7-f572ac1fb8fe | 0.667402 | 0.126122 | 4.546865e-03 | 0.332598 | 0.541281 | 0.121575 | 4.546865e-03 |
7 | a1a3c33c-6936-4092-9d5b-64941ed8b1d6 | 0.667402 | 0.126122 | 4.546865e-03 | 0.332598 | 0.541281 | 0.121575 | 4.546865e-03 |
8 | a0a379d1-3ad3-45df-947b-ec8f8c51b0ee | 0.973078 | 0.697859 | 1.526643e-01 | 0.026922 | 0.275219 | 0.545195 | 1.526643e-01 |
9 | cb287985-862f-4b2a-b51f-7a88e4e1f8cf | 0.833515 | 0.271090 | 1.908092e-02 | 0.166485 | 0.562425 | 0.252009 | 1.908092e-02 |
10 | ce47cd50-59ef-4d38-bdf9-e2059850a95c | 0.721545 | 0.161030 | 7.067309e-03 | 0.278455 | 0.560515 | 0.153963 | 7.067309e-03 |
11 | 824aef23-a946-4916-b867-c371c4dfc0b3 | 0.730460 | 0.167657 | 7.610897e-03 | 0.269540 | 0.562803 | 0.160046 | 7.610897e-03 |
12 | e5871d1a-f76b-4afd-bae9-a4f30af8750a | 0.822580 | 0.299517 | 1.761579e-02 | 0.177420 | 0.523063 | 0.281901 | 1.761579e-02 |
13 | 8099ee28-22b6-44e2-a53c-ae3e67134812 | 0.901285 | 0.491102 | 9.169931e-02 | 0.098715 | 0.410184 | 0.399402 | 9.169931e-02 |
14 | 4b088339-1668-44e2-97d7-24a4c37b32c9 | 0.763308 | 0.194705 | 1.005527e-02 | 0.236692 | 0.568602 | 0.184650 | 1.005527e-02 |
15 | 2b1c295d-62e1-4879-8c2f-15af787a88f4 | 0.743243 | 0.177666 | 8.472765e-03 | 0.256757 | 0.565576 | 0.169194 | 8.472765e-03 |
2. Perform Building Damage analysis with an Tornado#
Perform building damage analysis with the following input parameters and datasets
Hazard type: tornado
Hazard ID: 60ad632f84525d4c31005a84
Mapping ID: 5d8942dfb9219c068ea795ea
# TODO: Define the variables that used for input parameters and datasets
hazard_type = "tornado"
hazard_id = "60ad632f84525d4c31005a84"
mapping_id = "5d8942dfb9219c068ea795ea"
result_name = "station_dmg_tornado"
# TODO: create fragility mapping object with id
tornado_mapping_set = MappingSet(fragility_services.get_mapping(mapping_id))
# Create building damage
bldg_dmg_tornado = BuildingDamage(client)
# TODO: Set up building damage analysis
bldg_dmg_tornado.set_input_dataset("buildings", local_buildings)
bldg_dmg_tornado.set_input_dataset("dfr3_mapping_set", tornado_mapping_set)
bldg_dmg_tornado.set_parameter("result_name", result_name)
bldg_dmg_tornado.set_parameter("hazard_type", hazard_type)
bldg_dmg_tornado.set_parameter("hazard_id", hazard_id)
bldg_dmg_tornado.set_parameter("num_cpu", 1)
True
# TODO: run analysis
bldg_dmg_tornado.run_analysis()
True
# TODO: Display the output of damage table by using DataFrame
tornado_bldg_dmg_table = bldg_dmg_tornado.get_output_dataset("ds_result").get_dataframe_from_csv()
tornado_bldg_dmg_table
guid | LS_0 | LS_1 | LS_2 | DS_0 | DS_1 | DS_2 | DS_3 | |
---|---|---|---|---|---|---|---|---|
0 | 2cfb735a-a648-46af-8ef2-81758207b707 | 0.000000 | 0.000000 | 0.000000 | 1.000000 | 0.000000 | 0.000000 | 0.000000 |
1 | c8767706-f6da-409a-989f-f4061315b704 | 0.000000 | 0.000000 | 0.000000 | 1.000000 | 0.000000 | 0.000000 | 0.000000 |
2 | 2a24ea2e-49d8-4ef4-bc4d-f2593ce5581d | 0.000000 | 0.000000 | 0.000000 | 1.000000 | 0.000000 | 0.000000 | 0.000000 |
3 | 88c670b7-6ae3-4f46-8fcb-0390f26dbf37 | 0.000000 | 0.000000 | 0.000000 | 1.000000 | 0.000000 | 0.000000 | 0.000000 |
4 | 962c1fbd-0161-4e05-b68c-b67b20410832 | 0.000000 | 0.000000 | 0.000000 | 1.000000 | 0.000000 | 0.000000 | 0.000000 |
5 | bc2cf058-636f-4e48-a9d0-3294a74adc38 | 0.000000 | 0.000000 | 0.000000 | 1.000000 | 0.000000 | 0.000000 | 0.000000 |
6 | 142b316d-04c6-427b-b8a7-f572ac1fb8fe | 0.000000 | 0.000000 | 0.000000 | 1.000000 | 0.000000 | 0.000000 | 0.000000 |
7 | a1a3c33c-6936-4092-9d5b-64941ed8b1d6 | 0.000000 | 0.000000 | 0.000000 | 1.000000 | 0.000000 | 0.000000 | 0.000000 |
8 | a0a379d1-3ad3-45df-947b-ec8f8c51b0ee | 0.000000 | 0.000000 | 0.000000 | 1.000000 | 0.000000 | 0.000000 | 0.000000 |
9 | cb287985-862f-4b2a-b51f-7a88e4e1f8cf | 0.000000 | 0.000000 | 0.000000 | 1.000000 | 0.000000 | 0.000000 | 0.000000 |
10 | ce47cd50-59ef-4d38-bdf9-e2059850a95c | 0.000000 | 0.000000 | 0.000000 | 1.000000 | 0.000000 | 0.000000 | 0.000000 |
11 | 824aef23-a946-4916-b867-c371c4dfc0b3 | 0.000000 | 0.000000 | 0.000000 | 1.000000 | 0.000000 | 0.000000 | 0.000000 |
12 | e5871d1a-f76b-4afd-bae9-a4f30af8750a | 0.955444 | 0.673680 | 0.325429 | 0.044556 | 0.281763 | 0.348251 | 0.325429 |
13 | 8099ee28-22b6-44e2-a53c-ae3e67134812 | 0.016072 | 0.000346 | 0.001991 | 0.983928 | 0.014081 | 0.000000 | 0.001991 |
14 | 4b088339-1668-44e2-97d7-24a4c37b32c9 | 0.000000 | 0.000000 | 0.000000 | 1.000000 | 0.000000 | 0.000000 | 0.000000 |
15 | 2b1c295d-62e1-4879-8c2f-15af787a88f4 | 0.000000 | 0.000000 | 0.000000 | 1.000000 | 0.000000 | 0.000000 | 0.000000 |
3. Compare damage outputs#
# TODO: Join two DataFrames with guid
comparison = eq_bldg_dmg_table.merge(tornado_bldg_dmg_table, how="outer", on="guid", suffixes=('_eq', '_tornado'))
# TODO: Display joined dataframe with most damaged (sorted by DS3 decending order)
comparison.sort_values(by=['DS_3_eq'])
guid | LS_0_eq | LS_1_eq | LS_2_eq | DS_0_eq | DS_1_eq | DS_2_eq | DS_3_eq | LS_0_tornado | LS_1_tornado | LS_2_tornado | DS_0_tornado | DS_1_tornado | DS_2_tornado | DS_3_tornado | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
3 | 88c670b7-6ae3-4f46-8fcb-0390f26dbf37 | 0.979347 | 0.194344 | 3.000000e-10 | 0.020653 | 0.785002 | 0.194344 | 3.000000e-10 | 0.000000 | 0.000000 | 0.000000 | 1.000000 | 0.000000 | 0.000000 | 0.000000 |
1 | c8767706-f6da-409a-989f-f4061315b704 | 0.594377 | 0.090310 | 2.535863e-03 | 0.405623 | 0.504068 | 0.087774 | 2.535863e-03 | 0.000000 | 0.000000 | 0.000000 | 1.000000 | 0.000000 | 0.000000 | 0.000000 |
4 | 962c1fbd-0161-4e05-b68c-b67b20410832 | 0.618612 | 0.101007 | 3.077337e-03 | 0.381388 | 0.517605 | 0.097930 | 3.077337e-03 | 0.000000 | 0.000000 | 0.000000 | 1.000000 | 0.000000 | 0.000000 | 0.000000 |
5 | bc2cf058-636f-4e48-a9d0-3294a74adc38 | 0.667402 | 0.126122 | 4.546865e-03 | 0.332598 | 0.541281 | 0.121575 | 4.546865e-03 | 0.000000 | 0.000000 | 0.000000 | 1.000000 | 0.000000 | 0.000000 | 0.000000 |
6 | 142b316d-04c6-427b-b8a7-f572ac1fb8fe | 0.667402 | 0.126122 | 4.546865e-03 | 0.332598 | 0.541281 | 0.121575 | 4.546865e-03 | 0.000000 | 0.000000 | 0.000000 | 1.000000 | 0.000000 | 0.000000 | 0.000000 |
7 | a1a3c33c-6936-4092-9d5b-64941ed8b1d6 | 0.667402 | 0.126122 | 4.546865e-03 | 0.332598 | 0.541281 | 0.121575 | 4.546865e-03 | 0.000000 | 0.000000 | 0.000000 | 1.000000 | 0.000000 | 0.000000 | 0.000000 |
10 | ce47cd50-59ef-4d38-bdf9-e2059850a95c | 0.721545 | 0.161030 | 7.067309e-03 | 0.278455 | 0.560515 | 0.153963 | 7.067309e-03 | 0.000000 | 0.000000 | 0.000000 | 1.000000 | 0.000000 | 0.000000 | 0.000000 |
11 | 824aef23-a946-4916-b867-c371c4dfc0b3 | 0.730460 | 0.167657 | 7.610897e-03 | 0.269540 | 0.562803 | 0.160046 | 7.610897e-03 | 0.000000 | 0.000000 | 0.000000 | 1.000000 | 0.000000 | 0.000000 | 0.000000 |
15 | 2b1c295d-62e1-4879-8c2f-15af787a88f4 | 0.743243 | 0.177666 | 8.472765e-03 | 0.256757 | 0.565576 | 0.169194 | 8.472765e-03 | 0.000000 | 0.000000 | 0.000000 | 1.000000 | 0.000000 | 0.000000 | 0.000000 |
0 | 2cfb735a-a648-46af-8ef2-81758207b707 | 0.755346 | 0.222489 | 9.364605e-03 | 0.244654 | 0.532857 | 0.213125 | 9.364605e-03 | 0.000000 | 0.000000 | 0.000000 | 1.000000 | 0.000000 | 0.000000 | 0.000000 |
14 | 4b088339-1668-44e2-97d7-24a4c37b32c9 | 0.763308 | 0.194705 | 1.005527e-02 | 0.236692 | 0.568602 | 0.184650 | 1.005527e-02 | 0.000000 | 0.000000 | 0.000000 | 1.000000 | 0.000000 | 0.000000 | 0.000000 |
2 | 2a24ea2e-49d8-4ef4-bc4d-f2593ce5581d | 0.792943 | 0.261558 | 1.302004e-02 | 0.207057 | 0.531385 | 0.248538 | 1.302004e-02 | 0.000000 | 0.000000 | 0.000000 | 1.000000 | 0.000000 | 0.000000 | 0.000000 |
12 | e5871d1a-f76b-4afd-bae9-a4f30af8750a | 0.822580 | 0.299517 | 1.761579e-02 | 0.177420 | 0.523063 | 0.281901 | 1.761579e-02 | 0.955444 | 0.673680 | 0.325429 | 0.044556 | 0.281763 | 0.348251 | 0.325429 |
9 | cb287985-862f-4b2a-b51f-7a88e4e1f8cf | 0.833515 | 0.271090 | 1.908092e-02 | 0.166485 | 0.562425 | 0.252009 | 1.908092e-02 | 0.000000 | 0.000000 | 0.000000 | 1.000000 | 0.000000 | 0.000000 | 0.000000 |
13 | 8099ee28-22b6-44e2-a53c-ae3e67134812 | 0.901285 | 0.491102 | 9.169931e-02 | 0.098715 | 0.410184 | 0.399402 | 9.169931e-02 | 0.016072 | 0.000346 | 0.001991 | 0.983928 | 0.014081 | 0.000000 | 0.001991 |
8 | a0a379d1-3ad3-45df-947b-ec8f8c51b0ee | 0.973078 | 0.697859 | 1.526643e-01 | 0.026922 | 0.275219 | 0.545195 | 1.526643e-01 | 0.000000 | 0.000000 | 0.000000 | 1.000000 | 0.000000 | 0.000000 | 0.000000 |