Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#Get rupture times for subfault windows
i=where(num==unum[kfault])[0]
trup=f[i,12]
#Get slips on windows
ss=all_ss[i]
ds=all_ds[i]
#Add it up
slip=(ss**2+ds**2)**0.5
#Get first source time function
t1,M1=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[0],slip[0])
#Loop over windows
for kwin in range(nwin-1):
#Get next source time function
t2,M2=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[kwin+1],slip[kwin+1])
#Add the soruce time functions
t1,M1=add2stf(t1,M1,t2,M2)
if kfault==0: #Intialize
M=zeros((len(t),nfault))
T=zeros((len(t),nfault))
Mout=interp(t,t1,M1)
M[:,kfault]=Mout
T[:,kfault]=t
#Now look through time slices
maxsr=0
#First retain original rupture information
ruptout=f[0:len(unum),:]
ruptout[:,8]=0 #Set SS to 0
print( 'Writing files...')
for ktime in range(len(t)):
sliprate=zeros(lon.shape)
for kfault in range(nfault):
i=where(T[:,kfault]==t[ktime])[0]
t1,M1=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[0],slip[0])
if covfile !=None:
t1plus,M1plus=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[0],slip_plus[0])
t1minus,M1minus=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[0],slip_minus[0])
#Loop over windows
for kwin in range(nwin-1):
#Get next source time function
t2,M2=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[kwin+1],slip[kwin+1])
if covfile !=None:
t2plus,M2plus=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[kwin+1],slip_plus[kwin+1])
t2minus,M2minus=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[kwin+1],slip_minus[kwin+1])
#Add the soruce time functions
t1,M1=add2stf(t1,M1,t2,M2)
if covfile !=None:
t1plus,M1plus=add2stf(t1plus,M1plus,t2plus,M2plus)
t1minus,M1minus=add2stf(t1minus,M1minus,t2minus,M2minus)
#Save M1 for output
if kfault==0:
Mout=expand_dims(M1,1).T
tout=expand_dims(t1,1).T
else:
Mout=r_[Mout,expand_dims(M1,1).T]
tout=r_[tout,expand_dims(t1,1).T]
#Track maximum moment
Mmax=max(Mmax,M1.max())
print('Maximum moment was '+str(Mmax)+'N-m')
return tout,Mout
t1,M1=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[0],slip[0])
if covfile !=None:
t1plus,M1plus=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[0],slip_plus[0])
t1minus,M1minus=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[0],slip_minus[0])
#Loop over windows
for kwin in range(nwin-1):
#Get next source time function
t2,M2=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[kwin+1],slip[kwin+1])
if covfile !=None:
t2plus,M2plus=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[kwin+1],slip_plus[kwin+1])
t2minus,M2minus=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[kwin+1],slip_minus[kwin+1])
#Add the soruce time functions
t1,M1=add2stf(t1,M1,t2,M2)
if covfile !=None:
t1plus,M1plus=add2stf(t1plus,M1plus,t2plus,M2plus)
t1minus,M1minus=add2stf(t1minus,M1minus,t2minus,M2minus)
#Save M1 for output
if kfault==0:
Mout=expand_dims(M1,1).T
tout=expand_dims(t1,1).T
else:
Mout=r_[Mout,expand_dims(M1,1).T]
tout=r_[tout,expand_dims(t1,1).T]
#Track maximum moment
Mmax=max(Mmax,M1.max())
#Done now plot them
#get current axis
ax=axarr[int(idip[kfault]), int(istrike[kfault])]
if shade:
#Make contourf
Mc=linspace(0,0.98*max(M1),100)
T,M=meshgrid(t1,Mc)
slip_plus=slipCIplus[i]
slip_minus=slipCIminus[i]
#Get first source time function
t1,M1=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[0],slip[0])
if covfile !=None:
t1plus,M1plus=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[0],slip_plus[0])
t1minus,M1minus=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[0],slip_minus[0])
#Loop over windows
for kwin in range(nwin-1):
#Get next source time function
t2,M2=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[kwin+1],slip[kwin+1])
if covfile !=None:
t2plus,M2plus=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[kwin+1],slip_plus[kwin+1])
t2minus,M2minus=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[kwin+1],slip_minus[kwin+1])
#Add the soruce time functions
t1,M1=add2stf(t1,M1,t2,M2)
if covfile !=None:
t1plus,M1plus=add2stf(t1plus,M1plus,t2plus,M2plus)
t1minus,M1minus=add2stf(t1minus,M1minus,t2minus,M2minus)
#Save M1 for output
if kfault==0:
Mout=expand_dims(M1,1).T
tout=expand_dims(t1,1).T
else:
Mout=r_[Mout,expand_dims(M1,1).T]
tout=r_[tout,expand_dims(t1,1).T]
#Track maximum moment
Mmax=max(Mmax,M1.max())
print('Maximum moment was '+str(Mmax)+'N-m')
return tout,Mout
#Get rupture times for subfault windows
i=where(num==unum[kfault])[0]
trup=f[i,12]
#Get slips on windows
ss=all_ss[i]
ds=all_ds[i]
#Add it up
slip=(ss**2+ds**2)**0.5
#Get first source time function
t1,M1=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[0],slip[0])
#Loop over windows
for kwin in range(nwin-1):
#Get next source time function
t2,M2=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[kwin+1],slip[kwin+1])
#Add the soruce time functions
t1,M1=add2stf(t1,M1,t2,M2)
if kfault==0: #Intialize
M=zeros((len(t),nfault))
T=zeros((len(t),nfault))
Mout=interp(t,t1,M1)
M[:,kfault]=Mout
T[:,kfault]=t
#Now look through time slices
maxsr=0
#Now integrate slip
t=arange(0,tmax+dt*0.1,dt)
print(t)
#First retain original rupture information
ruptout=f[0:len(unum),:]
ruptout[:,8]=0 #Set SS to 0
print('Writing files...')
for ktime in range(len(t)-1):
#Get rupture times for subfault windows
i=where(num==unum[kfault])[0]
trup=f[i,12]
#Get slips on windows
ss=all_ss[i]
ds=all_ds[i]
#Add it up
slip=(ss**2+ds**2)**0.5
if kfault==0:#Get first source time function
t1,M1=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[0],slip[0])
#Loop over windows
for kwin in range(nwin-1):
#Get next source time function
t2,M2=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[kwin+1],slip[kwin+1])
#Add the soruce time functions
t1,M1=add2stf(t1,M1,t2,M2)
#Get power
exp=floor(log10(M1.max()))
M1=M1/(10**exp)
if plot==True:
plt.figure()
plt.fill(t1,M1,'b',alpha=0.5)
plt.plot(t1,M1,color='k')
plt.grid()
plt.xlabel('Time(s)')
plt.ylabel('Moment Rate ('+r'$\times 10^{'+str(int(exp))+r'}$Nm/s)')
plt.subplots_adjust(left=0.3, bottom=0.3, right=0.7, top=0.7, wspace=0, hspace=0)
if xlim!=None:
plt.xlim(xlim)
if ylim!=None:
plt.ylim(ylim)
return t1,M1
#Get rupture times for subfault windows
i=where(num==unum[kfault])[0]
trup=f[i,12]
#Get slips on windows
ss=all_ss[i]
ds=all_ds[i]
#Add it up
slip=(ss**2+ds**2)**0.5
#Get first source time function
t1,M1=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[0],slip[0])
#Loop over windows
for kwin in range(nwin-1):
#Get next source time function
t2,M2=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[kwin+1],slip[kwin+1])
#Add the soruce time functions
t1,M1=add2stf(t1,M1,t2,M2)
if kfault==0: #Intialize
M=zeros((len(t),nfault))
T=zeros((len(t),nfault))
Mout=interp(t,t1,M1)
M[:,kfault]=Mout
T[:,kfault]=t
#Now look through time slices
maxsr=0
print('Writing files...')
for ktime in range(len(t)):
sliprate=zeros(lon.shape)
for kfault in range(nfault):
i=where(T[:,kfault]==t[ktime])[0]
sliprate[kfault]=M[i,kfault]/(mu[kfault]*area[kfault])
maxsr=max(maxsr,sliprate.max())
fname=out+str(ktime).rjust(4,'0')+'.sliprate'
#Get rupture times for subfault windows
i=where(num==unum[kfault])[0]
trup=f[i,12]
#Get slips on windows
ss=all_ss[i]
ds=all_ds[i]
#Add it up
slip=(ss**2+ds**2)**0.5
#Get first source time function
t1,M1=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[0],slip[0])
#Loop over windows
for kwin in range(nwin-1):
#Get next source time function
t2,M2=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[kwin+1],slip[kwin+1])
#Add the soruce time functions
t1,M1=add2stf(t1,M1,t2,M2)
#Convert to slip rate
s=M1/(mu[kfault]*area[kfault])
#remove mean
s=s-mean(s)
#Done now compute spectra of STF
fsample=1./(t1[1]-t1[0])
freq, psd, nu = tsa.multi_taper_psd(s,Fs=fsample,adaptive=True,jackknife=False,low_bias=True)
outname=run_name+'.'+run_number+'.sub'+str(kfault).rjust(4,'0')+'.stfpsd'
savez(outpath+outname,freq=freq,psd=psd)
slip_plus=slipCIplus[i]
slip_minus=slipCIminus[i]
#Get first source time function
t1,M1=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[0],slip[0])
if covfile !=None:
t1plus,M1plus=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[0],slip_plus[0])
t1minus,M1minus=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[0],slip_minus[0])
#Loop over windows
for kwin in range(nwin-1):
#Get next source time function
t2,M2=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[kwin+1],slip[kwin+1])
if covfile !=None:
t2plus,M2plus=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[kwin+1],slip_plus[kwin+1])
t2minus,M2minus=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[kwin+1],slip_minus[kwin+1])
#Add the soruce time functions
t1,M1=add2stf(t1,M1,t2,M2)
if covfile !=None:
t1plus,M1plus=add2stf(t1plus,M1plus,t2plus,M2plus)
t1minus,M1minus=add2stf(t1minus,M1minus,t2minus,M2minus)
#Save M1 for output
if kfault==0:
Mout=expand_dims(M1,1).T
tout=expand_dims(t1,1).T
else:
Mout=r_[Mout,expand_dims(M1,1).T]
tout=r_[tout,expand_dims(t1,1).T]
#Track maximum moment
Mmax=max(Mmax,M1.max())
#Done now plot them
#get current axis
ax=axarr[int(idip[kfault]), int(istrike[kfault])]
if shade:
#Get first source time function
t1,M1=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[0],slip[0])
if covfile !=None:
t1plus,M1plus=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[0],slip_plus[0])
t1minus,M1minus=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[0],slip_minus[0])
#Loop over windows
for kwin in range(nwin-1):
#Get next source time function
t2,M2=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[kwin+1],slip[kwin+1])
if covfile !=None:
t2plus,M2plus=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[kwin+1],slip_plus[kwin+1])
t2minus,M2minus=get_source_time_function(mu[kfault],area[kfault],rise_time[kfault],trup[kwin+1],slip_minus[kwin+1])
#Add the soruce time functions
t1,M1=add2stf(t1,M1,t2,M2)
if covfile !=None:
t1plus,M1plus=add2stf(t1plus,M1plus,t2plus,M2plus)
t1minus,M1minus=add2stf(t1minus,M1minus,t2minus,M2minus)
#Save M1 for output
if kfault==0:
Mout=expand_dims(M1,1).T
tout=expand_dims(t1,1).T
else:
Mout=r_[Mout,expand_dims(M1,1).T]
tout=r_[tout,expand_dims(t1,1).T]
#Track maximum moment
Mmax=max(Mmax,M1.max())
print('Maximum moment was '+str(Mmax)+'N-m')
return tout,Mout