def source_spectra(home,project_name,run_name,run_number,rupt,nstrike,ndip): ''' Tile plot of subfault source-time functions ''' from numpy import genfromtxt,unique,zeros,where,arange,savez,mean from mudpy.forward import get_source_time_function,add2stf import nitime.algorithms as tsa from string import rjust outpath=home+project_name+'/analysis/frequency/' f=genfromtxt(rupt) num=f[:,0] nfault=nstrike*ndip #Get slips all_ss=f[:,8] all_ds=f[:,9] all=zeros(len(all_ss)*2) iss=2*arange(0,len(all)/2,1) ids=2*arange(0,len(all)/2,1)+1 all[iss]=all_ss all[ids]=all_ds #Now parse for multiple rupture speeds unum=unique(num) #Count number of windows nwin=len(where(num==unum[0])[0]) #Get rigidities mu=f[0:len(unum),13] #Get rise times rise_time=f[0:len(unum),7] #Get areas area=f[0:len(unum),10]*f[0:len(unum),11] for kfault in range(nfault): if kfault%10==0: print '... working on subfault '+str(kfault)+' of '+str(nfault) #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'+rjust(str(kfault),4,'0')+'.stfpsd' savez(outpath+outname,freq=freq,psd=psd)
def source_time_function(rupt,epicenter): ''' Plot source time function of complete ru ''' import matplotlib.pyplot as plt from numpy import genfromtxt,unique,log10,where,floor from mudpy.forward import get_source_time_function,add2stf f=genfromtxt(rupt) num=f[:,0] #Get slips all_ss=f[:,8] all_ds=f[:,9] #Now parse for multiple rupture speeds unum=unique(num) nfault=len(unum) #Count number of windows nwin=len(where(num==unum[0])[0]) #Get rigidities mu=f[0:len(unum),13] #Get rise times rise_time=f[0:len(unum),7] #Get areas area=f[0:len(unum),10]*f[0:len(unum),11] #Loop over subfaults for kfault in range(nfault): if kfault%10==0: print '... working on subfault '+str(kfault)+' of '+str(nfault) #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) 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)') return t1,M1
def make_slip_slice(rupt,nstrike,ndip,epicenter,out,tmax,dt): ''' ''' from numpy import genfromtxt,unique,zeros,where,arange,interp,c_,savetxt,intersect1d from mudpy.forward import get_source_time_function,add2stf from scipy.integrate import trapz f=genfromtxt(rupt) num=f[:,0] nfault=nstrike*ndip unum=unique(num) lon=f[0:len(unum),1] lat=f[0:len(unum),2] depth=f[0:len(unum),3] #Get slips all_ss=f[:,8] all_ds=f[:,9] #Now parse for multiple rupture speeds unum=unique(num) #Count number of windows nwin=len(where(num==unum[0])[0]) #Get rigidities mu=f[0:len(unum),13] #Get rise times rise_time=f[0:len(unum),7] #Get areas area=f[0:len(unum),10]*f[0:len(unum),11] #Get indices for plot istrike=zeros(nstrike*ndip) idip=zeros(nstrike*ndip) k=0 t=arange(0,tmax,0.1) for i in range(ndip): for j in range(nstrike): istrike[k]=nstrike-j-1 idip[k]=i k+=1 #Loop over subfaults print(nfault) for kfault in range(nfault): if kfault%10==0: print('... working on subfault '+str(kfault)+' of '+str(nfault)) #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): slip=zeros(lon.shape) for kfault in range(nfault): i1=where(T[:,kfault]>=t[ktime])[0] i2=where(T[:,kfault]<t[ktime+1])[0] i=intersect1d(i1,i2) slip[kfault]=trapz(M[i,kfault]/(mu[kfault]*area[kfault]),T[i,kfault]) ruptout[:,9]=slip #Assign slip to SS component maxsr=max(maxsr,slip.max()) fname=out+str(ktime).rjust(4,'0')+'.slip' fmtout='%6i\t%.4f\t%.4f\t%8.4f\t%.2f\t%.2f\t%.2f\t%.2f\t%12.4e\t%12.4e%10.1f\t%10.1f\t%8.4f\t%.4e' savetxt(fname,ruptout,fmtout,header='No,lon,lat,z(km),strike,dip,rise,dura,ss-slip(m),ds-slip(m),ss_len(m),ds_len(m),rupt_time(s),rigidity(Pa)') print('Maximum slip was '+str(maxsr)+'m')
def make_sliprate_slice(rupt,nstrike,ndip,epicenter,out,tmax,dt): ''' ''' from numpy import genfromtxt,unique,zeros,where,arange,interp,c_,savetxt from mudpy.forward import get_source_time_function,add2stf f=genfromtxt(rupt) num=f[:,0] nfault=nstrike*ndip unum=unique(num) lon=f[0:len(unum),1] lat=f[0:len(unum),2] depth=f[0:len(unum),3] #Get slips all_ss=f[:,8] all_ds=f[:,9] #Now parse for multiple rupture speeds unum=unique(num) #Count number of windows nwin=len(where(num==unum[0])[0]) #Get rigidities mu=f[0:len(unum),13] #Get rise times rise_time=f[0:len(unum),7] #Get areas area=f[0:len(unum),10]*f[0:len(unum),11] t=arange(0,tmax,dt) #Loop over subfaults for kfault in range(nfault): if kfault%10==0: print( '... working on subfault '+str(kfault)+' of '+str(nfault)) #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' savetxt(fname, c_[lon,lat,depth,sliprate],fmt='%.6f\t%.6f\t%.4f\t%.6f') print( 'Maximum slip rate was '+str(maxsr)+'m/s')
def make_slip_slice(rupt,nstrike,ndip,epicenter,out,tmax,dt): ''' ''' from numpy import genfromtxt,unique,zeros,where,arange,interp,c_,savetxt,intersect1d from mudpy.forward import get_source_time_function,add2stf from string import rjust from scipy.integrate import trapz f=genfromtxt(rupt) num=f[:,0] nfault=nstrike*ndip unum=unique(num) lon=f[0:len(unum),1] lat=f[0:len(unum),2] depth=f[0:len(unum),3] #Get slips all_ss=f[:,8] all_ds=f[:,9] #Now parse for multiple rupture speeds unum=unique(num) #Count number of windows nwin=len(where(num==unum[0])[0]) #Get rigidities mu=f[0:len(unum),13] #Get rise times rise_time=f[0:len(unum),7] #Get areas area=f[0:len(unum),10]*f[0:len(unum),11] #Get indices for plot istrike=zeros(nstrike*ndip) idip=zeros(nstrike*ndip) k=0 t=arange(0,tmax,0.1) for i in range(ndip): for j in range(nstrike): istrike[k]=nstrike-j-1 idip[k]=i k+=1 #Loop over subfaults print nfault for kfault in range(nfault): if kfault%10==0: print '... working on subfault '+str(kfault)+' of '+str(nfault) #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): slip=zeros(lon.shape) for kfault in range(nfault): i1=where(T[:,kfault]>=t[ktime])[0] i2=where(T[:,kfault]<t[ktime+1])[0] i=intersect1d(i1,i2) slip[kfault]=trapz(M[i,kfault]/(mu[kfault]*area[kfault]),T[i,kfault]) ruptout[:,9]=slip #Assign slip to SS component maxsr=max(maxsr,slip.max()) fname=out+rjust(str(ktime),4,'0')+'.slip' fmtout='%6i\t%.4f\t%.4f\t%8.4f\t%.2f\t%.2f\t%.2f\t%.2f\t%12.4e\t%12.4e%10.1f\t%10.1f\t%8.4f\t%.4e' savetxt(fname,ruptout,fmtout,header='No,lon,lat,z(km),strike,dip,rise,dura,ss-slip(m),ds-slip(m),ss_len(m),ds_len(m),rupt_time(s),rigidity(Pa)') print 'Maximum slip was '+str(maxsr)+'m'
def make_sliprate_slice(rupt,nstrike,ndip,epicenter,out,tmax,dt): ''' ''' from numpy import genfromtxt,unique,zeros,where,arange,interp,c_,savetxt from mudpy.forward import get_source_time_function,add2stf from string import rjust f=genfromtxt(rupt) num=f[:,0] nfault=nstrike*ndip unum=unique(num) lon=f[0:len(unum),1] lat=f[0:len(unum),2] depth=f[0:len(unum),3] #Get slips all_ss=f[:,8] all_ds=f[:,9] #Now parse for multiple rupture speeds unum=unique(num) #Count number of windows nwin=len(where(num==unum[0])[0]) #Get rigidities mu=f[0:len(unum),13] #Get rise times rise_time=f[0:len(unum),7] #Get areas area=f[0:len(unum),10]*f[0:len(unum),11] t=arange(0,tmax,dt) #Loop over subfaults for kfault in range(nfault): if kfault%10==0: print '... working on subfault '+str(kfault)+' of '+str(nfault) #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+rjust(str(ktime),4,'0')+'.sliprate' savetxt(fname, c_[lon,lat,depth,sliprate],fmt='%.6f\t%.6f\t%.4f\t%.6f') print 'Maximum slip rate was '+str(maxsr)+'m/s'
def subfault_STFs(rupt,epicenter,nstrike,ndip,beta=None,covfile=None): ''' Extract subfault source-time functions If analyzing an output .inv file make beta=0 ''' from numpy import genfromtxt,unique,zeros,where,meshgrid,linspace,load,arange,expand_dims,squeeze,tile,r_ from mudpy.forward import get_source_time_function,add2stf from mudpy.inverse import d2epi,ds2rot f=genfromtxt(rupt) num=f[:,0] nfault=nstrike*ndip #Get slips all_ss=f[:,8] all_ds=f[:,9] all=zeros(len(all_ss)*2) iss=2*arange(0,len(all)/2,1) ids=2*arange(0,len(all)/2,1)+1 all[iss]=all_ss all[ids]=all_ds #Compute CI #Load covariances if covfile!=None: rot=ds2rot(expand_dims(all,1),beta) C=load(covfile) CIplus=squeeze(rot)+1*(C**0.5) CIminus=squeeze(rot)-1*(C**0.5) CIminus[CIminus<0]=0 slipCIplus=(CIplus[iss]**2+CIplus[ids]**2)**0.5 slipCIminus=(CIminus[iss]**2+CIminus[ids]**2)**0.5 #Now parse for multiple rupture speeds unum=unique(num) #Count number of windows nwin=len(where(num==unum[0])[0]) #Get rigidities mu=f[0:len(unum),13] #Get rise times rise_time=f[0:len(unum),7] #Get areas area=f[0:len(unum),10]*f[0:len(unum),11] #Get coordinates and compute distances source=f[0:len(unum),1:4] d=d2epi(epicenter,source) #Loop over subfaults Mmax=0 Mout=[] for kfault in range(nfault): if kfault%10==0: print '... working on subfault '+str(kfault)+' of '+str(nfault) #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 covfile !=None: 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
def subfault_STFs(rupt, epicenter, nstrike, ndip, beta=None, covfile=None): """ Extract subfault source-time functions If analyzing an output .inv file make beta=0 """ from numpy import genfromtxt, unique, zeros, where, meshgrid, linspace, load, arange, expand_dims, squeeze, tile, r_ from mudpy.forward import get_source_time_function, add2stf from mudpy.inverse import d2epi, ds2rot f = genfromtxt(rupt) num = f[:, 0] nfault = nstrike * ndip # Get slips all_ss = f[:, 8] all_ds = f[:, 9] all = zeros(len(all_ss) * 2) iss = 2 * arange(0, len(all) / 2, 1) ids = 2 * arange(0, len(all) / 2, 1) + 1 all[iss] = all_ss all[ids] = all_ds # Compute CI # Load covariances if covfile != None: rot = ds2rot(expand_dims(all, 1), beta) C = load(covfile) CIplus = squeeze(rot) + 1 * (C ** 0.5) CIminus = squeeze(rot) - 1 * (C ** 0.5) CIminus[CIminus < 0] = 0 slipCIplus = (CIplus[iss] ** 2 + CIplus[ids] ** 2) ** 0.5 slipCIminus = (CIminus[iss] ** 2 + CIminus[ids] ** 2) ** 0.5 # Now parse for multiple rupture speeds unum = unique(num) # Count number of windows nwin = len(where(num == unum[0])[0]) # Get rigidities mu = f[0 : len(unum), 13] # Get rise times rise_time = f[0 : len(unum), 7] # Get areas area = f[0 : len(unum), 10] * f[0 : len(unum), 11] # Get coordinates and compute distances source = f[0 : len(unum), 1:4] d = d2epi(epicenter, source) # Loop over subfaults Mmax = 0 Mout = [] for kfault in range(nfault): if kfault % 10 == 0: print "... working on subfault " + str(kfault) + " of " + str(nfault) # 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 covfile != None: 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
def source_spectra(home, project_name, run_name, run_number, rupt, nstrike, ndip): ''' Tile plot of subfault source-time functions ''' from numpy import genfromtxt, unique, zeros, where, arange, savez, mean from mudpy.forward import get_source_time_function, add2stf import nitime.algorithms as tsa outpath = home + project_name + '/analysis/frequency/' f = genfromtxt(rupt) num = f[:, 0] nfault = nstrike * ndip #Get slips all_ss = f[:, 8] all_ds = f[:, 9] all = zeros(len(all_ss) * 2) iss = 2 * arange(0, len(all) / 2, 1) ids = 2 * arange(0, len(all) / 2, 1) + 1 all[iss] = all_ss all[ids] = all_ds #Now parse for multiple rupture speeds unum = unique(num) #Count number of windows nwin = len(where(num == unum[0])[0]) #Get rigidities mu = f[0:len(unum), 13] #Get rise times rise_time = f[0:len(unum), 7] #Get areas area = f[0:len(unum), 10] * f[0:len(unum), 11] for kfault in range(nfault): if kfault % 10 == 0: print('... working on subfault ' + str(kfault) + ' of ' + str(nfault)) #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)
def make_sliprate_ruptfiles(rupt,nstrike,ndip,epicenter,out,tmax,dt): ''' Make sliprate .rupt files for plotting several frames with tile_slip and animating with ffmpeg. Only write dip slip component regardless of the actual rake angle. We're just plotting scalar slip rate... ''' from numpy import genfromtxt,unique,zeros,where,arange,interp,c_,savetxt from mudpy.forward import get_source_time_function,add2stf from string import rjust f=genfromtxt(rupt) num=f[:,0] nfault=nstrike*ndip unum=unique(num) lon=f[0:len(unum),1] lat=f[0:len(unum),2] depth=f[0:len(unum),3] #Get slips all_ss=f[:,8] all_ds=f[:,9] #Now parse for multiple rupture speeds unum=unique(num) #Count number of windows nwin=len(where(num==unum[0])[0]) #Get rigidities mu=f[0:len(unum),13] #Get rise times rise_time=f[0:len(unum),7] #Get areas area=f[0:len(unum),10]*f[0:len(unum),11] #Get indices for plot istrike=zeros(nstrike*ndip) idip=zeros(nstrike*ndip) k=0 t=arange(0,tmax,dt) for i in range(ndip): for j in range(nstrike): istrike[k]=nstrike-j-1 idip[k]=i k+=1 #Loop over subfaults for kfault in range(nfault): if kfault%10==0: print '... working on subfault '+str(kfault)+' of '+str(nfault) #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] sliprate[kfault]=M[i,kfault]/(mu[kfault]*area[kfault]) ruptout[:,9]=sliprate #Assign slip rate to SS component maxsr=max(maxsr,sliprate.max()) fname=out+rjust(str(ktime),4,'0')+'.sliprate' #Write as a rupt file fmtout='%6i\t%.4f\t%.4f\t%8.4f\t%.2f\t%.2f\t%.2f\t%.2f\t%12.4e\t%12.4e%10.1f\t%10.1f\t%8.4f\t%.4e' savetxt(fname,ruptout,fmtout,header='No,lon,lat,z(km),strike,dip,rise,dura,ss-slip(m),ds-slip(m),ss_len(m),ds_len(m),rupt_time(s),rigidity(Pa)') print 'Maximum slip rate was '+str(maxsr)+'m/s'
def tile_moment(rupt,epicenter,nstrike,ndip,covfile,beta): ''' Tile plot of subfault source-time functions ''' import matplotlib.pyplot as plt from matplotlib import cm from numpy import genfromtxt,unique,zeros,where,meshgrid,linspace,load,arange,expand_dims,squeeze from mudpy.forward import get_source_time_function,add2stf from mudpy.inverse import d2epi,ds2rot f=genfromtxt(rupt) num=f[:,0] nfault=nstrike*ndip #Get slips all_ss=f[:,8] all_ds=f[:,9] all=zeros(len(all_ss)*2) iss=2*arange(0,len(all)/2,1) ids=2*arange(0,len(all)/2,1)+1 all[iss]=all_ss all[ids]=all_ds rot=ds2rot(expand_dims(all,1),beta) #Compute CI #Load covariances if covfile!=None: C=load(covfile) CIplus=squeeze(rot)+1*(C**0.5) CIminus=squeeze(rot)-1*(C**0.5) CIminus[CIminus<0]=0 slipCIplus=(CIplus[iss]**2+CIplus[ids]**2)**0.5 slipCIminus=(CIminus[iss]**2+CIminus[ids]**2)**0.5 #Now parse for multiple rupture speeds unum=unique(num) #Count number of windows nwin=len(where(num==unum[0])[0]) #Get rigidities mu=f[0:len(unum),13] #Get rise times rise_time=f[0:len(unum),7] #Get areas area=f[0:len(unum),10]*f[0:len(unum),11] #Get coordinates and compute distances source=f[0:len(unum),1:4] d=d2epi(epicenter,source) #Define velocity limits vfast=3.8 vslow=1.0 #Get indices for plot istrike=zeros(nstrike*ndip) idip=zeros(nstrike*ndip) k=0 for i in range(ndip): for j in range(nstrike): istrike[k]=nstrike-j-1 idip[k]=i k+=1 #Define canvas fig, axarr = plt.subplots(ndip, nstrike) #Loop over subfaults Mmax=0 for kfault in range(nfault): if kfault%10==0: print '... working on subfault '+str(kfault)+' of '+str(nfault) #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 covfile !=None: 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) #Track maximum moment Mmax=max(Mmax,M1.max()) #Done now plot them #get current axis ax=axarr[idip[kfault], istrike[kfault]] #Make contourf Mc=linspace(0,0.98*max(M1),100) T,M=meshgrid(t1,Mc) i=where(T==0)[0] T[i]=0.01 V=d[kfault]/T im=ax.contourf(T,M,V,100,vmin=vslow,vmax=vfast,cmap=cm.spectral) #Cover upper part ax.fill_between(t1,y1=M1,y2=1.01*M1.max(),color='white') #Plot confidence intervals if covfile !=None: ax.fill_between(t1,M1minus,M1plus,facecolor='grey',alpha=0.4) ax.plot(t1,M1plus,color='black') ax.plot(t1,M1minus,color='white',lw=2) #Plot curve ax.plot(t1, M1,color='k') ax.grid() ax.set_xlim([t1[0],t1[-1]]) ax.xaxis.set_ticks(linspace(t1[0],t1[-1],5)) ax.xaxis.set_ticklabels([]) ax.yaxis.set_ticklabels([]) #Go back and rescale all subplots by maximum moment for k in range(ndip): for k2 in range(nstrike): ax=axarr[k,k2] ax.set_ylim([0,Mmax]) #Fix subplot arrangement plt.subplots_adjust(left=0.02, bottom=0.02, right=0.9, top=0.98, wspace=0, hspace=0) #Add colorbar cbar_ax = fig.add_axes([0.91, 0.15, 0.01, 0.7]) cb=fig.colorbar(im, cax=cbar_ax) cb.set_label('Reference rupture velocity (km/s)') print 'Maximum moment was '+str(Mmax)+'N-m'