def nr_dt(t_shift_array, max_ts=180., width=1., num_bands=1, enum=0, leg='default', line_plot=False): """ histogram plot for all measured traveltime anomalies """ bins = np.arange(-int(max_ts), int(max_ts)+width, width) for i in range(len(bins)): bins[i] = round(bins[i], 6) for i in range(len(t_shift_array)): t_shift_array[i] = uf.round_to(t_shift_array[i], width) digit = np.digitize(t_shift_array, bins) digit_list = digit.tolist() for i in range(len(digit_list)): digit_list[i] -= 1 digit_count = {} for i in range(0, len(bins)): digit_count[str(i)] = digit_list.count(i) dic_color = {'0': 'blue', '1': 'deepskyblue', '2': 'green', '3': 'darkorange', '4': 'brown', '5': 'olive', '6': 'tan', '7': 'darkviolet'} x_line = [] y_line = [] for i in range(0, len(bins)): x_line.append(bins[i]) y_line.append(digit_count[str(i)]) # Calculating the percentage: # Method: First we should run the code for xcorr_limit = -1000 # This can assure us that we consider all the source receiver pairs # The next two lines should be uncomment first # Second: continue after two lines.... #y_l = open(os.path.join('statistics_all', 'yband' + str(enum)), 'w') #pickle.dump(y_line, y_l) # (cont) in this part, first we load the data for all source receiver pairs... # note that there is not difference between band01 to the last band! since we consider all # Now uncomment the next lines (up to plt.plot) # to load and calculate the percentage # IMPORTANT: the two lines up should be commented out! y_l = open(os.path.join('statistics_all', 'yband' + str(enum))) y_l_all = pickle.load(y_l) for i in range(len(y_l_all)-1, -1, -1): if y_l_all[i] < 1: del y_l_all[i] del y_line[i] del x_line[i] #plt.plot(x_line, np.array(y_line, dtype=float)/np.array(y_l_all, dtype=float)*100., lw=3.0, label=leg, # color=dic_color[str(enum)]) plt.plot(x_line, y_line, lw=3.0, label=leg, color=dic_color[str(enum)])
def nr_dt(t_shift_array, max_ts=30., width=0.1, num_bands=1, enum=0, leg='default', line_plot=False): """ histogram plot for all measured traveltime anomalies EXAMPLES: 1) For nr_cc: max_ts=2., width=0.1 * max_ts=2., width=0.01 2) For nr_dt: max_ts=30., width=0.1 max_ts=30., width=0.5 """ bins = np.arange(-int(max_ts), int(max_ts)+width, width) for i in range(len(bins)): bins[i] = round(bins[i], 6) for i in range(len(t_shift_array)): t_shift_array[i] = uf.round_to(t_shift_array[i], width) digit = np.digitize(t_shift_array, bins) digit_list = digit.tolist() for i in range(len(digit_list)): digit_list[i] -= 1 digit_count = {} for i in range(0, len(bins)): digit_count[str(i)] = digit_list.count(i) dic_color = {'0': 'blue', '1': 'deepskyblue', '2': 'green', '3': 'darkorange', '4': 'brown', '5': 'olive', '6': 'tan', '7': 'darkviolet'} x_line = [] y_line = [] for i in range(0, len(bins)): if not line_plot: if i == 0: plt.bar(left=bins[i]-width*(0.25*1.5-enum*1.5*0.5/num_bands), width=1.5*width/2./num_bands, height=digit_count[str(i)], color=dic_color[str(enum)], edgecolor=dic_color[str(enum)], label=leg) else: plt.bar(left=bins[i]-width*(0.25*1.5-enum*1.5*0.5/num_bands), width=1.5*width/2./num_bands, height=digit_count[str(i)], color=dic_color[str(enum)], edgecolor=dic_color[str(enum)]) else: x_line.append(bins[i]) y_line.append(digit_count[str(i)]) if line_plot: plt.plot(x_line[9:-10], y_line[9:-10], lw=3.0, label=leg, color=dic_color[str(enum)])
passed_staev = uf.filters(all_staev, [bands[i]], xcorr_limit=xcorr_limit) if not passed_staev[0]: continue magni = mag_finder(proc_ev_ls[j], ev_fi) mag_all = np.append(mag_all, magni) ### FIND EACH EVENT WITH SPECIFIED MAGNITUDE AND THE NUMBER OF WAVEFORNS ASSOCIATED ??????? passed_staev_epi = [] for k in range(len(passed_staev[0])): if min_epi <= passed_staev[0][k][6] < max_epi: passed_staev_epi.append(passed_staev[0][k]) nw_all = np.append(nw_all, len(passed_staev_epi)) for j in range(len(mag_all)): for k in mag_dic: if abs(uf.round_to(mag_all[j], 0.5) - float(k)) < 0.1: mag_dic[k][0] += nw_all[j] mag_dic[k][1] += 1 break mag_sta_list = [] for md in mag_dic: mag_sta_list.append([float(md), mag_dic[md][0], mag_dic[md][1]]) mag_sta_list.sort() import py2mat_mod py2mat_mod.py2mat(mag_sta_list, 'mag_sta_%s' % bands[i], 'mag_sta_%s' % bands[i]) plt.ion() plt.figure()