Beispiel #1
0
def _sta_val(stack_range, radius):
    dep_mod = DepModel(stack_range)
    x_s = np.cumsum((dep_mod.dz / dep_mod.R) /
                    np.sqrt((1. / (skm2srad(0.08)**2. *
                                   (dep_mod.R / dep_mod.vs)**-2)) - 1))
    dis = radius + rad2deg(x_s[-1]) + 0.5
    return dis
def makedata(cpara, velmod3d=None, log=setuplog()):
    if velmod3d is not None:
        if isinstance(velmod3d, str):
            if exists(velmod3d):
                model_3d = np.load(velmod3d)
            else:
                model_3d = None
        else:
            raise ValueError('Path to 3d velocity model should be in str')
    else:
        model_3d = None
    # cpara = ccppara(cfg_file)
    sta_info = Station(cpara.stalist)
    RFdepth = []
    for i in range(sta_info.stla.shape[0]):
        rfdep = {}
        evt_lst = join(cpara.rfpath, sta_info.station[i],
                       sta_info.station[i] + 'finallist.dat')
        stadatar = SACStation(evt_lst, only_r=True)
        log.RF2depthlog.info('the {}th/{} station with {} events'.format(
            i + 1, sta_info.stla.shape[0], stadatar.ev_num))
        piercelat = np.zeros([stadatar.ev_num, cpara.depth_axis.shape[0]])
        piercelon = np.zeros([stadatar.ev_num, cpara.depth_axis.shape[0]])
        PS_RFdepth, end_index, x_s, x_p = psrf2depth(stadatar,
                                                     cpara.depth_axis,
                                                     stadatar.sampling,
                                                     stadatar.shift,
                                                     cpara.velmod,
                                                     velmod_3d=model_3d,
                                                     srayp=cpara.rayp_lib)
        for j in range(stadatar.ev_num):
            piercelat[j], piercelon[j] = latlon_from(sta_info.stla[i],
                                                     sta_info.stlo[i],
                                                     stadatar.bazi[j],
                                                     rad2deg(x_s[j]))
        rfdep['Station'] = sta_info.station[i]
        rfdep['stalat'] = sta_info.stla[i]
        rfdep['stalon'] = sta_info.stlo[i]
        # rfdep['Depthrange'] = cpara.depth_axis
        # rfdep['events'] = _convert_str_mat(stadatar.event)
        rfdep['bazi'] = stadatar.bazi
        rfdep['rayp'] = stadatar.rayp
        # rfdep['phases'] = _convert_str_mat(stadatar.phase)
        rfdep['moveout_correct'] = PS_RFdepth
        rfdep['Piercelat'] = piercelat
        rfdep['Piercelon'] = piercelon
        rfdep['StopIndex'] = end_index
        RFdepth.append(rfdep)
    savemat(cpara.depthdat, {'RFdepth': RFdepth})
Beispiel #3
0
 def _select_sta(self):
     if exists(self.cpara.stack_sta_list):
         self.logger.CCPlog.info('Use stacking stations in {}'.format(
             self.cpara.stack_sta_list))
         self.idxs = []
         for sta in self.stations.station:
             try:
                 idx = self.staname.index(sta)
                 self.idxs.append(idx)
             except ValueError:
                 self.logger.CCPlog.warning(
                     '{} does not in RFdepth structure'.format(sta))
             if self.cpara.shape == 'rect' and self.cpara.adaptive == False:
                 self._pierce_project(self.rfdep[idx])
     elif self.cpara.width is None and self.cpara.shape == 'circle':
         dep_mod = DepModel(self.cpara.stack_range)
         x_s = np.cumsum((dep_mod.dz / dep_mod.R) /
                         np.sqrt((1. / (skm2srad(0.085)**2. *
                                        (dep_mod.R / dep_mod.vs)**-2)) - 1))
         dis = self.fzone[-1] + rad2deg(x_s[-1]) + 0.3
         # self.idxs = self._proj_sta(dis)
         self.idxs = []
         for i, bin_info in enumerate(self.bin_loca):
             self.idxs.append(
                 np.where(
                     distaz(bin_info[0], bin_info[1], self.stalst[:, 0],
                            self.stalst[:, 1]).delta <= dis)[0])
     elif self.cpara.width is not None and self.cpara.shape == 'rect':
         self.logger.CCPlog.info(
             'Select stations within {} km perpendicular to the profile'.
             format(self.cpara.width))
         self.idxs = self._proj_sta(self.cpara.width)
         self._write_sta()
     else:
         if self.cpara.width is not None:
             self.logger.CCPlog.error(
                 'Width of profile was set, the bin shape of {} is invalid'.
                 format(self.cpara.shape))
             raise ValueError(
                 'Width of profile was set, the bin shape of {} is invalid'.
                 format(self.cpara.shape))
         else:
             self.logger.CCPlog.error(
                 'Width of profile was not set, the bin shape of {} is invalid'
                 .format(self.cpara.shape))
             raise ValueError(
                 'Width of profile was not set, the bin shape of {} is invalid'
                 .format(self.cpara.shape))
