コード例 #1
0
    def apply_decluster(self):
        """
        apply window method to the whole catalog and write mainshocks on file
        """
        # get instances of classes we'll need
        catalog = Catalog()
        window_var = WindowVar()
        
        # from the catalog we want, get earthquakes array on memory
        earthquake_array = catalog.get_earthquake_array('../catalogs/new_jma.txt')

        # decluster array, separating mainshocks and aftershocks
        declustered_array = window_var.decluster(earthquake_array)

        # save declustered array using pickle
        file_aux1 = open('data_persistence/declustered_array_window_var', 'wb')
        pickle.dump(declustered_array, file_aux1)
        
        # open declustered array using another name 
        file_aux2 = open('data_persistence/declustered_array_window_var', 'rb')
        new_declustered_array = pickle.load(file_aux2)

        # save declustered array
        # record the mainshocks on a catalog
        catalog.record_mainshocks(declustered_array, file_write='../results/window_var_method/mainshocks.txt', file_read='../catalogs/jma.txt')
コード例 #2
0
ファイル: kmeans_simulation.py プロジェクト: gabriel951/pibic
    def apply_decluster(self):
        """
        apply window method to the whole catalog and write mainshocks on file
        """
        # get instances of classes we'll need
        catalog = Catalog()
        kmeans = KMeans() 

        # from the catalog we want, get earthquakes array on memory
        earthquake_array = catalog.get_earthquake_array('../catalogs/new_jma.txt')

        # decluster array, separating mainshocks and aftershocks
        declustered_array = kmeans.do_kmeans(earthquake_array)
        
        # record the mainshocks on a catalog
        catalog.record_mainshocks(declustered_array, file_write='../results/mainshocks.txt', file_read='../catalogs/jma.txt')
コード例 #3
0
ファイル: kmeans_simulation.py プロジェクト: gabriel951/pibic
    def apply_decluster_smaller(self):
        """
        apply window method to a smaller catalog and write mainshocks on file
        """
        # get instances of classes we'll need
        catalog = Catalog()
        kmeans = KMeans() 

        # obtain a smaller catalog, so we can run this function faster
        catalog.get_smaller_catalog(300)

        # from the catalog we want, get earthquakes array on memory
        earthquake_array = catalog.get_earthquake_array()
        
        # decluster array, separating mainshocks and aftershocks
        declustered_array = kmeans.do_kmeans(earthquake_array, 25)
        
        # record the mainshocks on a catalog
        catalog.record_mainshocks(declustered_array, file_write='../results/mainshocks.txt', file_read='../catalogs/reduced_jma.txt')
コード例 #4
0
    def study_chi_square(self, mag_thresh, region, time_spacing):
        """
        receives a magnitude threshold, a region and a interval of time
        perform a poisson test on the clusters that had quakes with magnitude above the threshold
        prints the results and returns nothing
        """
        CLUSTER_NUM = 1

        # auxiliar class
        stat = Statistic()
        cat = Catalog()
        slc = Single_Link()

        print('\nApplying chi-squared for magnitude ' + str(mag_thresh) + ' and region ' + str(region) + \
                ' and time interval of ' + str(time_spacing) + ' seconds')
            
        # get the name of the declustered and undeclustered catalog 
        decluster_catalog = '../results/single_link/temp_decluster_' + region + '.txt'
        original_catalog = '../results/single_link/temp_original_' + region + '.txt'
        aux_catalog = '../results/single_link/temp_aux_' + region + '.txt'
        
        # obtain catalog containing the quakes of the region - cat_region
        cat_orig = '../catalogs/new_jma.txt'
        cat_region = '../results/single_link/temp.txt'
        bounds = get_region_bounds(region)
        cat.select_geographically(bounds, cat_orig, cat_region) 

        # generates catalog containing only the mainshocks of clusters that had one quake (at least) 
        # with a shock greater than the magnitude threshold
        # open quake declustered array 
        path = '../results/single_link/declustered_array_' + region
        quakes = pickle.load(open(path, 'rb'))

        # mark every quake initially as an aftershock
        for quake in quakes: 
            quake.is_aftershock = True

        # iterate through all quakes 
        count = 0
        for quake in quakes:

            # if the current quake has magnitude bigger than or equal to the threshold
            if quake.mag >= mag_thresh: 

                # mark as mainshock the centroid it belongs to 
                quakes[quake.centroid_index].is_aftershock = False
                count += 1
        #print(count)
        # from the quake and catalog to read from, obtain declustered catalog 
        cat.record_mainshocks(quakes, aux_catalog, cat_region)
        cat.get_mainshocks(decluster_catalog, aux_catalog, index = 5)
         
        # obtain original catalog for the region, only with quakes bigger than magnitude
        cat.get_mag_threshold(cat_region, original_catalog, mag_thresh) 

        # apply the chisquared test for the declustered catalog and for the original catalog 
        print("Applying chi-squared for declustered catalog")
        stat.do_chi_square(decluster_catalog, 0.05, time_spacing)

        print("Applying chi-squared for the original catalog")
        stat.do_chi_square(original_catalog, 0.05, time_spacing)
