def boot_stack(ccp_data, bin_loca, depaxis): stack_data = [] for i in range(ccp_data.shape[0]): print('{}/{}'.format(i + 1, bin_loca.shape[0])) boot_stack = {} bin_mu = np.zeros(depaxis.shape[0]) bin_ci = np.zeros([depaxis.shape[0], 2]) bin_count = np.zeros(depaxis.shape[0]) for j in range(depaxis.shape[0]): bin_count[j] = ccp_data[i, j].shape[1] if ccp_data[i, j].shape[1] > 1: cci = ci(ccp_data[i, j], n_samples=2000) bin_ci[j, 0] = cci[0] bin_ci[j, 1] = cci[1] bin_mu[j] = np.average(ccp_data[i, j]) else: bin_ci[j, 0] = np.nan bin_ci[j, 1] = np.nan bin_mu[j] = np.nan boot_stack['bin_lat'] = bin_loca[i, 0] boot_stack['bin_lon'] = bin_loca[i, 1] boot_stack['mu'] = bin_mu boot_stack['ci'] = bin_ci boot_stack['count'] = bin_count stack_data.append(boot_stack) return stack_data
def boot_bin_stack(data_bin): count = data_bin.shape[0] if count > 1: cci = ci(data_bin, n_samples=2000) mu = np.average(data_bin) else: cci = np.array([np.nan, np.nan]) mu = np.nan return mu, cci, count
def search_pierce(rfdep, depaxis, bin_loca, profile_range, bin_radius=75): bin_radius = km2deg(bin_radius) data = [] for i in range(bin_loca.shape[0]): rfbin = {} print('{}/{}'.format(i + 1, bin_loca.shape[0])) ccp_mean = np.zeros(depaxis.shape[0]) ccp_count = np.zeros(depaxis.shape[0]) ccp_ci = np.zeros((depaxis.shape[0], 2)) for j, dep in zip(range(depaxis.shape[0]), depaxis): bin_dep = np.array([]) for sta in rfdep: fall_idx = np.where( distaz(sta['Piercelat'][0, 0][:, dep], sta['Piercelon'][ 0, 0][:, dep], bin_loca[i, 0], bin_loca[i, 1]).delta < bin_radius)[0] bin_dep = np.append( bin_dep, sta['moveout_correct'][0, 0][fall_idx, dep]) if bin_dep.shape[0] > 1: bin_ci = ci(bin_dep, n_samples=2000) bin_mu = np.average(bin_dep) else: bin_ci = (np.nan, np.nan) bin_mu = np.nan ccp_count[j] = bin_dep.shape[0] ccp_mean[j] = bin_mu ccp_ci[j, 0] = bin_ci[0] ccp_ci[j, 1] = bin_ci[1] rfbin['bin_lat'] = bin_loca[i, 0] rfbin['bin_lon'] = bin_loca[i, 1] rfbin['profile_dis'] = profile_range[i] rfbin['mu'] = ccp_mean rfbin['ci'] = ccp_ci rfbin['count'] = ccp_count data.append(rfbin) return data
# pierce_interval = distaz.deg2km(dis_event) * np.abs(distaz.cosd(azi - azi_event)) if np.abs(dis_along - Profile_range[i] ) < bin_radius and dis_proj < seispy.geo.deg2km( bin_radius): # print(pierce_interval, azi - azi_event, bin_radius) # Stack_RF = Stack_RF + RFdepth[0, k]['moveout_correct'][2*Stack_range[j], l] Stack_RF = np.append( Stack_RF, RFdepth[0, k]['moveout_correct'][2 * Stack_range[j], l]) Event_count = Event_count + 1 if isboot: if Event_count > 1: straptimes = int(Event_count * 2) ci = boot.ci(Stack_RF, n_samples=straptimes, method='pi') mu = np.average(Stack_RF) else: ci = np.zeros(2) if j == 0: mu = np.nan ci = np.array([np.nan, np.nan]) fid.write('%-8.3f %-8.3f %-6.3f %-6.3f %-8.3f %-8.3f %-8.3f %d\n' % (Profile_lat[i], Profile_lon[i], Profile_range[i], Stack_range[j], mu, ci[0], ci[1], Event_count)) else: if Event_count > 0: mu = np.mean(Stack_RF) fid.write('%-8.3f %-8.3f %-6.3f %-6.3f %-8.3f %d\n' % (Profile_lat[i], Profile_lon[i], Profile_range[i], Stack_range[j], mu, Event_count))
for l in range(RFdepth[0, k]['Piercelat'].shape[1]): # azi_event = distaz.distaz(Profile_lat[i], Profile_lon[i], RFdepth[0, k]['Piercelat'][l, 0], RFdepth[0, k]['Piercelon'][l, 0]).baz dis_event = seispy.distaz( Profile_lat[i], Profile_lon[i], RFdepth[0, k]['Piercelat'][2 * Stack_range[j], l], RFdepth[0, k]['Piercelon'][2 * Stack_range[j], l]).delta # pierce_interval = distaz.deg2km(dis_event) * np.abs(distaz.cosd(azi - azi_event)) if dis_event < seispy.geo.km2deg(bin_radius): Amp_bin = np.append( Amp_bin, RFdepth[0, k]['moveout_correct'][2 * Stack_range[j], l]) Event_count = Event_count + 1 if Event_count > 1: straptimes = int(Event_count * 2) ci = boot.ci(Amp_bin, n_samples=straptimes, method='pi') mu = np.average(Amp_bin) else: mu = 0 ci = np.zeros(2) # fid.write('%-8.3f %-8.3f %-6.3f %-6.3f %-8.5f %-8.5f %-8.5f %d\n' % (Profile_lat[i], Profile_lon[i], Profile_range[i], Stack_range[j], mu, ci[0], ci[1], Event_count)) mu_arr[j][0] = mu ci_arr[j] = ci Event_count_arr[j][0] = Event_count mu_arr = sm.nonparametric.lowess(mu_arr[:, 0], Stack_range, frac=smooth_para)[:, 1] ci_arr[:, 0] = sm.nonparametric.lowess(ci_arr[:, 0], Stack_range, frac=smooth_para)[:, 1] ci_arr[:, 1] = sm.nonparametric.lowess(ci_arr[:, 1],
pier_lon = RFdepth[0, k]['Piercelon'][2*Stack_range[j], l] pier_azi = seispy.distaz(lat1, lon1, pier_lat, pier_lon).baz pier_dis = seispy.distaz(lat1, lon1, pier_lat, pier_lon).degreesToKilometers() dis_along = pier_dis * seispy.geo.cosd(azi - pier_azi) # (pro_lat, pro_lon) = seispy.geo.latlon_from(lat1, lon1, azi, seispy.geo.km2deg(dis_along)) # dis_event = seispy.distaz(Profile_lat[i], Profile_lon[i], RFdepth[0, k]['Piercelat'][2*Stack_range[j], l], RFdepth[0, k]['Piercelon'][2*Stack_range[j], l]).degreesToKilometers() # pierce_interval = distaz.deg2km(dis_event) * np.abs(distaz.cosd(azi - azi_event)) if np.abs(dis_along - Profile_range[i]) < bin_radius: # print(pierce_interval, azi - azi_event, bin_radius) # Stack_RF = Stack_RF + RFdepth[0, k]['moveout_correct'][2*Stack_range[j], l] Stack_RF = np.append(Stack_RF, RFdepth[0, k]['moveout_correct'][2*Stack_range[j], l]) Event_count = Event_count + 1 if isboot: if Event_count > 1: straptimes = int(Event_count * 2) ci = boot.ci(Stack_RF, n_samples=straptimes, method='pi') mu = np.average(Stack_RF) else: ci = np.zeros(2) if j == 0: mu = np.nan ci = np.array([np.nan, np.nan]) fid.write('%-8.3f %-8.3f %-6.3f %-6.3f %-8.3f %-8.3f %-8.3f %d\n' % (Profile_lat[i], Profile_lon[i], Profile_range[i], Stack_range[j], mu, ci[0], ci[1], Event_count)) else: if Event_count > 0: mu = np.mean(Stack_RF) fid.write('%-8.3f %-8.3f %-6.3f %-6.3f %-8.3f %d\n' % (Profile_lat[i], Profile_lon[i], Profile_range[i], Stack_range[j], mu, Event_count))
# fid.write('%-8.3f %-8.3f %-6.3f %-6.3f %-8.5f %-8.5f %-8.5f %d\n' % (Profile_lat[i], Profile_lon[i], Profile_range[i], Stack_range[j], mu, ci[0], ci[1], Event_count)) # mu_arr[j][0] = np.nan # ci_arr[j] = np.array([np.nan, np.nan]) # Event_count_arr[j][0] = 0 # continue for k in staidx: for l in range(RFdepth[0, k]['Piercelat'].shape[1]): # azi_event = distaz.distaz(Profile_lat[i], Profile_lon[i], RFdepth[0, k]['Piercelat'][l, 0], RFdepth[0, k]['Piercelon'][l, 0]).baz dis_event = seispy.distaz(Profile_lat[i], Profile_lon[i], RFdepth[0, k]['Piercelat'][2*Stack_range[j], l], RFdepth[0, k]['Piercelon'][2*Stack_range[j], l]).delta # pierce_interval = distaz.deg2km(dis_event) * np.abs(distaz.cosd(azi - azi_event)) if dis_event < seispy.geo.km2deg(bin_radius): Amp_bin = np.append(Amp_bin, RFdepth[0, k]['moveout_correct'][2*Stack_range[j], l]) Event_count = Event_count + 1 if Event_count > 1: straptimes = int(Event_count*2) ci = boot.ci(Amp_bin, n_samples=straptimes, method='pi') mu = np.average(Amp_bin) else: mu = 0 ci = np.zeros(2) # fid.write('%-8.3f %-8.3f %-6.3f %-6.3f %-8.5f %-8.5f %-8.5f %d\n' % (Profile_lat[i], Profile_lon[i], Profile_range[i], Stack_range[j], mu, ci[0], ci[1], Event_count)) mu_arr[j][0] = mu ci_arr[j] = ci Event_count_arr[j][0] = Event_count mu_arr = sm.nonparametric.lowess(mu_arr[:, 0], Stack_range, frac=smooth_para)[:, 1] ci_arr[:, 0] = sm.nonparametric.lowess(ci_arr[:, 0], Stack_range, frac=smooth_para)[:, 1] ci_arr[:, 1] = sm.nonparametric.lowess(ci_arr[:, 1], Stack_range, frac=smooth_para)[:, 1] Stack_data[i][0] = Profile_lat[i] Stack_data[i][1] = Profile_lon[i] Stack_data[i][2] = Profile_range[i] Stack_data[i][3] = Stack_range