def test_weichert_full(self): """ Tests the Weichert function for the synthetic catalogue """ wchrt = Weichert() bval, sigmab, rate, sigma_rate = wchrt.calculate( self.catalogue, self.config, self.completeness) self.assertAlmostEqual(bval, 0.890, 3) self.assertAlmostEqual(sigmab, 0.015, 3) self.assertAlmostEqual(rate, 100.1078, 4) self.assertAlmostEqual(sigma_rate, 2.1218, 4)
def test_weichert_full(self): """ Tests the Weichert function for the synthetic catalogue """ wchrt = Weichert() bval, sigmab, rate, sigma_rate = wchrt.calculate(self.catalogue, self.config, self.completeness) self.assertAlmostEqual(bval, 0.890, 3) self.assertAlmostEqual(sigmab, 0.015, 3) self.assertAlmostEqual(rate, 100.1078, 4) self.assertAlmostEqual(sigma_rate, 2.1218, 4)
class WeichertTestCase(unittest.TestCase): def setUp(self): """ This generates a catalogue to be used for the regression. """ # Generates a data set assuming b=1 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 numobs = np.flipud(np.diff(np.flipud(10.0**(-self.bval * mext + 7.0)))) # Compute the number of observations in the different magnitude # intervals (according to completeness) numobs[0:6] *= 10 numobs[6:13] *= 20 numobs[13:22] *= 50 numobs[22:] *= 100 # Define completeness window compl = np.array([[1900, 1950, 1980, 1990], [6.34, 5.44, 4.74, 3.0]]) self.compl = np.flipud(compl.transpose()) # Compute the number of observations (i.e. earthquakes) in each # magnitude bin numobs = np.around(numobs) magnitude = np.zeros((np.sum(numobs))) year = np.zeros((np.sum(numobs))) * 1999 # Generate the catalogue lidx = 0 for mag, nobs in zip(self.mval, numobs): uidx = int(lidx + nobs) magnitude[lidx:uidx] = mag + 0.01 year_low = compl[0, np.min(np.nonzero(compl[1, :] < mag)[0])] year[lidx:uidx] = (year_low + np.random.rand(uidx - lidx) * (2000 - year_low)) lidx = uidx # Fix the parameters that later will be used for the testing self.catalogue = Catalogue.make_from_dict({ 'magnitude': magnitude, 'year': year }) self.wei = Weichert() self.config = {'Average Type': 'Weighted'} def test_weichert(self): """ Tests that the computed b value corresponds to the same value used to generate the test data set """ bval, sigma_b, aval, sigma_a = self.wei.calculate( self.catalogue, self.config, self.compl) self.assertAlmostEqual(self.bval, bval, 1)
class WeichertTestCase(unittest.TestCase): def setUp(self): """ This generates a catalogue to be used for the regression. """ # Generates a data set assuming b=1 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 numobs = np.flipud(np.diff(np.flipud(10.0**(-self.bval*mext+7.0)))) # Compute the number of observations in the different magnitude # intervals (according to completeness) numobs[0:6] *= 10 numobs[6:13] *= 20 numobs[13:22] *= 50 numobs[22:] *= 100 # Define completeness window compl = np.array([[1900, 1950, 1980, 1990], [6.34, 5.44, 4.74, 3.0]]) self.compl = np.flipud(compl.transpose()) # Compute the number of observations (i.e. earthquakes) in each # magnitude bin numobs = np.around(numobs) magnitude = np.zeros( (np.sum(numobs)) ) year = np.zeros( (np.sum(numobs)) ) * 1999 # Generate the catalogue lidx = 0 for mag, nobs in zip(self.mval, numobs): uidx = int(lidx+nobs) magnitude[lidx:uidx] = mag + 0.01 year_low = compl[0,np.min(np.nonzero(compl[1,:] < mag)[0])] year[lidx:uidx] = (year_low + np.random.rand(uidx-lidx) * (2000-year_low)) lidx = uidx # Fix the parameters that later will be used for the testing self.catalogue = Catalogue.make_from_dict( {'magnitude' : magnitude, 'year' : year}) self.wei = Weichert() self.config = {'Average Type' : 'Weighted'} def test_weichert(self): """ Tests that the computed b value corresponds to the same value used to generate the test data set """ bval, sigma_b, aval, sigma_a = self.wei.calculate(self.catalogue, self.config, self.compl) self.assertAlmostEqual(self.bval, bval, 1)
bval, sigmab, seismicity_rate, sigma_rate = bml_recurrence.calculate(catalogue, recurrence_config, completeness_table) print 'B-value = %9.4f +/- %9.4f' %(bval, sigmab) print 'Rate = %9.4f +/- %9.4f' %(seismicity_rate, sigma_rate) # In[ ]: # Set up the configuration parameters bwc_recurrence = Weichert() bval, sigmab, seismicity_rate, sigma_rate = bwc_recurrence.calculate(catalogue, recurrence_config, completeness_table) print 'B-value = %9.4f +/- %9.4f' %(bval, sigmab) print 'Rate = %9.4f +/- %9.4f' %(seismicity_rate, sigma_rate) # In[ ]: # In[ ]: # Set up the configuration parameters bks_recurrence = KijkoSmit() bval, sigmab, seismicity_rate, sigma_rate = bks_recurrence.calculate(catalogue, recurrence_config, completeness_table)
} bml_recurrence = BMaxLikelihood() bval, sigmab, seismicity_rate, sigma_rate = bml_recurrence.calculate( catalogue, recurrence_config, completeness_table) print 'B-value = %9.4f +/- %9.4f' % (bval, sigmab) print 'Rate = %9.4f +/- %9.4f' % (seismicity_rate, sigma_rate) # In[ ]: # Set up the configuration parameters bwc_recurrence = Weichert() bval, sigmab, seismicity_rate, sigma_rate = bwc_recurrence.calculate( catalogue, recurrence_config, completeness_table) print 'B-value = %9.4f +/- %9.4f' % (bval, sigmab) print 'Rate = %9.4f +/- %9.4f' % (seismicity_rate, sigma_rate) # In[ ]: # In[ ]: # Set up the configuration parameters bks_recurrence = KijkoSmit() bval, sigmab, seismicity_rate, sigma_rate = bks_recurrence.calculate( catalogue, recurrence_config, completeness_table) print 'B-value = %9.4f +/- %9.4f' % (bval, sigmab) print 'Rate (M >= 4.0) = %9.4f +/- %9.4f' % (seismicity_rate, sigma_rate)