In order to use this methodology, it is necessary to provide a hazard curve, defined according to the format established on the RMTK manual. Please provide the location of the file containing this input using the parameter capacity_curves_file.
In [30]:
from rmtk.vulnerability.common import utils
%matplotlib inline
hazard_curve_file = '../../../../../../Google Drive 2/Otros GEM/RMTK/Convolution_module/Hazard_PGA.csv'
hazard_curve = utils.read_hazard(hazard_curve_file)
utils.plot_hazard_curve(hazard_curve)
The fragility function representing the risk of the building class being analysed should be provided here. This function should follow the format established in the RMTK manual. Please provide the location of the file containing this input using the parameter fragility_function_file.
In [44]:
fragility_function_file = '../../../../../../Google Drive 2/Otros GEM/RMTK/Convolution_module/MUR_H1.csv'
fragility_model = utils.read_frag_model(fragility_function_file)
save = False
utils.plot_fragility_model(fragility_function_file,0.01,2,save)
In order to obtain the fragility model, it is necessary to input the return period for which the hazard curve was derived, as well as the damage state of interest (slight, collapse, etc.), as described in the RMTK manual.
def calculate_convolution(hazard_curve,fragility_model,return_period,damage_state)
In [45]:
import Convolution
return_period = 50
damage_state = 'Collapse'
save = True
APD = Convolution.calculate_convolution(hazard_curve,fragility_model,return_period,damage_state)
In [208]:
# -*- coding: utf-8 -*-
import os
import numpy
import math
import csv
import matplotlib.pyplot as plt
from rmtk.vulnerability.common import utils
from scipy.stats import lognorm
def read_hazard(input_file):
#This function reads a hazard curve and stores it in a dictionary
file = open(input_file)
data = csv.reader(file)
IMLs = []
prob_exceedance = []
IM_type = []
for line in data:
if line[0] == 'PGA':
IM_type.append(line[0])
for value in line[1:]:
if isNumber(value):
IMLs.append(float(value))
if line[0] == 'Sa':
IM_type.append(line[0])
for value in line[1:]:
if isNumber(value):
IMLs.append(float(value))
if line[0] == 'PoE':
for value in line[1:]:
if isNumber(value):
prob_exceedance.append(float(value))
#Store all the data in the dictionary
hazard_curve = {'IMLs':None,'PoE':None,'IM_Type':None}
hazard_curve['IMLs'] = IMLs
hazard_curve['PoE'] = prob_exceedance
hazard_curve['IM_Type'] = IM_type
return hazard_curve
def isNumber(s):
try:
float(s)
return True
except ValueError:
return False
def plot_hazard_curve(hazard_curve):
#This function plots the hazard curve
IMLs = hazard_curve['IMLs']
PoE = hazard_curve['PoE']
plt.plot(IMLs,PoE,color='g',linewidth=2)
plt.xlabel(hazard_curve['IM_Type'][0] + ' [g]',fontsize = 10)
plt.ylabel('Probability of Exceedance',fontsize = 10)
In [209]:
input_file = 'Hazard_PGA.csv'
%matplotlib inline
hazard_curve = read_hazard(input_file)
print(hazard_curve)
plot_hazard_curve(hazard_curve)
In [210]:
# -*- coding: utf-8 -*-
import os
import numpy
import math
import csv
import matplotlib.pyplot as plt
from rmtk.vulnerability.common import utils
from scipy.stats import lognorm
def read_frag_model(input_file):
#This function reads a fragility model and stores it in a dictionary
damage_states = []
model_type = []
cent_value = []
dispersion = []
log_mean = []
log_stdev = []
file = open(input_file)
data = file.readlines()
line = data[0]
line = line.strip().split(',')
model_type = line[1]+' - '+line[2]
file = open(input_file)
data = csv.reader(file)
data = [row for row in data]
for iline in range(len(data)-1):
line = data[iline+1]
damage_states.append(line[0])
cent_value.append(float(line[1]))
dispersion.append(float(line[2]))
if model_type == ' median - dispersion':
for ids in range(len(cent_value)):
mean = math.log(cent_value[ids])
stdev = dispersion[ids]
log_mean.append(mean)
log_stdev.append(stdev)
elif model_type == ' mean of x - cov of x':
for ids in range(len(cent_value)):
mu = cent.value[ids]
cov = dispersion[ids]
median = (mu**2)/math.sqrt(mu**2+cov**2)
mean = math.log(median)
stdev = math.sqrt(math.log(1+(cov**2)/mu**2))
log_mean.append(mean)
log_stdev.append(stdev)
elif model_type == 'mean of ln(x) - st. dev. of ln(x)':
for ids in range(len(cent_value)):
mean = cent_value[ids]
stdev = line[ids]
log_mean.append(mean)
log_stdev.append(stdev)
#Store all the data in the dictionary
fragility_model = {'Damage_states':None,'log_mean':None,'log_stdev':None}
fragility_model['Damage_states'] = damage_states
fragility_model['log_mean'] = log_mean
fragility_model['log_stdev'] = log_stdev
return fragility_model
In [211]:
fragility_function_file = 'MUR_H1.csv'
fragility_model = read_frag_model(fragility_function_file)
save = False
print(fragility_model)
In [227]:
print(hazard_curve['IMLs'])
print(len(hazard_curve['IMLs']))
In [345]:
# -*- coding: utf-8 -*-
import os
import numpy
import math
import csv
import matplotlib.pyplot as plt
from rmtk.vulnerability.common import utils
from scipy.stats import lognorm
def calculate_convolution(hazard_curve,fragility_model,return_period,damage_state):
#This function calculates the annual probability of collapse given a hazard
#curve and a fragility model
rate_exceed = []
segment_limit = []
segment_width = []
imls = []
prob_exceed = []
frag_curve = []
damage_rate_dist = []
for iIML in range(len(hazard_curve['IMLs'])):
#1. Calculate the annual rate of exceedance
imls.append(hazard_curve['IMLs'][iIML])
prob_exceed.append(hazard_curve['PoE'][iIML])
rate_exceed.append(-math.log(1-prob_exceed[iIML])/return_period)
#2. Divide the curve into segments and derive the rate of occurrence
# of the associated central IML value
for iIML in range(len(imls)-1):
segment_limit.append((imls[iIML]+imls[iIML+1])/2)
segment_width.append(segment_limit[0])
for iDelta in range(len(imls)-2):
k = iDelta + 1
segment_width.append(segment_limit[k]-segment_limit[(k-1)])
segment_width.append(imls[-1]-segment_limit[-1])
#3. Read fragility curve of interest and estimate the probability of
# reaching the DS of interest, given the values of IML
ds = fragility_model['Damage_states'].index(damage_state)
mean = fragility_model['log_mean'][ds]
stdev = fragility_model['log_stdev'][ds]
for iIML in range(len(imls)):
frag_curve.append(lognorm.cdf(imls[iIML], stdev, loc=0, scale=math.exp(mean)))
#4. Calculate the damage rate distribution for the given IML
for iIML in range(len(imls)):
damage_rate_dist.append(rate_exceed[iIML]*frag_curve[iIML]*segment_width[iIML])
#5. Calculate the annual damage rate (ADR) and annual probability of damage (APD)
ADR = sum(damage_rate_dist)
APD = (math.exp(ADR*1)-1)/math.exp(ADR*1)
return APD
print(ADR)
#print(rate_exceed)
#print(frag_curve)
#print(damage_rate_dist)
#print(rate_exceed)
In [346]:
return_period = 50
damage_state = 'Collapse'
APD = calculate_convolution(hazard_curve,fragility_model,return_period,damage_state)
print(APD)