Browse Source

fixed stacking functions for S and P, name for setup.py

pull/1/head
Gesa 2 years ago
parent
commit
4f3681f4b4
  1. 1
      setup.py
  2. 12
      src/cc.py
  3. 6
      src/clustering.py
  4. 59
      src/clusty.py

1
setup.py

@ -7,6 +7,7 @@ version = '0.1'
setup(
name='clusty',
version=version,
author='clusty collective',
install_requires=[],

12
src/cc.py

@ -304,10 +304,10 @@ def max_cc(coef_array):
'''
n_ph = num.shape(coef_array)[0]
n_ev = num.shape(coef_array)[2]
array_max_cc = num.empty((n_ph,n_ev))
array_max_cc = num.empty((n_ph, n_ev, n_ev))
for i_ph in range(n_ph):
array_max_cc[i_ph, :] = num.nanmax(coef_array,
axis=1)
array_max_cc[i_ph,:,:] = num.nanmax(coef_array[i_ph],
axis=0)
return array_max_cc
@ -329,7 +329,6 @@ def median_ccs(coef_array):
# #fancy numpy
# array_median_ccs2 = num.median(coef_array, axis=2)
return array_median_ccs
@ -377,7 +376,7 @@ def product_combPS(coef_array):
cc_nonan_0 = coef_array[0, :,i,j][coef_array[0,:,i,j] != 0]
cc_nonan_1 = coef_array[1, :,i,j][coef_array[1,:,i,j] != 0]
try:
array_prod_ccs[0,i,j] = (num.prod(cc_nonan_0)*num.prod(cc_nonan_1))**(1/(2*len(cc_nonan)))
array_prod_ccs[0,i,j] = (num.prod(cc_nonan_0)*num.prod(cc_nonan_1))**(1/(len(cc_nonan_0)+len(cc_nonan_1)))
except ZeroDivisionError:
array_prod_ccs[0,i,j] = 0
continue
@ -476,7 +475,8 @@ def stack_ccs_over_stations(coef_array, weights_array, az_stats_weights,
'''
method = netsim_settings.method_similarity_computation
print(method)
#print(coef_array[0])
#print(coef_array[1])
if netsim_settings.apply_cc_station_thresh:
apply_cc_station_threshs(coef_array, netsim_settings, n_ph)

6
src/clustering.py

@ -64,7 +64,7 @@ def write_pretty_output(catalog, clustering, method):
cl.dump(filename='clustering_%s.yaml' % method)
def cluster_plots(network_similarity, clustering_list, catalog):
def cluster_plots(network_similarity, clustering_list, catalog, method):
'''
plot results
(a) network similarity matrix sorted by clusters
@ -92,7 +92,7 @@ def cluster_plots(network_similarity, clustering_list, catalog):
events_sorted = [s[2] for s in sorted_tuples]
title = 'Network Similarity, events sorted by cluster'
fig_name = 'network_similarity_cluster.png'
fig_name = 'net_sim_cl_%s.png' % method
small_imshow_plot(network_similarity_cluster, events_sorted, title,
cbarlabel=None, fig_name=fig_name)
@ -126,5 +126,5 @@ def cluster_plots(network_similarity, clustering_list, catalog):
cbar.ax.set_xticklabels(bounds, rotation=60)
plt.tight_layout()
fig.savefig('cluster.png')
fig.savefig('cluster_%s.png' % method)
plt.close()

59
src/clusty.py

@ -126,28 +126,33 @@ def main():
arrivals_array.fill(num.nan)
print('Computing arrival times.')
if cc_cnf.use_cake:
st_lats = num.asarray([st.lat for st in station_list])
st_lons = num.asarray([st.lon for st in station_list])
if cc_cnf.vmodel == '':
vmodel = cake.load_model(
crust2_profile=crust2x2.get_profile(
cat[0].lat, cat[0].lon))
vmodels = [cake.load_model(crust2_profile=crust2x2.get_profile(st.lat, st.lon))
for st in station_list]
else:
vmodel = cake.load_model(cc_cnf.vmodel)
for i_ph, phase_name in enumerate(cc_cnf.phase):
for i_ev, ev in enumerate(cat):
dists = orthodrome.distance_accurate50m_numpy(
ev.lat, ev.lon, st_lats, st_lons)
st_lats = num.asarray([st.lat for st in station_list])
st_lons = num.asarray([st.lon for st in station_list])
for i_st, st in enumerate(station_list):
dist = dists[i_st]
for i_ev, ev in enumerate(cat):
dists = orthodrome.distance_accurate50m_numpy(
ev.lat, ev.lon, st_lats, st_lons)
if cc_cnf.vmodel == '':
vmodel = vmodels[i_st]
else:
vmodel = vmodel
for i_st, st in enumerate(station_list):
dist = dists[i_st]
for i_ph, phase_name in enumerate(cc_cnf.phase):
if phase_name == 'P' or phase_name == 'p':
phase_names = ['p', 'P']
elif phase_name == 'S' or phase_name == 's':
phase_names = ['s', 'S']
arrivals = vmodel.arrivals(distances=[dist*cake.m2d],
phases=phase_names,
zstart=ev.depth)
@ -207,6 +212,7 @@ def main():
az_stats_weights = None
# print(coef_array.shape)
# print(weights_array.shape)
print('Similarity matrix ready.')
n_ph = len(cc_cnf.phase)
if not ns_cnf.use_precalc_net_sim:
@ -227,25 +233,30 @@ def main():
fig_name=ns_cnf.method_similarity_computation+str(i_ph))
# make optional combining of P and S results or more methods to combine them
# in computation of network similarity!!!
### clusterinng ###
'''
# adjust for one more dimension of network_similarity array
if cl_cnf.method == 'dbscan':
clustering = cl.cluster_dbscan(cl_cnf.dbscan_eps,
cl_cnf.dbscan_min_samples,
network_similarity)
method_string = '%s_%s' % (ns_cnf.method_similarity_computation,
cl_cnf.method)
#cl.write_pretty_output(cat, clustering, method_string)
cl.cluster_plots(network_similarity, clustering, cat)
for i_ph in range(n_ph):
if cl_cnf.method == 'dbscan':
clustering = cl.cluster_dbscan(cl_cnf.dbscan_eps,
cl_cnf.dbscan_min_samples,
network_similarity[i_ph])
method_string = '%s_%s_%s' % (ns_cnf.method_similarity_computation,
cl_cnf.method, str(i_ph))
cl.write_pretty_output(cat, clustering, method_string)
cl.cluster_plots(network_similarity[i_ph], clustering, cat, method_string)
#for ev, c in zip(cat, clustering):
# print(util.time_to_str(ev.time)[0:11], ev.magnitude, c)
'''
print('Clusty run completed.')
if __name__ == '__main__':
main()

Loading…
Cancel
Save