Example #1
0
 def saverf(self,
            path,
            evtstr=None,
            shift=0,
            evla=-12345.,
            evlo=-12345.,
            evdp=-12345.,
            mag=-12345.,
            gauss=0,
            baz=-12345.,
            gcarc=-12345.,
            only_r=False,
            **kwargs):
     if self.phase[-1] == 'P':
         if self.comp == 'lqt':
             svcomp = 'Q'
         else:
             svcomp = 'R'
         if only_r:
             loop_lst = [svcomp]
         else:
             loop_lst = [svcomp, 'T']
         rayp = srad2skm(self.rayp)
     elif self.phase[-1] == 'S':
         if self.comp == 'lqt':
             loop_lst = ['L']
         else:
             loop_lst = ['Z']
         rayp = srad2skm(self.rayp)
     else:
         pass
     if evtstr is None:
         filename = join(path, self.datestr)
     else:
         filename = join(path, evtstr)
     for comp in loop_lst:
         trrf = self.rf.select(channel='*' + comp)[0]
         header = {
             'evla': evla,
             'evlo': evlo,
             'evdp': evdp,
             'mag': mag,
             'baz': baz,
             'gcarc': gcarc,
             'user0': rayp,
             'kuser0': 'Ray Para',
             'user1': gauss,
             'kuser1': 'G factor'
         }
         for key in kwargs:
             header[key] = kwargs[key]
         for key, value in header.items():
             trrf.stats['sac'][key] = value
         tr = SACTrace.from_obspy_trace(trrf)
         tr.b = -shift
         tr.a = 0
         tr.ka = self.phase
         tr.write(filename +
                  '_{0}_{1}.sac'.format(self.phase, tr.kcmpnm[-1]))
Example #2
0
 def syn_tps(self, phase_list, velmodel='iasp91', focal_dep=10):
     model = TauPyModel(model=velmodel)
     phase_list.insert(0, 'P')
     arrs = model.get_travel_times(focal_dep,
                                   self.ref_dis,
                                   phase_list=phase_list)
     p_arr = arrs[0].time
     p_rayp = skm2sdeg(srad2skm(arrs[0].ray_param))
     self.syn_tau = [arr.time - p_arr for arr in arrs[1:]]
     self.syn_drayp = [
         p_rayp - skm2sdeg(srad2skm(arr.ray_param)) for arr in arrs[1:]
     ]
Example #3
0
def PsRayp(layers, dist, dep):
    model = TauPyModel(model="iasp91")
    ph_list = makepheaselist(layers)
    arrs = model.get_ray_paths(dist, dep, ph_list)
    arr_num = len(arrs)
    print(arr_num, len(ph_list))
    rayp_list = np.zeros([arr_num, 2])
    for i in range(arr_num):
        rayp_list[i][0] = srad2skm(arrs[i].ray_param)
        rayp_list[i][1] = int(arrs[i].name.strip('Ps'))
    rayp_list.sort(axis=0)
    return(rayp_list)
Example #4
0
def hksta(hpara, isplot=False):
    station = basename(hpara.rfpath)
    stadata = SACStation(join(hpara.rfpath, station+'finallist.dat'), only_r=True)
    stack, _, allstack, _ = hkstack(stadata.datar, stadata.shift, stadata.sampling, srad2skm(stadata.rayp),
                                    hpara.hrange, hpara.krange, vp=hpara.vp, weight=hpara.weight)
    besth, bestk, cvalue, maxhsig, maxksig = ci(allstack, hpara.hrange, hpara.krange, stadata.ev_num)
    with open(hpara.hklist, 'a') as f:
        f.write('{}\t{:.3f}\t{:.3f}\t{:.1f}\t{:.2f}\t{:.2f}\t{:.3f}\n'.format(station, stadata.stla, stadata.stlo,
                                                                              besth, maxhsig, bestk, maxksig))
    title = '{}\nMoho depth = ${:.1f}\pm{:.2f}$\nV_P/V_S = ${:.2f}\pm{:.3f}$'.format(station, besth,
                                                                                     maxhsig, bestk, maxksig)
    if isplot:
        img_path = join(hpara.hkpath, station+'.pdf')
        plot(stack, allstack, hpara.hrange, hpara.krange, besth, bestk, cvalue, title=title, path=img_path)
    else:
        plot(stack, allstack, hpara.hrange, hpara.krange, besth, bestk, cvalue, title=title)
