Exemple #1
0
def decluster_GK74(catalogue):
    from hmtk.seismicity.declusterer.dec_gardner_knopoff import GardnerKnopoffType1
    from hmtk.seismicity.declusterer.distance_time_windows import GardnerKnopoffWindow

    decluster_config = {
        'time_distance_window': GardnerKnopoffWindow(),
        'fs_time_prop': 1.0
    }

    #####################################################
    # decluster here
    #####################################################

    print 'Running GK declustering...'
    decluster_method = GardnerKnopoffType1()

    #---------------------------------------------
    # declustering
    cluster_index_gk, cluster_flags_gk = decluster_method.decluster(
        catalogue, decluster_config)
    #---------------------------------------------

    # adding to the catalog
    # The cluster flag (main shock or after/foreshock) and cluster index to the catalogue keys
    catalogue.data['cluster_index_gk'] = cluster_index_gk
    catalogue.data['cluster_flags_gk'] = cluster_flags_gk

    #####################################################
    # purge remove non-poissonian events
    #####################################################

    # create a copy from the catalogue object to preserve it
    catalogue_gk = deepcopy(catalogue)

    catalogue_gk.purge_catalogue(
        cluster_flags_gk == 0)  # cluster_flags == 0: mainshocks

    print 'Gardner-Knopoff\tbefore: ', catalogue.get_number_events(
    ), " after: ", catalogue_gk.get_number_events()

    #####################################################
    # write declustered catalogue
    #####################################################

    # setup the writer
    declustered_catalog_file = hmtk_csv.split('.')[0] + '_declustered_GK74.csv'

    # if it exists, delete previous file
    try:
        remove(declustered_catalog_file)
    except:
        print declustered_catalog_file, 'does not exist'

    # set-up writer
    writer = CsvCatalogueWriter(declustered_catalog_file)

    # write
    writer.write_file(catalogue_gk)
    #writer.write_file(catalogue_af)
    print 'Declustered catalogue: ok\n'
class CsvCatalogueParserTestCase(unittest.TestCase):
    """ Unit tests for the csv Catalogue Parser Class"""
    BASE_DATA_PATH = os.path.join(os.path.dirname(__file__), 'data')

    def setUp(self):
        self.gardner_knopoff_window = GardnerKnopoffWindow()
        self.gruenthal_window = GruenthalWindow()
        self.uhrhammer_window = UhrhammerWindow()

    def test_gardner_knopoff_window(self):
        """
        Test the Gardner and Knopoff Distance-Time window
        """
        mag = np.array([5.0, 6.6])
        sw_space, sw_time = self.gardner_knopoff_window.calc(mag)
        self.assertAlmostEqual(sw_space[0], 39.99447, places=5)
        self.assertAlmostEqual(sw_space[1], 63.10736, places=5)
        self.assertAlmostEqual(sw_time[0], 143.71430 / 364.75, places=5)
        self.assertAlmostEqual(sw_time[1], 891.45618 / 364.75, places=5)

    def test_gruenthal_window(self):
        """
        Test the Gruenthal Distance-Time window
        """
        mag = np.array([5.0, 6.6])
        sw_space, sw_time = self.gruenthal_window.calc(mag)
        #self.assertAlmostEqual(sw_space[0], 39.99447, places=5)
        #self.assertAlmostEqual(sw_time[0], 143.71430/364.75, places=5)
        #self.assertAlmostEqual(sw_space[1], 63.10736, places=5)
        #self.assertAlmostEqual(sw_time[1], 891.45618/364.75, places=5)

    def test_uhrhammer_window(self):
        mag = np.array([5.0, 6.6])
        sw_space, sw_time = self.uhrhammer_window.calc(mag)
