def setUp(self): filename = os.path.join(BASE_DATA_PATH,'completeness_test_cat.csv') parser0 = CsvCatalogueParser(filename) self.catalogue = parser0.read_file() self.config = {'b-value': 1.0, 'sigma-b': 0.05, 'input_mmin': 5.0, 'input_mmax': None, 'input_mmax_uncertainty': None, 'tolerance': 0.001, 'maximum_iterations': 1000} self.model = KijkoSellevolBayes()
def setUp(self): parser0 = CsvCatalogueParser(TEST_CAT_1) self.catalogue = parser0.read_file() self.config = {'b-value': 1.0, 'sigma-b': 0.05, 'input_mmin': 5.0, 'input_mmax': None, 'input_mmax_uncertainty': None, 'tolerance': 0.001, 'maximum_iterations': 1000} self.model = KijkoSellevolBayes()
def setUp(self): filename = os.path.join(BASE_DATA_PATH,'completeness_test_cat.csv') parser0 = CsvCatalogueParser(filename) self.catalogue = parser0.read_file() self.config = {'b-value': 1.0, 'sigma-b': 0.05, 'input_mmin': 5.0, 'input_mmax': None, 'input_mmax_uncertainty': None, 'tolerance': 0.001, 'maximum_iterations': 1000} self.model = KijkoSellevolBayes()
mmax_ks = KijkoSellevolFixedb() mmax, mmax_sigma = mmax_ks.get_mmax(catalogue, mmax_config) print 'Mmax = %8.3f +/- %8.3f' %(mmax, mmax_sigma) # In[ ]: mmax_config = {'b-value': 1.0, 'sigma-b': 0.05, '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)
class TestKijkoSellevolBayes(unittest.TestCase): ''' Test the hmtk.seismicity.max_magnitude.KijkoSellevolBayes module ''' def setUp(self): parser0 = CsvCatalogueParser(TEST_CAT_1) self.catalogue = parser0.read_file() self.config = {'b-value': 1.0, 'sigma-b': 0.05, 'input_mmin': 5.0, 'input_mmax': None, 'input_mmax_uncertainty': None, 'tolerance': 0.001, 'maximum_iterations': 1000} self.model = KijkoSellevolBayes() def test_ksb_intfunc(self): ''' Tests the integral function of the Kijko-Sellevol-Bayes estimator of mmax ''' neq = 100. mval = 6.0 mmin = 5.0 # Good case b-value is 1.0, sigma-b is 0.05 pval, qval = self._get_pval_qval(1.0, 0.05) self.assertAlmostEqual( self.model._ksb_intfunc(mval, neq, mmin, pval, qval), 2.4676049E-5) # Bad case b-value is 0.0, sigma-b is 0,05 pval0, qval0 = self._get_pval_qval(0.0, 0.05) self.assertAlmostEqual( self.model._ksb_intfunc(mval, neq, mmin, pval0, qval0), 0.0) # Bad case neq = 0. self.assertAlmostEqual( self.model._ksb_intfunc(mval, 0., mmin, pval0, qval0), 1.0) # Bad case mval < mmin mmin = 6.0 mval = 5.0 self.assertAlmostEqual( np.log10(self.model._ksb_intfunc(mval, neq, mmin, pval, qval)), 95.7451687) def test_get_mmax(self): ''' Tests the function to calculate mmax using the Kijko-Sellevol-Bayes operator ''' # Good case - b = 1., sigma_b = 0.05, mmin = 5.0 mmax, mmax_sigma = self.model.get_mmax(self.catalogue, self.config) self.assertAlmostEqual(mmax, 7.6902450) self.assertAlmostEqual(mmax_sigma, 0.30698886) # Bad case 1 - input mmin < catalogue mmin self.config['input_mmin'] = 3.5 mmax, mmax_sigma = self.model.get_mmax(self.catalogue, self.config) self.assertAlmostEqual(mmax, 8.2371167) self.assertAlmostEqual(mmax_sigma, 0.84306841) self.config['input_mmin'] = 4.0 mmax_check, _ = self.model.get_mmax(self.catalogue, self.config) self.assertAlmostEqual(mmax, mmax_check) # Good case 1 - input mmax self.config['input_mmin'] = 5.0 self.config['input_mmax'] = 7.8 self.config['input_mmax_uncertainty'] = 0.2 mmax, mmax_sigma = self.model.get_mmax(self.catalogue, self.config) self.assertAlmostEqual(mmax, 8.9427386) self.assertAlmostEqual(mmax_sigma, 1.16010841) # Bad case 1 - negative b-value (should return nan) self.config = {'b-value': -0.5, 'sigma-b': 0.05, 'input_mmin': 5.0, 'input_mmax': None, 'input_mmax_uncertainty': None, 'tolerance': 0.001, 'maximum_iterations': 1000} mmax, mmax_sigma = self.model.get_mmax(self.catalogue, self.config) self.assertTrue(np.isnan(mmax)) self.assertTrue(np.isnan(mmax_sigma)) def _get_pval_qval(self, bval, sigma_b): ''' Get the p-value and q-value from b and sigma b ''' beta = bval * np.log(10.) sigma_beta = sigma_b * np.log(10.) pval = beta / (sigma_beta ** 2.) qval = (beta / sigma_beta) ** 2. return pval, qval
class TestKijkoSellevolBayes(unittest.TestCase): ''' Test the hmtk.seismicity.max_magnitude.KijkoSellevolBayes 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 = { 'b-value': 1.0, 'sigma-b': 0.05, 'input_mmin': 5.0, 'input_mmax': None, 'input_mmax_uncertainty': None, 'tolerance': 0.001, 'maximum_iterations': 1000 } self.model = KijkoSellevolBayes() def test_ksb_intfunc(self): # Tests the integral function of the Kijko-Sellevol-Bayes estimator # of mmax neq = 100. mval = 6.0 mmin = 5.0 # Good case b-value is 1.0, sigma-b is 0.05 pval, qval = self._get_pval_qval(1.0, 0.05) self.assertAlmostEqual( self.model._ksb_intfunc(mval, neq, mmin, pval, qval), 2.4676049E-5) # Bad case b-value is 0.0, sigma-b is 0,05 pval0, qval0 = self._get_pval_qval(0.0, 0.05) self.assertAlmostEqual( self.model._ksb_intfunc(mval, neq, mmin, pval0, qval0), 0.0) # Bad case neq = 0. self.assertAlmostEqual( self.model._ksb_intfunc(mval, 0., mmin, pval0, qval0), 1.0) # Bad case mval < mmin mmin = 6.0 mval = 5.0 self.assertAlmostEqual( np.log10(self.model._ksb_intfunc(mval, neq, mmin, pval, qval)), 95.7451687) def test_get_mmax(self): # Tests the function to calculate mmax using the Kijko-Sellevol-Bayes # operator # Good case - b = 1., sigma_b = 0.05, mmin = 5.0 mmax, mmax_sigma = self.model.get_mmax(self.catalogue, self.config) self.assertAlmostEqual(mmax, 7.6902450) self.assertAlmostEqual(mmax_sigma, 0.30698886) # Bad case 1 - input mmin < catalogue mmin self.config['input_mmin'] = 3.5 mmax, mmax_sigma = self.model.get_mmax(self.catalogue, self.config) self.assertAlmostEqual(mmax, 8.2371167) self.assertAlmostEqual(mmax_sigma, 0.84306841) self.config['input_mmin'] = 4.0 mmax_check, _ = self.model.get_mmax(self.catalogue, self.config) self.assertAlmostEqual(mmax, mmax_check) # Good case 1 - input mmax self.config['input_mmin'] = 5.0 self.config['input_mmax'] = 7.8 self.config['input_mmax_uncertainty'] = 0.2 mmax, mmax_sigma = self.model.get_mmax(self.catalogue, self.config) self.assertAlmostEqual(mmax, 8.9427386) self.assertAlmostEqual(mmax_sigma, 1.16010841) # Bad case 1 - negative b-value (should return nan) self.config = { 'b-value': -0.5, 'sigma-b': 0.05, 'input_mmin': 5.0, 'input_mmax': None, 'input_mmax_uncertainty': None, 'tolerance': 0.001, 'maximum_iterations': 1000 } mmax, mmax_sigma = self.model.get_mmax(self.catalogue, self.config) self.assertTrue(np.isnan(mmax)) self.assertTrue(np.isnan(mmax_sigma)) def _get_pval_qval(self, bval, sigma_b): ''' Get the p-value and q-value from b and sigma b ''' beta = bval * np.log(10.) sigma_beta = sigma_b * np.log(10.) pval = beta / (sigma_beta**2.) qval = (beta / sigma_beta)**2. return pval, qval
mmax, mmax_sigma = mmax_ks.get_mmax(catalogue, mmax_config) print 'Mmax = %8.3f +/- %8.3f' % (mmax, mmax_sigma) # In[ ]: mmax_config = { 'b-value': 1.0, 'sigma-b': 0.05, '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()