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

Added a file

parent 9de1d9f6
def get_PoE(fragility_function, gm_value):
import numpy as np
from scipy import interpolate
#can be done using spline
#https://stackoverflow.com/questions/2745329/how-to-make-scipy-interpolate-give-an-extrapolated-result-beyond-the-input-range
imls=fragility_function[0]
PoE_sli=fragility_function[1]
PoE_mod=fragility_function[2]
PoE_ext=fragility_function[3]
PoE_com=fragility_function[4]
print(imls)
print(gm_value)
if gm_value < imls[0] :
PoEs=[1,0,0,0,0]
PoOs=[1,0,0,0,0]
elif gm_value > imls[-1] :
iml_min=imls[-2]
idx_iml_min = -2
iml_max=imls[-1]
idx_iml_max = -1
x=[iml_min, iml_max]
x_new=gm_value
PoEs = [1]
for Poes in [PoE_sli,PoE_mod,PoE_ext,PoE_com]:
#print('Poes=',Poes)
y = [Poes[idx_iml_min], Poes[idx_iml_max]]
#print(y)
f = interpolate.interp1d(x, y, fill_value='extrapolate')
y_new=f(x_new)
#print('interpolatedValue=',y_new)
PoEs.append(y_new)
#print('PoEs=',PoEs)
PoOs = list()
for i in [1,2,3,4]:
t = np.subtract(PoEs[i-1], PoEs[i])
PoOs.append(t)
PoOs.append(PoEs[-1])
#print('PoOs=',PoOs)
else:
iml_min=imls[imls < gm_value].max()
idx_iml_min = np.searchsorted(imls, iml_min, side="left")
iml_max=imls[imls > gm_value].min()
idx_iml_max = np.searchsorted(imls, iml_max, side="left")
x=[iml_min, iml_max]
x_new=gm_value
PoEs = [1]
for Poes in [PoE_sli,PoE_mod,PoE_ext,PoE_com]:
y = [Poes[idx_iml_min], Poes[idx_iml_max]]
y_new = np.interp(x_new, x, y)
PoEs.append(y_new)
#print('PoEs=',PoEs)
PoOs = list()
for i in [1,2,3,4]:
t = np.subtract(PoEs[i-1], PoEs[i])
PoOs.append(t)
PoOs.append(PoEs[-1])
#print('PoOs=',PoOs)
return(PoEs,PoOs)
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