コード例 #5
0
ファイル: stats.py プロジェクト: gabriel951/pibic
    def study_chisquare(self, folder, array_path, days, alpha, mag_threshold=None):
        """
        receives a folder to look for the quakes, the path where the earthquake array is located,
        the number of days, a significance level and optionally a magnitude threshold

        performs a chisquare test for the 4 regions of japan and all the japan
        by taking the observed frequencies in that number of days
        """
        # auxiliar classes needed
        catalog = Catalog()
        stat = Statistic()

        # calculate the number of seconds to be done on the interval
        time_interval = days * 24.0 * 360.0

        # generate catalog in a good format to work with 
        quakes = pickle.load(open(array_path, 'rb'))
        catalog.record_mainshocks(quakes, folder + 'quakes.txt', '../catalogs/new_jma.txt')
        
        # get the core catalog name, and obtain it 
        if mag_threshold == None:
            CATALOG_EXTENSION = 'quakes.txt'
        else:
            CATALOG_EXTENSION = 'quakes_' + str(mag_threshold) + '.txt'
            catalog.get_mag_threshold(folder + 'quakes.txt', folder + CATALOG_EXTENSION ,mag_threshold)

        # do chi square test for all japan, with aftershocks
        print("Doing chi-square test for all japan, including aftershocks on analysis:")
        stat.do_chi_square(folder + CATALOG_EXTENSION, 0.05, time_interval)
        # do chi square test for all japan, without aftershocks
        print("\nDoing chi-square test for all japan, excluding aftershocks on analysis")
        catalog.get_mainshocks(folder + 'japan_mainshocks.txt', folder + CATALOG_EXTENSION, 5)
        stat.do_chi_square(folder + 'japan_mainshocks.txt', 0.05, time_interval)
       
        # get bounds for kanto
        bounds = catalog.get_kanto_bounds()
        # construct a catalog for quakes that happened in kanto
        catalog.select_geographically(bounds, folder + CATALOG_EXTENSION, 
                                        folder + 'quakes_kanto.txt')
        # do chi_squared test for kanto, with aftershocks
        print("\nDoing chi-square test for kanto, including aftershocks on analysis:")
        stat.do_chi_square(folder + 'quakes_kanto.txt', 0.05, time_interval)
        # do chi_squared test for kanto, without aftershocks
        print("\nDoing chi-square test for kanto, excluding aftershocks on analysis")
        catalog.get_mainshocks(folder + 'mainshocks_kanto.txt', folder + 'quakes_kanto.txt', 5)
        stat.do_chi_square(folder + 'mainshocks_kanto.txt', 0.05, time_interval)


        # get bounds for kansai
        bounds = catalog.get_kansai_bounds()
        # construct a catalog for quakes that happened in kansai
        catalog.select_geographically(bounds, folder + CATALOG_EXTENSION, 
                                        folder + 'quakes_kansai.txt')
        # do chi_squared test for kansai, with aftershocks
        print("\nDoing chi-square test for kansai, including aftershocks on analysis:")
        stat.do_chi_square(folder + 'quakes_kansai.txt', 0.05, time_interval)
        # do chi_squared test for kansai, without aftershocks
        print("\nDoing chi-square test for kansai, excluding aftershocks on analysis")
        catalog.get_mainshocks(folder + 'mainshocks_kansai.txt', folder + 'quakes_kansai.txt', 5)
        stat.do_chi_square(folder + 'mainshocks_kansai.txt', 0.05, time_interval)

        # get bounds for tohoku
        bounds = catalog.get_tohoku_bounds()
        # construct a catalog for quakes that happened in tohoku
        catalog.select_geographically(bounds, folder + CATALOG_EXTENSION, 
                                        folder + 'quakes_tohoku.txt')
        # do chi_squared test for tohoku, with aftershocks
        print("\nDoing chi-square test for tohoku, including aftershocks on analysis:")
        stat.do_chi_square(folder + 'quakes_tohoku.txt', 0.05, time_interval)
        # do chi_squared test for tohoku, without aftershocks
        print("\nDoing chi-square test for tohoku, excluding aftershocks on analysis")
        catalog.get_mainshocks(folder + 'mainshocks_tohoku.txt', folder + 'quakes_tohoku.txt', 5)
        stat.do_chi_square(folder + 'mainshocks_tohoku.txt', 0.05, time_interval)

        # get bounds for east_japan
        bounds = catalog.get_east_japan_bounds()
        # construct a catalog for quakes that happened in east_japan
        catalog.select_geographically(bounds, folder + CATALOG_EXTENSION, 
                                        folder + 'quakes_east_japan.txt')
        # do chi_squared test for east_japan, with aftershocks
        print("\nDoing chi-square test for east_japan, including aftershocks on analysis:")
        stat.do_chi_square(folder + 'quakes_east_japan.txt', 0.05, time_interval)
        # do chi_squared test for east_japan, without aftershocks
        print("\nDoing chi-square test for east_japan, excluding aftershocks on analysis")
        catalog.get_mainshocks(folder + 'mainshocks_east_japan.txt', folder + 'quakes_east_japan.txt', 5)
        stat.do_chi_square(folder + 'mainshocks_east_japan.txt', 0.05, time_interval)