def init_profile(lat1, lon1, lat2, lon2, val): """ Initial bins along a profile with given position of two points. :param lat1: The latitude of the start point :type lat1: float :param lon1: The lontitude of the start point :type lon1: float :param lat2: The latitude of the end point :type lat2: float :param lon2: The lontitude of the end point :type lon2: float :param val: The interval between two points in km :type val: float :return: The location of bins (bin_loca), and length between each bin and the start point (profile_range) The bin_loca is positions of bins with a numpy.array with two column. The profile_range is distance between bin center and the start point with an 1D numpy.array. :rtype: (numpy.array, numpy.array) """ azi = distaz(lat1, lon1, lat2, lon2).baz dis = distaz(lat1, lon1, lat2, lon2).delta profile_range = np.arange(0, deg2km(dis), val) lat_loca, lon_loca = latlon_from(lat1, lon1, azi, km2deg(profile_range)) bin_loca = np.zeros([lat_loca.shape[0], 2]) bin_loca = np.vstack((lat_loca, lon_loca)).T return bin_loca, profile_range
def init_profile(lat1, lon1, lat2, lon2, val): azi = distaz(lat1, lon1, lat2, lon2).baz dis = distaz(lat1, lon1, lat2, lon2).delta profile_range = np.arange(0, deg2km(dis), val) lat_loca, lon_loca = latlon_from(lat1, lon1, azi, km2deg(profile_range)) bin_loca = np.zeros([lat_loca.shape[0], 2]) for i in range(lat_loca.shape[0]): bin_loca[i, 0] = lat_loca[i] bin_loca[i, 1] = lon_loca[i] return bin_loca, profile_range
def gen_center_bin(center_lat, center_lon, len_lat, len_lon, val): """ Create spaced grid point with coordinates of the center point in the area in spherical coordinates. :param center_lat: Latitude of the center point. :type center_lat: float :param center_lon: Longitude of the center point. :type center_lon: float :param len_lat: Half length in degree along latitude axis. :type len_lat: float :param len_lon: Half length in degree along longitude axis. :type len_lon: float :param val: Interval in degree between adjacent grid point. :type val: float :return: Coordinates of Grid points. :rtype: 2-D ndarray of floats with shape (n, 2), where n is the number of grid points. """ lats = np.arange(0, 2 * len_lat, val) lons = np.arange(0, 2 * len_lon, val) plat, plon = latlon_from(center_lat, center_lon, 0, 90) da = distaz(plat, plon, center_lat, center_lon) begx = -len_lon begy = -len_lat bin_loca = [] bin_mat = np.zeros([lats.size, lons.size, 2]) bin_map = np.zeros([lats.size, lons.size]).astype(int) n = 0 for j in range(lats.size): delyinc = j * val + begy delt = da.delta + delyinc for i in range(lons.size): azim = da.az + (begx + i * val) / cosd(delyinc) glat, glon = latlon_from(plat, plon, azim, delt) if glon > 180: glon -= 360 bin_loca.append([glat, glon]) bin_mat[j, i, 0] = glat bin_mat[j, i, 1] = glon bin_map[j, i] = n n += 1 return np.array(bin_loca), bin_mat, bin_map
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})
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 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 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)
def gen_profile(lineloca, slid_val): da = distaz(lineloca[0, 0], lineloca[0, 1], lineloca[1, 0], lineloca[1, 1]) profile_range = np.arange(0, da.degreesToKilometers(), slid_val) profile_lat, profile_lon = latlon_from(lineloca[0, 0], lineloca[0, 1], da.baz, profile_range) return da, profile_range, profile_lat, profile_lon