Example #5
0
def psrf_3D_raytracing(stadatar, YAxisRange, mod3d, srayp=None):
    """
Back ray trace the S wavs with a assumed ray parameter of P.

Parameters
--------------
stla: float
    The latitude of the station
stlo: float
    The longitude of the station
stadatar: object SACStation
    The data class including PRFs and more parameters
YAxisRange: array_like
    The depth array with the same intervals
mod3d: 'Mod3DPerturbation' object
    The 3D velocity model with fields of ``dep``, ``lat``,
    ``lon``, ``vp`` and ``vs``.
    """
    R = 6371 - YAxisRange
    ddepth = np.mean(np.diff(YAxisRange))
    pplat_s = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    pplon_s = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    pplat_p = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    pplon_p = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    x_s = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    x_p = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    Tpds = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    rayps = srad2skm(stadatar.rayp)

    if isinstance(srayp, str) or isinstance(srayp, np.lib.npyio.NpzFile):
        if isinstance(srayp, str):
            if not exists(srayp):
                raise FileNotFoundError('Ps rayp lib file not found')
            else:
                rayp_lib = np.load(srayp)
        else:
            rayp_lib = srayp
    elif srayp is None:
        pass
    else:
        raise TypeError('srayp should be path to Ps rayp lib')

    for i in range(stadatar.ev_num):
        if srayp is None:
            srayps = stadatar.rayp[i]
        else:
            srayps = get_psrayp(rayp_lib, stadatar.dis[i], stadatar.evdp[i],
                                YAxisRange)
            srayps = skm2srad(sdeg2skm(srayps))
        pplat_s[i][0] = pplat_p[i][0] = stadatar.stla
        pplon_s[i][0] = pplon_p[i][0] = stadatar.stlo
        x_s[i][0] = 0
        x_p[i][0] = 0
        vs = np.zeros_like(YAxisRange)
        vp = np.zeros_like(YAxisRange)
        for j, dep in enumerate(YAxisRange[:-1]):
            vs[j] = interpn(
                (mod3d.model['dep'], mod3d.model['lat'], mod3d.model['lon']),
                mod3d.model['vs'], (dep, pplat_s[i, j], pplon_s[i, j]),
                bounds_error=False,
                fill_value=None)
            vp[j] = interpn(
                (mod3d.model['dep'], mod3d.model['lat'], mod3d.model['lon']),
                mod3d.model['vp'], (dep, pplat_p[i, j], pplon_p[i, j]),
                bounds_error=False,
                fill_value=None)
            x_s[i, j + 1] = ddepth * tand(asind(vs[j] * rayps[i])) + x_s[i, j]
            x_p[i, j + 1] = ddepth * tand(asind(vp[j] * rayps[i])) + x_p[i, j]
            pplat_s[i, j + 1], pplon_s[i, j + 1] = latlon_from(
                stadatar.stla, stadatar.stlo, stadatar.bazi[i],
                km2deg(x_s[i, j + 1]))
            pplat_p[i, j + 1], pplon_p[i, j + 1] = latlon_from(
                stadatar.stla, stadatar.stlo, stadatar.bazi[i],
                km2deg(x_p[i, j + 1]))
        Tpds[i] = np.cumsum(
            (np.sqrt((R / vs)**2 - srayps**2) -
             np.sqrt((R / vp)**2 - stadatar.rayp[i]**2)) * (ddepth / R))
    return pplat_s, pplon_s, pplat_p, pplon_p, Tpds
