本文整理汇总了Python中catalog.Catalog.get_quakes_link方法的典型用法代码示例。如果您正苦于以下问题:Python Catalog.get_quakes_link方法的具体用法?Python Catalog.get_quakes_link怎么用?Python Catalog.get_quakes_link使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类catalog.Catalog
的用法示例。
在下文中一共展示了Catalog.get_quakes_link方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: apply_single_link
# 需要导入模块: from catalog import Catalog [as 别名]
# 或者: from catalog.Catalog import get_quakes_link [as 别名]
def apply_single_link(self, catalog_name, region, alternative_threshold):
"""
receives a catalog file name, the name of the region
to which we are applying single link clustering and an alternative threshold to use
in case the calculated threshold is less than the necessary
apply the single link declustering method,
records all intermediate clusterings. Saves the matrix distance and the
threshold in the results folder
returns the quake array, with all the clusters saved
Complexity: O(n^2 * log n)
"""
# report
print('\n\n## region: ' + str(region) + ' ##alternative threshold: ' + str(alternative_threshold))
# put all the quakes on a numpy array
cat = Catalog()
quakes = cat.get_quakes_link(catalog_name)
# current number of clusters
num_clusters = quakes.shape[0]
# get file name in which we'll save the matrix
file_name = '../results/single_link/matrix_and_threshold/' + region + '_matrix.h5'
# construct distance matrix
#input("I'm possibly starting to construct matrix of distance. check if the next line is commented/uncommented")
#self.construct_matrix(quakes, file_name)
print("finished constructing matrix of distances")
# get threshold value
threshold = self.get_threshold(quakes, region)
if threshold < alternative_threshold:
threshold = alternative_threshold
#save threshold value
threshold_path = '../results/single_link/matrix_and_threshold/' + region + '_threshold_' + str(round(threshold, 3))
file_pointer = open(threshold_path, 'w')
file_pointer.write(str(threshold))
file_pointer.close()
print("finished calculating threshold")
# iterate until we have only one cluster
while num_clusters != 1:
print('current number of clusters: ' + str(num_clusters))
# build the cluster distance array and link the clusters
num_new_clusters = self.build_link_clusters(quakes, num_clusters, region, alternative_threshold)
# if the number of new cluster is the same as the old one we had
if num_new_clusters == num_clusters:
# break out of the loop
break
else:
# update the number of clusters for the next iteration
num_clusters = num_new_clusters
print('\n\nanalysing cluster number and quakes number')
for quake in quakes:
if quake.cluster[LAST_ELEMENT] >= num_clusters:
num_clusters = quake.cluster[LAST_ELEMENT]
num_clusters += 1 # because the counting started at zero
print('number of clusters: ' + str(num_clusters))
print('number of quakes: ' + str(quakes.shape[0]))
return quakes