Commit 8d59dc9a authored by Tara Evaz Zadeh's avatar Tara Evaz Zadeh
Browse files

Added a file

parent facfe75a
#!/usr/bin/env python
import matplotlib.pyplot as plt
import numpy as np
import os
import pandas as pd
from csv import writer
#from get_gm_at_location_02 import get_gm_at_location
from get_gm_at_location_02 import interp_gm_at_location
#from interpolate_Karsten import interp_gm_at_location_karsten
#from rbf import rbf_gm_at_location
from get_fragility_function import get_fragility_function
#from interp_gm_at_location_griddata import interp_gm_at_location_griddata
from get_PoE import get_PoE
import csv
def LossCalculatorWrap(Result_path,fragilities_path,exposures_path,taxonomy_conversion_path,shakemap_path):
if os.path.exists(Result_path):
os.remove(Result_path)
################################################ Read Files ################################################
#print('Read Files')
exposures = pd.read_csv(exposures_path)
taxonomy_conversion_file=pd.read_csv(taxonomy_conversion_path)
################################################ Read Columns ################################################
#print('read Columns')
taxonomies=exposures.taxonomy
tot_num_buildings_row=exposures.number
lons=exposures.lon
lats=exposures.lat
assetids=exposures.id
############################################## Prepare Result File ################################################
#print('Prepare Result Files')
def append_list_as_row(file_name, list_of_elem):
with open(file_name, 'a+', newline='') as write_obj:
csv_writer = writer(write_obj)
csv_writer.writerow(list_of_elem)
title=['asset_id','lon','lat','taxonomy','gmfType','gmfValue','Ppoe','PoOs','tot_num_buildings','structural_No-damage','structural_Slight','structural_moderate','structural_extensive','structural_complete']
append_list_as_row(Result_path, title)
############################################### COMPUTATION ################################################
#print('Computation')
for asset in range(exposures.shape[0]):
print(asset)
taxonomy=taxonomies[asset]
tot_num_buildings=tot_num_buildings_row[asset]
lon=lons[asset]
lat=lats[asset]
asset_id=assetids[asset]
print(lon,lat)
################## find new taxonomy names ##################
fragility_function, new_tax = get_fragility_function(taxonomy,fragilities_path,taxonomy_conversion_path)
data = list(csv.reader(open(new_tax)))
gm_type1=data[0][0]
gm_type="gmv_"+gm_type1
print(gm_type)
print(taxonomy)
#gm_value = get_gm_at_location(lon, lat, shakemap_path, gm_type)
gm_value = interp_gm_at_location(lon,lat,shakemap_path,gm_type)
#gm_value = interp_gm_at_location_karsten(lon,lat,shakemap_path,gm_type)
#gm_value = rbf_gm_at_location(lon,lat,shakemap_path,gm_type)
#gm_value = interp_gm_at_location_griddata(lon, lat, shakemap_path, gm_type)
print('gmv=', gm_value)
[PoEs, PoOs] = get_PoE(fragility_function, gm_value)
################## Compute damages by assets ##################
#print('Compute damage_by_asset')
dmg_by_asset = [i * tot_num_buildings for i in PoOs]
################## Append results ##################
#print('append results')
arr0=[asset_id,lon,lat,taxonomy,gm_type,gm_value,PoEs,PoOs,tot_num_buildings]
arr0.extend(dmg_by_asset)
append_list_as_row(Result_path, arr0)
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