2024-01-12 py版本的taup

def trav(thk,v,dist,ns):  # n=0 means surface n is the bottom of the layer
    v = 1/(v)**2
    lmax = ns
    jo = len(thk)
    t0,p0 = find2(dist,lmax,v,ns,thk)
    for lmax in range(ns+1,jo):
        t,p = find2(dist,lmax,v,ns,thk)
        if (t<t0):
            t0 = t
            p0 = p
    return t0.real,p0.real

def find2(dist,lmax,v,ns,thk):
    p1 = 1e-20j
    pm = 9999 
    for i in range(lmax):
        pm = np.min((pm,v[lmax-1]))
    p2 = np.sqrt(pm)+p1
    p0 = 0.5*(p1+p2)
    while((p2-p1)>1e-6):
        dtdp0 = dtdp(dist,p0,ns,lmax,v,thk)
        if np.abs(dtdp0)<1e-10:
            pm =np.min((pm,v[lmax])) 
        if dtdp0>0:
            p1 = p0
        else:
            p2 = p0
        p0 = 0.5*(p1+p2)
    pm = np.sqrt(pm)
    if (lmax<len(v)-1):
        if (lmax>ns) and pm<np.real(p0):
            p0 = pm
    t0 = taup(p0,dist,ns,lmax,v,thk)
    return t0,p0

def taup(p,dist,ns,lmax,v,thk):
    tau = p*dist
    pp = p*p
    for i in range(ns):
        tau = tau+np.sqrt(v[i]-pp)*thk[i]
    for i in range(ns,lmax):
        tau = tau+np.sqrt(v[i]-pp)*thk[i]*2
    return tau

def dtdp(dist,p,ns,lmax,v,thk): 
    pp = p*p
    dtdp=0
    for i in range(ns):
        dtdp = dtdp-thk[i]/np.sqrt(v[i]-pp)
    for i in range(ns,lmax):
        dtdp = dtdp-2*thk[i]/np.sqrt(v[i]-pp)
    dtdp = dist+p*dtdp
    return dtdp
#     print('fine')

model = np.array(([5.43, 0.00],
[5.80, 5.00],
[5.90, 8.00],
[5.95,11.00],
[6.00,14.00],
[6.09,20.00],
[6.27,30.00],
[6.50,45.00],
[8.00,55.00]))

thick = np.hstack((0,np.diff(model[:,1])))
vp = model[:,0]
vs = vp/1.73


tp = np.array([trav(thick,vp,dist,2)[0] for j,dist in enumerate(dists)]) 
ts = np.array([trav(thick,vs,dist,2)[0] for j,dist in enumerate(dists)])

trav(thick,vp,dist,2)中的2代表第三个depth

def trav_dep(model,mode,dist,dep):
    if dep in model[:,1]:
        print('yes')
        thick = np.hstack((0,np.diff(model[:,1])))
        vp = model[:,0]
        vs = vp/1.73
        ind_0 = np.where(model[:,1]==dep)[0][0]
        ind_1 = ind_0+1
        t, p = trav(thick, vp, dist, ind_1)
    else:
        ind_0 = np.where(model[:,1]>dep)[0][0]
        ind_1 = ind_0+1
        model_ = np.zeros((len(model)+1,2))
        model_[:ind_0] = model[:ind_0]
        model_[ind_0] = np.array([(model[ind_0-1][0]+model[ind_1-1][0])/2, dep])
        model_[ind_0] = np.array([(model[ind_0-1][0]+model[ind_0-1][0])/2, dep])
        model_[ind_0+1:] = model[ind_0:]
        
        # model = np.concatenate((model[ind_0],[(model[ind_0][0]+model[ind_1][0])/2, dep],model[ind_1:]))
        thick = np.hstack((0,np.diff(model_[:,1])))
        vp = model_[:,0]
        vs = vp/1.73
        if mode=='p':
            t, p = trav(thick, vp, dist, ind_1)
        elif mode=='s':
            t, p = trav(thick, vs, dist, ind_1)
        
    return t, p

Updated

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 我的图书馆 留言交流 2000个最常用的英语单词 2016-05-15酴羰骀璺 2000个最常用的英语单词 (英语...
    Mr_Wang92阅读 730评论 0 0
  • 结果文件的解读 输出文件1:*.variant_function 第一个文件包含所有变异的注释,方法是在每个输入行...
    生信师姐阅读 20,540评论 2 42
  • Linux习惯问题: 在vim编辑时,按了ctrl + s后,再按ctrl + q就可以继续执行了。ctrl + ...
    光着脚的鞋阅读 4,545评论 0 16
  • 虽然考研初试27号就结束了,现在已经过去了三十多天,但是看了看我只看了七八十页的计算机网络,感觉再浪下去要把自己腿...
    进击的苹果阅读 585评论 0 1
  • 一、Android5 1.ANDROID 5.0 行为变更: 声音和振动 (1)如果您当前使用 Ringtone、...
    杰奎琳子阅读 13,509评论 0 24