當前位置: 首頁>>代碼示例>>Python>>正文


Python Catalog.get_quakes_link方法代碼示例

本文整理匯總了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
開發者ID:gabriel951,項目名稱:pibic,代碼行數:71,代碼來源:single_link.py


注:本文中的catalog.Catalog.get_quakes_link方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。