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')
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!")