Beispiel #4
0
def psrf_1D_raytracing(stadatar, YAxisRange, velmod='iasp91', srayp=None):
    dep_mod = DepModel(YAxisRange, velmod)

    # x_s = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    raylength_s = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    pplat_s = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    pplon_s = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    # x_p = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    raylength_p = 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]])
    Tpds = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    if srayp is None:
        for i in range(stadatar.ev_num):
            x_s = np.cumsum((dep_mod.dz / dep_mod.R) /
                            np.sqrt((1. / (stadatar.rayp[i]**2. *
                                           (dep_mod.R / dep_mod.vs)**-2)) - 1))
            raylength_s[i] = (dep_mod.dz * dep_mod.R) / (np.sqrt(
                ((dep_mod.R / dep_mod.vs)**2) -
                (stadatar.rayp[i]**2)) * dep_mod.vs)
            x_p = np.cumsum((dep_mod.dz / dep_mod.R) /
                            np.sqrt((1. / (stadatar.rayp[i]**2. *
                                           (dep_mod.R / dep_mod.vp)**-2)) - 1))
            raylength_p[i] = (dep_mod.dz * dep_mod.R) / (np.sqrt(
                ((dep_mod.R / dep_mod.vp)**2) -
                (stadatar.rayp[i]**2)) * dep_mod.vp)
            Tpds[i] = np.cumsum(
                (np.sqrt((dep_mod.R / dep_mod.vs)**2 - stadatar.rayp[i]**2) -
                 np.sqrt((dep_mod.R / dep_mod.vp)**2 - stadatar.rayp[i]**2)) *
                (dep_mod.dz / dep_mod.R))
            pplat_s[i], pplon_s[i] = latlon_from(stadatar.stla, stadatar.stlo,
                                                 stadatar.bazi[i],
                                                 rad2deg(x_s))
            pplat_p[i], pplon_p[i] = latlon_from(stadatar.stla, stadatar.stlo,
                                                 stadatar.bazi[i],
                                                 rad2deg(x_p))
    elif 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
        for i in range(stadatar.ev_num):
            rayp = get_psrayp(rayp_lib, stadatar.dis[i], stadatar.evdp[i],
                              dep_mod.depths)
            rayp = skm2srad(sdeg2skm(rayp))
            x_s = np.cumsum(
                (dep_mod.dz / dep_mod.R) /
                np.sqrt((1. / (rayp**2. * (dep_mod.R / dep_mod.vs)**-2)) - 1))
            raylength_s[i] = (dep_mod.dz * dep_mod.R) / (np.sqrt((
                (dep_mod.R / dep_mod.vs)**2) - (rayp**2)) * dep_mod.vs)
            x_p = np.cumsum((dep_mod.dz / dep_mod.R) /
                            np.sqrt((1. / (stadatar.rayp[i]**2. *
                                           (dep_mod.R / dep_mod.vp)**-2)) - 1))
            raylength_p[i] = (dep_mod.dz * dep_mod.R) / (np.sqrt(
                ((dep_mod.R / dep_mod.vp)**2) -
                (stadatar.rayp[i]**2)) * dep_mod.vp)
            Tpds[i] = np.cumsum(
                (np.sqrt((dep_mod.R / dep_mod.vs)**2 - rayp**2) -
                 np.sqrt((dep_mod.R / dep_mod.vp)**2 - stadatar.rayp[i]**2)) *
                (dep_mod.dz / dep_mod.R))
            x_s = _imag2nan(x_s)
            x_p = _imag2nan(x_p)
            pplat_s[i], pplon_s[i] = latlon_from(stadatar.stla, stadatar.stlo,
                                                 stadatar.bazi[i],
                                                 rad2deg(x_s))
            pplat_p[i], pplon_p[i] = latlon_from(stadatar.stla, stadatar.stlo,
                                                 stadatar.bazi[i],
                                                 rad2deg(x_p))
    else:
        raise TypeError('srayp should be path to Ps rayp lib')
    return pplat_s, pplon_s, pplat_p, pplon_p, raylength_s, raylength_p, Tpds