Example #6
0
def psrf_3D_raytracing(stadatar,
                       YAxisRange,
                       mod3d,
                       srayp=None,
                       elevation=0,
                       sphere=True):
    """
    Back ray trace the S wavs with a assumed ray parameter of P.

    :param stadatar: The data class including PRFs and more parameters
    :type stadatar: object RFStation
    :param YAxisRange: The depth array with the same intervals
    :type YAxisRange: numpy.ndarray
    :param mod3d:  The 3D velocity model with fields of ``dep``, ``lat``,
                    ``lon``, ``vp`` and ``vs``.
    :type mod3d: 'Mod3DPerturbation' object
    :param elevation: Elevation of this station relative to sea level
    :type elevation: float
    :return: pplat_s, pplon_s, pplat_p, pplon_p, tps
    :type: numpy.ndarray * 5
    """
    if sphere:
        R = 6371.0 - YAxisRange + elevation
    else:
        R = 6371.0 + elevation
    dep_range = YAxisRange.copy()
    YAxisRange -= elevation
    ddepth = np.mean(np.diff(YAxisRange))
    pplat_s = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    pplon_s = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    pplat_p = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    pplon_p = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    x_s = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    x_p = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    tps = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    rayps = srad2skm(stadatar.rayp)

    if isinstance(srayp, str) or isinstance(srayp, np.lib.npyio.NpzFile):
        if isinstance(srayp, str):
            if not exists(srayp):
                raise FileNotFoundError('Ps rayp lib file not found')
            else:
                rayp_lib = np.load(srayp)
        else:
            rayp_lib = srayp
    elif srayp is None:
        pass
    else:
        raise TypeError('srayp should be path to Ps rayp lib')

    for i in range(stadatar.ev_num):
        if srayp is None:
            srayps = stadatar.rayp[i]
        else:
            srayps = get_psrayp(rayp_lib, stadatar.dis[i], stadatar.evdp[i],
                                YAxisRange)
            srayps = skm2srad(sdeg2skm(srayps))
        pplat_s[i][0] = pplat_p[i][0] = stadatar.stla
        pplon_s[i][0] = pplon_p[i][0] = stadatar.stlo
        x_s[i][0] = 0
        x_p[i][0] = 0
        vs = np.zeros_like(YAxisRange)
        vp = np.zeros_like(YAxisRange)
        for j, dep in enumerate(YAxisRange[:-1]):
            vs[j] = interpn(
                (mod3d.model['dep'], mod3d.model['lat'], mod3d.model['lon']),
                mod3d.model['vs'], (dep, pplat_s[i, j], pplon_s[i, j]),
                bounds_error=False,
                fill_value=None)
            vp[j] = interpn(
                (mod3d.model['dep'], mod3d.model['lat'], mod3d.model['lon']),
                mod3d.model['vp'], (dep, pplat_p[i, j], pplon_p[i, j]),
                bounds_error=False,
                fill_value=None)
            x_s[i, j + 1] = ddepth * tand(asind(vs[j] * rayps[i])) + x_s[i, j]
            x_p[i, j + 1] = ddepth * tand(asind(vp[j] * rayps[i])) + x_p[i, j]
            pplat_s[i, j + 1], pplon_s[i, j + 1] = latlon_from(
                stadatar.stla, stadatar.stlo, stadatar.bazi[i],
                km2deg(x_s[i, j + 1]))
            pplat_p[i, j + 1], pplon_p[i, j + 1] = latlon_from(
                stadatar.stla, stadatar.stlo, stadatar.bazi[i],
                km2deg(x_p[i, j + 1]))
        tps_corr = np.cumsum(
            (np.sqrt((R / vs)**2 - srayps**2) -
             np.sqrt((R / vp)**2 - stadatar.rayp[i]**2)) * (ddepth / R))
        if elevation != 0:
            tps[i] = interp1d(YAxisRange, tps_corr)(dep_range)
    return pplat_s, pplon_s, pplat_p, pplon_p, tps