def setUp(self): filename = os.path.join(BASE_DATA_PATH, 'completeness_test_cat.csv') parser0 = CsvCatalogueParser(filename) self.catalogue = parser0.read_file() self.config = {'algorithm': None, 'number_bootstraps': None} self.model = CumulativeMoment()
def setUp(self): filename = os.path.join(BASE_DATA_PATH,'completeness_test_cat.csv') parser0 = CsvCatalogueParser(filename) self.catalogue = parser0.read_file() self.config = {'algorithm': None, 'number_bootstraps': None} self.model = CumulativeMoment()
def setUp(self): test_data = np.genfromtxt(TEST_CAT_1, delimiter=',', skip_header=1) parser0 = CsvCatalogueParser(TEST_CAT_1) self.catalogue = parser0.read_file() self.config = {'algorithm': None, 'number_bootstraps': None} self.model = CumulativeMoment()
'input_mmin': 4.5, 'input_mmax': None, 'input_mmax_uncertainty': 0.5} mmax_ksb = KijkoSellevolBayes() mmax, mmax_sigma = mmax_ksb.get_mmax(catalogue, mmax_config) print 'Mmax = %8.3f +/- %8.3f' %(mmax, mmax_sigma) # In[ ]: mmax_config = {'number_earthquakes': 100, # Selects the N largest earthquakes in the catalogue for analysis 'input_mmax': None, 'input_mmax_uncertainty': 0.5} mmax_knpg = KijkoNonParametricGaussian() mmax, mmax_sigma = mmax_knpg.get_mmax(catalogue, mmax_config) print 'Mmax = %8.3f +/- %8.3f' %(mmax, mmax_sigma) # In[ ]: mmax_config = {'number_bootstraps': 1000} # Number of samples for the uncertainty analyis mmax_cum_mo = CumulativeMoment() mmax, mmax_sigma = mmax_cum_mo.get_mmax(catalogue, mmax_config) print 'Mmax = %8.3f +/- %8.3f' %(mmax, mmax_sigma)
class TestCumulativeMoment(unittest.TestCase): ''' Test suite for the :class: hmtk.seismicity.max_magnitude.cumulative_moment_release module ''' def setUp(self): test_data = np.genfromtxt(TEST_CAT_1, delimiter=',', skip_header=1) parser0 = CsvCatalogueParser(TEST_CAT_1) self.catalogue = parser0.read_file() self.config = {'algorithm': None, 'number_bootstraps': None} self.model = CumulativeMoment() def test_check_config(self): ''' Tests the configuration checker ''' # Test 1: No bootstraps specified self.config['number_bootstraps'] = None fixed_config = self.model.check_config(self.config) self.assertEqual(1, fixed_config['number_bootstraps']) # Test 2: Invalid number of bootstraps specified self.config['number_bootstraps'] = 0 fixed_config = self.model.check_config(self.config) self.assertEqual(1, fixed_config['number_bootstraps']) # Test 3: Valid number of bootstraps self.config['number_bootstraps'] = 1000 fixed_config = self.model.check_config(self.config) self.assertEqual(1000, fixed_config['number_bootstraps']) def test_cumulative_moment(self): ''' Tests the cumulative moment function ''' # Test 1: Ordinary behaviour using the completeness_test_cat.csv self.assertAlmostEqual(7.4847335589, self.model.cumulative_moment( self.catalogue.data['year'], self.catalogue.data['magnitude'])) # Test 2: If catalogue is less than or equal to 1 year duration id0 = self.catalogue.data['year'].astype(int) == 1990 self.assertTrue(np.isinf(self.model.cumulative_moment( self.catalogue.data['year'][id0], self.catalogue.data['magnitude'][id0]))) def test_get_mmax_cumulative_moment(self): ''' Tests the cumulative moment function sampled with uncertainty ''' # Test 1: Case when no sigma is found on magnitude self.catalogue.data['backup'] = np.copy( self.catalogue.data['sigmaMagnitude']) self.catalogue.data['sigmaMagnitude'] = None mmax, sigma_mmax = self.model.get_mmax(self.catalogue, self.config) self.assertAlmostEqual(7.4847335589, mmax) self.assertAlmostEqual(0.0, sigma_mmax) # Test 2: Case when one or no bootstraps are specified self.catalogue.data['sigmaMagnitude'] = self.catalogue.data['backup'] self.config['number_bootstraps'] = 0 mmax, sigma_mmax = self.model.get_mmax(self.catalogue, self.config) self.assertAlmostEqual(7.4847335589, mmax) self.assertAlmostEqual(0.0, sigma_mmax) # Test 3: Ordinary test case with uncertainty - seeded random generator self.config['number_bootstraps'] = 1000 mmax, sigma_mmax = self.model.get_mmax(self.catalogue, self.config, seed=123456) self.assertAlmostEqual(7.518906927, mmax) self.assertAlmostEqual(0.058204597, sigma_mmax)
class TestCumulativeMoment(unittest.TestCase): ''' Test suite for the :class: hmtk.seismicity.max_magnitude.cumulative_moment_release module ''' def setUp(self): filename = os.path.join(BASE_DATA_PATH, 'completeness_test_cat.csv') parser0 = CsvCatalogueParser(filename) self.catalogue = parser0.read_file() self.config = {'algorithm': None, 'number_bootstraps': None} self.model = CumulativeMoment() def test_check_config(self): # Tests the configuration checker # Test 1: No bootstraps specified self.config['number_bootstraps'] = None fixed_config = self.model.check_config(self.config) self.assertEqual(1, fixed_config['number_bootstraps']) # Test 2: Invalid number of bootstraps specified self.config['number_bootstraps'] = 0 fixed_config = self.model.check_config(self.config) self.assertEqual(1, fixed_config['number_bootstraps']) # Test 3: Valid number of bootstraps self.config['number_bootstraps'] = 1000 fixed_config = self.model.check_config(self.config) self.assertEqual(1000, fixed_config['number_bootstraps']) def test_cumulative_moment(self): # Tests the cumulative moment function # Test 1: Ordinary behaviour using the completeness_test_cat.csv self.assertAlmostEqual( 7.5, self.model.cumulative_moment(self.catalogue.data['year'], self.catalogue.data['magnitude']), 1) # Test 2: If catalogue is less than or equal to 1 year duration id0 = self.catalogue.data['year'].astype(int) == 1990 self.assertTrue( np.isinf( self.model.cumulative_moment( self.catalogue.data['year'][id0], self.catalogue.data['magnitude'][id0]))) def test_get_mmax_cumulative_moment(self): # Tests the cumulative moment function sampled with uncertainty # Test 1: Case when no sigma is found on magnitude self.catalogue.data['backup'] = np.copy( self.catalogue.data['sigmaMagnitude']) self.catalogue.data['sigmaMagnitude'] = None mmax, sigma_mmax = self.model.get_mmax(self.catalogue, self.config) self.assertAlmostEqual(7.4847335589, mmax, 1) self.assertAlmostEqual(0.0, sigma_mmax) # Test 2: Case when one or no bootstraps are specified self.catalogue.data['sigmaMagnitude'] = self.catalogue.data['backup'] self.config['number_bootstraps'] = 0 mmax, sigma_mmax = self.model.get_mmax(self.catalogue, self.config) self.assertAlmostEqual(7.4847335589, mmax, 1) self.assertAlmostEqual(0.0, sigma_mmax) # Test 3: Ordinary test case with uncertainty - seeded random generator self.config['number_bootstraps'] = 1000 # Can fix the seed (used for testing!) np.random.seed(123456) mmax, sigma_mmax = self.model.get_mmax(self.catalogue, self.config) self.assertAlmostEqual(7.518906927, mmax) self.assertAlmostEqual(0.058204597, sigma_mmax)
} mmax_ksb = KijkoSellevolBayes() mmax, mmax_sigma = mmax_ksb.get_mmax(catalogue, mmax_config) print 'Mmax = %8.3f +/- %8.3f' % (mmax, mmax_sigma) # In[ ]: mmax_config = { 'number_earthquakes': 100, # Selects the N largest earthquakes in the catalogue for analysis 'input_mmax': None, 'input_mmax_uncertainty': 0.5 } mmax_knpg = KijkoNonParametricGaussian() mmax, mmax_sigma = mmax_knpg.get_mmax(catalogue, mmax_config) print 'Mmax = %8.3f +/- %8.3f' % (mmax, mmax_sigma) # In[ ]: mmax_config = { 'number_bootstraps': 1000 } # Number of samples for the uncertainty analyis mmax_cum_mo = CumulativeMoment() mmax, mmax_sigma = mmax_cum_mo.get_mmax(catalogue, mmax_config) print 'Mmax = %8.3f +/- %8.3f' % (mmax, mmax_sigma)