Beispiel #5
0
def psrf_1D_raytracing(stadatar,
                       YAxisRange,
                       velmod='iasp91',
                       srayp=None,
                       sphere=True,
                       phase=1):
    dep_mod = DepModel(YAxisRange, velmod, stadatar.stel)

    # x_s = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    raylength_s = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    pplat_s = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    pplon_s = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    # x_p = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    raylength_p = 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]])
    tps = np.zeros([stadatar.ev_num, YAxisRange.shape[0]])
    if srayp is None:
        for i in range(stadatar.ev_num):
            tps[i], x_s, x_p, raylength_s[i], raylength_p[i] = xps_tps_map(
                dep_mod,
                stadatar.rayp[i],
                stadatar.rayp[i],
                is_raylen=True,
                sphere=sphere,
                phase=phase)
            pplat_s[i], pplon_s[i] = latlon_from(stadatar.stla, stadatar.stlo,
                                                 stadatar.bazi[i],
                                                 rad2deg(x_s))
            pplat_p[i], pplon_p[i] = latlon_from(stadatar.stla, stadatar.stlo,
                                                 stadatar.bazi[i],
                                                 rad2deg(x_p))
    elif 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
        for i in range(stadatar.ev_num):
            rayp = get_psrayp(rayp_lib, stadatar.dis[i], stadatar.evdp[i],
                              dep_mod.depths_elev)
            rayp = skm2srad(sdeg2skm(rayp))
            tps[i], x_s, x_p, raylength_s[i], raylength_p[i] = xps_tps_map(
                dep_mod,
                rayp,
                stadatar.rayp[i],
                is_raylen=True,
                sphere=sphere,
                phase=phase)
            x_s = _imag2nan(x_s)
            x_p = _imag2nan(x_p)
            pplat_s[i], pplon_s[i] = latlon_from(stadatar.stla, stadatar.stlo,
                                                 stadatar.bazi[i],
                                                 rad2deg(x_s))
            pplat_p[i], pplon_p[i] = latlon_from(stadatar.stla, stadatar.stlo,
                                                 stadatar.bazi[i],
                                                 rad2deg(x_p))
    else:
        raise TypeError('srayp should be path to Ps rayp lib')
    return pplat_s, pplon_s, pplat_p, pplon_p, raylength_s, raylength_p, tps
Beispiel #6
0
def makedata(cpara, velmod3d=None, modfolder1d=None, log=setuplog()):
    ismod1d = False
    if velmod3d is not None:
        if isinstance(velmod3d, str):
            velmod = velmod3d
        else:
            raise ValueError('Path to 3d velocity model should be in str')
    elif modfolder1d is not None:
        if isinstance(modfolder1d, str):
            if exists(modfolder1d):
                ismod1d = True
            else:
                raise FileNotFoundError(
                    'No such folder of {}'.format(modfolder1d))
        else:
            ValueError('Path to 1d velocity model files should be in str')
    else:
        ismod1d = True

    # cpara = ccppara(cfg_file)
    sta_info = Station(cpara.stalist)
    RFdepth = []
    for i in range(sta_info.stla.shape[0]):
        rfdep = {}
        evt_lst = join(cpara.rfpath, sta_info.station[i],
                       sta_info.station[i] + 'finallist.dat')
        stadatar = RFStation(evt_lst, only_r=True)
        stadatar.stel = sta_info.stel[i]
        stadatar.stla = sta_info.stla[i]
        stadatar.stlo = sta_info.stlo[i]
        log.RF2depthlog.info('the {}th/{} station with {} events'.format(
            i + 1, sta_info.stla.shape[0], stadatar.ev_num))
        piercelat = np.zeros([stadatar.ev_num, cpara.depth_axis.shape[0]])
        piercelon = np.zeros([stadatar.ev_num, cpara.depth_axis.shape[0]])
        if stadatar.prime_phase == 'P':
            sphere = True
        else:
            sphere = False
        if ismod1d:
            if modfolder1d is not None:
                velmod = _load_mod(modfolder1d, sta_info.station[i])
            else:
                velmod = cpara.velmod
        PS_RFdepth, end_index, x_s, _ = psrf2depth(stadatar,
                                                   cpara.depth_axis,
                                                   velmod=velmod,
                                                   srayp=cpara.rayp_lib,
                                                   sphere=sphere,
                                                   phase=cpara.phase)
        for j in range(stadatar.ev_num):
            piercelat[j], piercelon[j] = latlon_from(sta_info.stla[i],
                                                     sta_info.stlo[i],
                                                     stadatar.bazi[j],
                                                     rad2deg(x_s[j]))
        rfdep['station'] = sta_info.station[i]
        rfdep['stalat'] = sta_info.stla[i]
        rfdep['stalon'] = sta_info.stlo[i]
        rfdep['depthrange'] = cpara.depth_axis
        # rfdep['events'] = _convert_str_mat(stadatar.event)
        rfdep['bazi'] = stadatar.bazi
        rfdep['rayp'] = stadatar.rayp
        # rfdep['phases'] = stadatar.phase[i]
        rfdep['moveout_correct'] = PS_RFdepth
        rfdep['piercelat'] = piercelat
        rfdep['piercelon'] = piercelon
        rfdep['stopindex'] = end_index
        RFdepth.append(rfdep)
    # savemat(cpara.depthdat, {'RFdepth': RFdepth})
    np.save(cpara.depthdat, RFdepth)