def moveoutcorrect(self, ref_rayp=0.06, dep_range=np.arange(0, 150), velmod='iasp91', replace=False): """Moveout correction with specified reference ray-parameter and depth :param ref_rayp: reference ray-parameter in s/km, defaults to 0.06 :type ref_rayp: float, optional :param dep_range: Depth range used for extracting velocity in velocity model, defaults to np.arange(0, 150) :type dep_range: :meth:`np.ndarray`, optional :param velmod: Velocity model for moveout correction. 'iasp91', 'prem' and 'ak135' is valid for internal model. Specify path to velocity model for the customized model. The format is the same as in Taup, but the depth should be monotonically increasing, defaults to 'iasp91' :type velmod: str, optional :param replace: whether replace original data, False to return new array, defaults to False :type replace: bool, optional Returns ------- rf_corr: :meth:`np.ndarray` Corrected RFs with component of :meth:`RFStation.comp` t_corr: :meth:`np.ndarray` or ``None`` Corrected RFs in transverse component. If ``only_r`` is ``True``, this variable is ``None`` """ if not self.only_r: t_corr, _ = moveoutcorrect_ref(self, skm2srad(ref_rayp), dep_range, chan='t', velmod=velmod) else: t_corr = None if 'datar' in self.__dict__: chan = 'r' elif 'dataz' in self.__dict__: chan = 'z' elif 'datal' in self.__dict__: chan = 'l' else: pass rf_corr, _ = moveoutcorrect_ref(self, skm2srad(ref_rayp), dep_range, chan=chan, velmod=velmod) if replace: self.__dict__['data{}'.format(chan)] = rf_corr if not self.only_r: self.datat = t_corr else: return rf_corr, t_corr
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 __init__(self, path): fnames = sorted(glob.glob(join(path, '*S_*.sac'))) self.ev_num = len(fnames) self.rayp = np.zeros(self.ev_num) self.bazi = np.zeros(self.ev_num) self.dis = np.zeros(self.ev_num) self.evla = np.zeros(self.ev_num) self.evlo = np.zeros(self.ev_num) self.evdp = np.zeros(self.ev_num) sample_sac = SACTrace.read(fnames[0]) self.sampling = sample_sac.delta self.stla = sample_sac.stla self.stlo = sample_sac.stlo self.shift = -sample_sac.b self.RFlength = sample_sac.npts self.datal = np.zeros([self.ev_num, self.RFlength]) for i, sacfile in enumerate(fnames): sac = SACTrace.read(sacfile) self.rayp[i] = sac.user0 self.bazi[i] = sac.baz self.dis[i] = sac.gcarc self.evla[i] = sac.evla self.evlo[i] = sac.evlo self.evdp[i] = sac.evdp self.datal[i] = sac.data self.rayp = skm2srad(self.rayp)
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))
def __init__(self, evt_lst, only_r=False): """ :param evt_lst: event list in RF data dir. Column as date string, phase, evt lat, evt lon, evt dep, distance, back-azimuth, ray parameter, magnitude and gauss factor. """ self.only_r = only_r data_path = dirname(evt_lst) dtype = { 'names': ('evt', 'phase', 'evlat', 'evlon', 'evdep', 'dis', 'bazi', 'rayp', 'mag', 'f0'), 'formats': ('U20', 'U20', 'f4', 'f4', 'f4', 'f4', 'f4', 'f4', 'f4', 'f4') } self.event, self.phase, self.evla, self.evlo, self.evdp, self.dis, self.bazi, self.rayp, self.mag, self.f0 = \ np.loadtxt(evt_lst, dtype=dtype, unpack=True, ndmin=1) # self.event = [datestr.decode() for datestr in self.event] # self.phase = [ph.decode() for ph in self.phase] self.rayp = skm2srad(self.rayp) self.ev_num = self.evla.shape[0] sample_sac = SACTrace.read( join(data_path, self.event[0] + '_' + self.phase[0] + '_R.sac')) self.stla = sample_sac.stla self.stlo = sample_sac.stlo self.RFlength = sample_sac.npts self.shift = -sample_sac.b self.sampling = sample_sac.delta self.datar = np.empty([self.ev_num, self.RFlength]) if not only_r: self.datat = np.empty([self.ev_num, self.RFlength]) for _i, evt, ph in zip(range(self.ev_num), self.event, self.phase): sac = SACTrace.read(join(data_path, evt + '_' + ph + '_R.sac')) sact = SACTrace.read(join(data_path, evt + '_' + ph + '_T.sac')) self.datar[_i] = sac.data self.datat[_i] = sact.data else: for _i, evt, ph in zip(range(self.ev_num), self.event, self.phase): sac = SACTrace.read(join(data_path, evt + '_' + ph + '_R.sac')) self.datar[_i] = sac.data
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
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
def psrf2depth(stadatar, YAxisRange, sampling, shift, velmod='iasp91', velmod_3d=None, srayp=None): """ :param stadatar: :param YAxisRange: :param sampling: :param shift: :param velmod: :return: """ dep_mod = DepModel(YAxisRange, velmod) if velmod_3d is not None: dep_mod.vp, dep_mod.vs = interp_depth_model(velmod_3d, stadatar.stla, stadatar.stlo, YAxisRange) 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]]) if srayp is None: for i in range(stadatar.ev_num): x_s[i] = np.cumsum( (dep_mod.dz / dep_mod.R) / np.sqrt((1. / (stadatar.rayp[i]**2. * (dep_mod.R / dep_mod.vs)**-2)) - 1)) x_p[i] = np.cumsum( (dep_mod.dz / dep_mod.R) / np.sqrt((1. / (stadatar.rayp[i]**2. * (dep_mod.R / dep_mod.vp)**-2)) - 1)) 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)) 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[i] = np.cumsum( (dep_mod.dz / dep_mod.R) / np.sqrt((1. / (rayp**2. * (dep_mod.R / dep_mod.vs)**-2)) - 1)) x_p[i] = np.cumsum( (dep_mod.dz / dep_mod.R) / np.sqrt((1. / (stadatar.rayp[i]**2. * (dep_mod.R / dep_mod.vp)**-2)) - 1)) 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)) else: raise TypeError('srayp should be path to Ps rayp lib') time_axis = np.arange(0, stadatar.RFlength) * sampling - shift PS_RFdepth = np.zeros([stadatar.ev_num, dep_mod.depths.shape[0]]) EndIndex = np.zeros(stadatar.ev_num) for i in range(stadatar.ev_num): TempTpds = Tpds[i, :] StopIndex = np.where(np.imag(TempTpds) == 1)[0] if StopIndex.size == 0: EndIndex[i] = dep_mod.depths.shape[0] DepthAxis = interp1d(TempTpds, dep_mod.depths, bounds_error=False)(time_axis) else: EndIndex[i] = StopIndex[0] - 1 DepthAxis = interp1d(TempTpds[0:StopIndex], dep_mod.depths[0:StopIndex], bounds_error=False)(time_axis) PS_RFTempAmps = stadatar.datar[i] ValueIndices = np.where(np.logical_not(np.isnan(DepthAxis)))[0] if ValueIndices.size == 0: continue elif np.max(ValueIndices) > PS_RFTempAmps.shape[0]: continue else: PS_RFAmps = interp1d(DepthAxis[ValueIndices], PS_RFTempAmps[ValueIndices], bounds_error=False)(YAxisRange) PS_RFdepth[i] = PS_RFAmps / np.nanmax(PS_RFAmps) return PS_RFdepth, EndIndex, x_s, x_p
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
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
def psrf2depth(stadatar, YAxisRange, velmod='iasp91', srayp=None, normalize='single', sphere=True, phase=1): """ Time-to-depth conversion with S-wave backprojection. :param stadatar: Data class of RFStation :type stadatar: :meth:`RFStation` :param YAxisRange: Depth range for converison :type YAxisRange: numpy.ndarray :param velmod: Velocity for conversion, whcih can be a path to velocity file, defaults to 'iasp91' :type velmod: str, optional :param srayp: ray-parameter library of conversion phases. See :meth:`seispy.psrayp` in detail, defaults to None :type srayp: str or :meth:`seispy.psrayp.PsRayp`, optional :param normalize: method of normalization, defaults to 'single'. Please refer to :meth:`RFStation.normalize` :type normalize: str, optional :param sphere: Wether do earth-flattening transformation, defaults to True :type sphere: bool, optional Returns ------------ ps_rfdepth: 2-D numpy.ndarray, float RFs in depth with shape of ``(stadatar.ev_num, YAxisRange.size)``, ``stadatar.ev_num`` is the number of RFs in current station. ``YAxisRange.size`` is the size of depth axis. endindex: numpy.ndarray, int End index of each RF in depth x_s: 2-D numpy.ndarray, float Horizontal distance between station and S-wave conversion points with shape of ``(stadatar.ev_num, YAxisRange.size)`` x_p: 2-D numpy.ndarray, float Horizontal distance between station and P-wave conversion points with shape of ``(stadatar.ev_num, YAxisRange.size)`` """ if exists(velmod): try: dep_mod = DepModel(YAxisRange, velmod, elevation=stadatar.stel) except: dep_mod = DepModel(YAxisRange, 'iasp91', elevation=stadatar.stel) try: velmod_3d = np.load(velmod) dep_mod.vp, dep_mod.vs = interp_depth_model( velmod_3d, stadatar.stla, stadatar.stlo, dep_mod.depths_elev) except Exception as e: raise FileNotFoundError( 'Cannot load 1D or 3D velocity model of \'{}\''.format( velmod)) else: try: dep_mod = DepModel(YAxisRange, velmod, elevation=stadatar.stel) except: raise ValueError( 'Cannot recognize the velocity model of \'{}\''.format(velmod)) 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]]) if srayp is None: for i in range(stadatar.ev_num): tps[i], x_s[i], x_p[i] = xps_tps_map(dep_mod, stadatar.rayp[i], stadatar.rayp[i], sphere=sphere, phase=phase) 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 was 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[i], x_p[i] = xps_tps_map(dep_mod, rayp, stadatar.rayp[i], sphere=sphere, phase=phase) else: raise TypeError('srayp should be path to Ps rayp lib') ps_rfdepth, endindex = time2depth(stadatar, dep_mod.depths, tps, normalize=normalize) return ps_rfdepth, endindex, x_s, x_p
def __init__(self, data_path, only_r=False, prime_comp='R'): """ Class for derivative process of RFs. :param data_path: Path to RF data with SAC format. A finallist.dat must be in this path. :type data_path: str :param only_r: Whether reading transverse RFs, defaults to False :type only_r: bool, optional :param prime_comp: Prime component in RF filename. ``R`` or ``Q`` for PRF and ``L`` or ``Z`` for SRF :type prime_comp: str .. warning:: This Class will be renamed to ``RFStation`` in future versions. """ self.only_r = only_r self.comp = prime_comp self._chech_comp() if isfile(data_path): data_path = dirname(abspath(data_path)) self.staname = basename(abspath(data_path)) evt_lsts = glob.glob(join(data_path, '*finallist.dat')) if len(evt_lsts) == 0: raise FileNotFoundError( "No such *finallist.dat in the {}".format(data_path)) elif len(evt_lsts) > 1: raise ValueError( "More than one finallist.dat in the {}".format(data_path)) else: evt_lst = evt_lsts[0] self.dtype = { 'names': ('event', 'phase', 'evla', 'evlo', 'evdp', 'dis', 'bazi', 'rayp', 'mag', 'f0'), 'formats': ('U20', 'U20', 'f4', 'f4', 'f4', 'f4', 'f4', 'f4', 'f4', 'f4') } self.event, self.phase, self.evla, self.evlo, self.evdp, self.dis, self.bazi, self.rayp, self.mag, self.f0 = \ np.loadtxt(evt_lst, dtype=self.dtype, unpack=True, ndmin=1) self.rayp = skm2srad(self.rayp) self.ev_num = self.evla.shape[0] self.read_sample(data_path) self.__dict__['data{}'.format(self.comp.lower())] = np.empty( [self.ev_num, self.rflength]) if not only_r: self.datat = np.empty([self.ev_num, self.rflength]) for _i, evt, ph in zip(range(self.ev_num), self.event, self.phase): sac = SACTrace.read( join(data_path, evt + '_' + ph + '_{}.sac'.format(self.comp))) sact = SACTrace.read(join(data_path, evt + '_' + ph + '_T.sac')) self.__dict__['data{}'.format( self.comp.lower())][_i] = sac.data self.datat[_i] = sact.data else: for _i, evt, ph in zip(range(self.ev_num), self.event, self.phase): sac = SACTrace.read( join(data_path, evt + '_' + ph + '_{}.sac'.format(self.comp))) self.__dict__['data{}'.format( self.comp.lower())][_i] = sac.data