示例#1
0
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
示例#2
0
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
示例#3
0
f = np.genfromtxt(
    u'/Users/dmelgar/Slip_inv/iquique_joint/data/model_info/iquique_coarse.fault'
)
out = '/Users/dmelgar/code/GMT/Iquique/rupt_vel/'
lon = f[:, 1]
lat = f[:, 2]
z = f[:, 3]

loni, lati = np.mgrid[min(lon):max(lon):600j, min(lat):max(lat):600j]
zi = griddata((lon, lat), z, (loni, lati))
i, j = np.where(np.isnan(zi) != True)

lon = loni[i, j]
lat = lati[i, j]
z = zi[i, j]

source = np.c_[lon, lat, z]
d = d2epi(epicenter, source)
t = np.arange(1, 150, 1)
v = 2.0
for k in range(len(t)):
    i1 = np.where(d < v * t[k] + 1)[0]
    i2 = np.where(d > v * t[k] - 1)[0]
    i = np.intersect1d(i1, i2)
    lonout = lon[i]
    latout = lat[i]
    outdata = np.c_[lonout, latout]
    np.savetxt(out + 'v' + str(v) + '.' + rjust(str(k), 4, '0') + '.velfile',
               outdata,
               fmt='%.4f\t%.4f')
示例#4
0
f=np.genfromtxt(u'/Users/dmelgarm/Research/Slip_Inv/tohoku_10s/data/model_info/tohoku.fault')
out='/Users/dmelgarm/scripts/GMT/RTOkada/'
lon=f[:,1]
lat=f[:,2]
z=f[:,3]

loni,lati=np.mgrid[min(lon):max(lon):600j,min(lat):max(lat):600j]
zi=griddata((lon,lat),z,(loni,lati))
i,j=np.where(np.isnan(zi)!=True)

lon=loni[i,j]
lat=lati[i,j]
z=zi[i,j]

source=np.c_[lon,lat,z]
d=d2epi(epicenter,source)
t=np.arange(1,205,1)
v=1.5
for k in range(len(t)):
    i1=np.where(d<v*t[k]+1)[0]
    i2=np.where(d>v*t[k]-1)[0]
    i=np.intersect1d(i1,i2)
    lonout=lon[i]
    latout=lat[i]
    outdata=np.c_[lonout,latout]
    np.savetxt(out+'v'+str(v)+'.'+rjust(str(k),4,'0')+'.velfile',outdata,fmt='%.4f\t%.4f')
    
    
    
    
示例#5
0
文件: view.py 项目: degoldbe/mudpyseg
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'