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() window_var = WindowVar() # 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 = 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) # recover declustered array using pickle # record the mainshocks on a catalog catalog.record_mainshocks(new_declustered_array, file_write='../results/window_var_method/mainshocks.txt', file_read='../catalogs/reduced_jma.txt')
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')
def compare_window_kmeans(num_entries): """ receives a number of entries the function applies to a catalog with that number of entries the window method and the kmeans to decluster the catalog the function returns a comparation, showing how much there is of a difference between the two Complexity: O(n^2) """ # obtain a smaller catalog catalog = Catalog() catalog.get_smaller_catalog(num_entries) # get earthquake array of that catalog quakes = catalog.get_earthquake_array() # get declustered array of that catalog, according to the window method window = Window() window_quakes = window.decluster(quakes) # get the number of mainshocks of that catalog, according to the kmeans clustering method num_mainshocks = 0 for i in range(len(window_quakes)): if window_quakes[i].is_aftershock == False: num_mainshocks += 1 print(num_mainshocks) # apply declustering using the kmeans method to the catalog kmeans = KMeans() kmeans_quakes = kmeans.do_kmeans(quakes, num_mainshocks) # show what are the differences between both methods for i in range(len(quakes)): if window_quakes[i].is_aftershock != kmeans_quakes[i].is_aftershock: print("found a difference!")
# obtain declustered catalog for Tohoku bounds = catalog.get_tohoku_bounds() catalog.select_geographically(bounds, '../results/mainshocks.txt', '../results/mainshocks_tohoku.txt') #### TESTS AND SIMULATIONS - just comment them out #### # simulation to see how many earthquakes there are in a given range of magnitudes - TESTED #sim = CatalogSimulation() #sim.simple_report() # see if it's possible to represent all Earthquakes on the catalog in memory - TESTED #catalog = Catalog() #catalog.get_earthquake_array() # obtain a smaller catalog, will be good for preliminar tests - TESTED catalog = Catalog() catalog.get_smaller_catalog(40) # see if we can obtain a catalog which selects the regions geographically - TESTED #catalog = Catalog() #bounds = [120.0, 130.0, 30.0, 40.0] #catalog.select_geographically(bounds, '../results/mainshocks.txt', '../results/stricted_mainshocks.txt') # get declustered catalogs for Yuri - TESTED #catalog = Catalog() #sim = CatalogSimulation() #sim.help_yuri(catalog) # obtain a catalog of only mainshocks - NOT TESTED #catalog = Catalog() #catalog.get_mainshocks()