class CsvCatalogueParserTestCase(unittest.TestCase):
    """ Unit tests for the csv Catalogue Parser Class"""

    BASE_DATA_PATH = os.path.join(os.path.dirname(__file__), "data")

    def setUp(self):
        self.gardner_knopoff_window = GardnerKnopoffWindow()
        self.gruenthal_window = GruenthalWindow()
        self.uhrhammer_window = UhrhammerWindow()

    def test_gardner_knopoff_window(self):
        """
        Test the Gardner and Knopoff Distance-Time window
        """
        mag = np.array([5.0, 6.6])
        sw_space, sw_time = self.gardner_knopoff_window.calc(mag)
        self.assertAlmostEqual(sw_space[0], 39.99447, places=5)
        self.assertAlmostEqual(sw_space[1], 63.10736, places=5)
        self.assertAlmostEqual(sw_time[0], 143.71430 / 364.75, places=5)
        self.assertAlmostEqual(sw_time[1], 891.45618 / 364.75, places=5)

    def test_gruenthal_window(self):
        """
        Test the Gruenthal Distance-Time window
        """
        mag = np.array([5.0, 6.6])
        sw_space, sw_time = self.gruenthal_window.calc(mag)
        # self.assertAlmostEqual(sw_space[0], 39.99447, places=5)
        # self.assertAlmostEqual(sw_time[0], 143.71430/364.75, places=5)
        # self.assertAlmostEqual(sw_space[1], 63.10736, places=5)
        # self.assertAlmostEqual(sw_time[1], 891.45618/364.75, places=5)

    def test_uhrhammer_window(self):
        mag = np.array([5.0, 6.6])
        sw_space, sw_time = self.uhrhammer_window.calc(mag)
 def test_dec_gardner_knopoff(self):
     """
     Testing the Gardner and Knopoff algorithm 
     """
     config = {
         'time_distance_window': GardnerKnopoffWindow(),
         'fs_time_prop': 1.0
     }
     # Instantiate the declusterer and process the sample catalogue
     dec = GardnerKnopoffType1()
     vcl, flagvector = dec.decluster(self.cat, config)
     print 'vcl:', vcl
     print 'flagvector:', flagvector, self.cat.data['flag']
     self.assertTrue(np.allclose(flagvector, self.cat.data['flag']))
Exemple #5
0
 def test_dec_afteran(self):
     """
     Testing the Afteran algorithm
     """
     config = {
         'time_distance_window': GardnerKnopoffWindow(),
         'time_window': 60.}
     # Instantiate the declusterer and process the sample catalogue
     # self.dec = Afteran()
     print(dir(self.dec))
     vcl, flagvector = self.dec.decluster(self.cat, config)
     print('vcl:', vcl)
     print('flagvector:', flagvector, self.cat.data['flag'])
     self.assertTrue(np.allclose(flagvector, self.cat.data['flag']))
Exemple #6
0
    writer = CsvCatalogueWriter(output_file_name)
    # Write the catalogue to file
    writer.write_file(catalogue)
    #exit()

    print 'File %s written' % output_file_name
    f = open(input_catalogue_file + ".pkl", 'wb')
    pickle.dump(catalogue, f)
    f.close()

# Set up the declustering algorithm
# Step 1 - set-up the tool
gardner_knopoff = GardnerKnopoffType1()

declust_config = {
    'time_distance_window': GardnerKnopoffWindow(),
    'fs_time_prop': 1.0
}
print declust_config

print 'Running declustering ...'
vcl, flag_vector = gardner_knopoff.decluster(catalogue, declust_config)
print 'done!'
print '%s clusters found' % np.max(vcl)
print '%s Non-poissionian events identified' % np.sum(flag_vector != 0)

# In[ ]:

# Setup the algorithm
afteran = Afteran()
declust_config = {
 def setUp(self):
     self.gardner_knopoff_window = GardnerKnopoffWindow()
     self.gruenthal_window = GruenthalWindow()
     self.uhrhammer_window = UhrhammerWindow()
 def setUp(self):
     self.gardner_knopoff_window = GardnerKnopoffWindow()
     self.gruenthal_window = GruenthalWindow()
     self.uhrhammer_window = UhrhammerWindow()