class TestSyntheticCatalogues(unittest.TestCase): ''' Tests the synthetic catalogue functions ''' def setUp(self): ''' ''' self.occur = AkiMaxLikelihood() def test_generate_magnitudes(self): ''' Tests the hmtk.seismicity.occurence.utils function generate_trunc_gr_magnitudes ''' bvals = [] # Generate set of synthetic catalogues for _ in range(0, 100): mags = rec_utils.generate_trunc_gr_magnitudes(1.0, 4.0, 8.0, 1000) cat = Catalogue.make_from_dict({ 'magnitude': mags, 'year': np.zeros(len(mags), dtype=int) }) bvals.append(self.occur.calculate(cat)[0]) bvals = np.array(bvals) self.assertAlmostEqual(np.mean(bvals), 1.0, 1) def test_generate_synthetic_catalogues(self): ''' Tests the hmtk.seismicity.occurence.utils function generate_synthetic_magnitudes ''' bvals = [] # Generate set of synthetic catalogues for i in range(0, 100): cat1 = rec_utils.generate_synthetic_magnitudes( 4.5, 1.0, 4.0, 8.0, 1000) bvals.append( self.occur.calculate(Catalogue.make_from_dict(cat1))[0]) bvals = np.array(bvals) self.assertAlmostEqual(np.mean(bvals), 1.0, 1)
class TestSyntheticCatalogues(unittest.TestCase): ''' Tests the synthetic catalogue functions ''' def setUp(self): ''' ''' self.occur = AkiMaxLikelihood() def test_generate_magnitudes(self): ''' Tests the hmtk.seismicity.occurence.utils function generate_trunc_gr_magnitudes ''' bvals = [] # Generate set of synthetic catalogues for _ in range(0, 100): mags = rec_utils.generate_trunc_gr_magnitudes(1.0, 4.0, 8.0, 1000) cat = Catalogue.make_from_dict( {'magnitude': mags, 'year': np.zeros(len(mags), dtype=int)}) bvals.append(self.occur.calculate(cat)[0]) bvals = np.array(bvals) self.assertAlmostEqual(np.mean(bvals), 1.0, 1) def test_generate_synthetic_catalogues(self): ''' Tests the hmtk.seismicity.occurence.utils function generate_synthetic_magnitudes ''' bvals = [] # Generate set of synthetic catalogues for i in range(0, 100): cat1 = rec_utils.generate_synthetic_magnitudes(4.5, 1.0, 4.0, 8.0, 1000) bvals.append(self.occur.calculate( Catalogue.make_from_dict(cat1))[0]) bvals = np.array(bvals) self.assertAlmostEqual(np.mean(bvals), 1.0, 1)
class AkiMaximumLikelihoodTestCase(unittest.TestCase): def setUp(self): """ This generates a minimum data-set to be used for the regression. """ # Test A: Generates a data set assuming b=1 and N(m=4.0)=10.0 events self.dmag = 0.1 mext = np.arange(4.0, 7.01, 0.1) self.mval = mext[0:-1] + self.dmag / 2.0 self.bval = 1.0 self.numobs = np.flipud( np.diff(np.flipud(10.0**(-self.bval * mext + 8.0)))) # Test B: Generate a completely artificial catalogue using the # Gutenberg-Richter distribution defined above numobs = np.around(self.numobs) size = int(np.sum(self.numobs)) magnitude = np.zeros(size) lidx = 0 for mag, nobs in zip(self.mval, numobs): uidx = int(lidx + nobs) magnitude[lidx:uidx] = mag + 0.01 lidx = uidx year = np.ones(size) * 1999 self.catalogue = Catalogue.make_from_dict({ 'magnitude': magnitude, 'year': year }) # Create the seismicity occurrence calculator self.aki_ml = AkiMaxLikelihood() def test_aki_maximum_likelihood_A(self): """ Tests that the computed b value corresponds to the same value used to generate the test data set """ bval, sigma_b = self.aki_ml._aki_ml(self.mval, self.numobs) self.assertAlmostEqual(self.bval, bval, 2) def test_aki_maximum_likelihood_B(self): """ Tests that the computed b value corresponds to the same value used to generate the test data set """ bval, sigma_b = self.aki_ml.calculate(self.catalogue) self.assertAlmostEqual(self.bval, bval, 2)
class AkiMaximumLikelihoodTestCase(unittest.TestCase): def setUp(self): """ This generates a minimum data-set to be used for the regression. """ # Test A: Generates a data set assuming b=1 and N(m=4.0)=10.0 events self.dmag = 0.1 mext = np.arange(4.0, 7.01, 0.1) self.mval = mext[0:-1] + self.dmag / 2.0 self.bval = 1.0 self.numobs = np.flipud( np.diff(np.flipud(10.0 ** (-self.bval * mext + 8.0)))) # Test B: Generate a completely artificial catalogue using the # Gutenberg-Richter distribution defined above numobs = np.around(self.numobs) size = int(np.sum(self.numobs)) magnitude = np.zeros(size) lidx = 0 for mag, nobs in zip(self.mval, numobs): uidx = int(lidx+nobs) magnitude[lidx:uidx] = mag + 0.01 lidx = uidx year = np.ones(size) * 1999 self.catalogue = Catalogue.make_from_dict( {'magnitude': magnitude, 'year': year}) # Create the seismicity occurrence calculator self.aki_ml = AkiMaxLikelihood() def test_aki_maximum_likelihood_A(self): """ Tests that the computed b value corresponds to the same value used to generate the test data set """ bval, sigma_b = self.aki_ml._aki_ml(self.mval, self.numobs) self.assertAlmostEqual(self.bval, bval, 2) def test_aki_maximum_likelihood_B(self): """ Tests that the computed b value corresponds to the same value used to generate the test data set """ bval, sigma_b = self.aki_ml.calculate(self.catalogue) self.assertAlmostEqual(self.bval, bval, 2)