'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)

Beispiel #2
0
class TestKijkoNPG(unittest.TestCase):
    '''
    Class to test the Kijko Nonparametric Gaussian function
    '''
    def setUp(self):
        filename = os.path.join(BASE_DATA_PATH, 'completeness_test_cat.csv')
        parser0 = CsvCatalogueParser(filename)
        self.catalogue = parser0.read_file()
        self.config = {
            'maximum_iterations': 1000,
            'number_earthquakes': 100,
            'number_samples': 51,
            'tolerance': 0.05
        }
        self.model = KijkoNonParametricGaussian()

    def test_get_exponential_values(self):
        # Tests the function to derive an exponentially spaced set of values.
        # Tested against Kijko implementation
        min_mag = 5.8
        max_mag = 7.4
        expected_output = np.array([
            5.8, 5.87609089, 5.94679912, 6.01283617, 6.07478116, 6.13311177,
            6.18822664, 6.24046187, 6.29010351, 6.33739696, 6.38255438,
            6.42576041, 6.46717674, 6.50694576, 6.5451935, 6.58203209,
            6.61756168, 6.65187211, 6.68504428, 6.71715129, 6.74825943,
            6.77842898, 6.80771492, 6.83616754, 6.86383296, 6.89075356,
            6.9169684, 6.94251354, 6.96742235, 6.99172576, 7.0154525,
            7.0386293, 7.06128109, 7.08343111, 7.10510113, 7.1263115,
            7.14708132, 7.16742851, 7.18736994, 7.20692147, 7.22609806,
            7.24491382, 7.26338207, 7.28151542, 7.2993258, 7.31682451,
            7.33402228, 7.35092928, 7.36755517, 7.38390916, 7.4
        ])
        np.testing.assert_almost_equal(
            expected_output,
            _get_exponential_spaced_values(min_mag, max_mag, 51))

    def test_h_smooth(self):
        # Function to test the smoothing factor functiob h_smooth

        # Test 1: Good magnitude range (4.0 - 8.0)
        mag = np.arange(4.5, 8.1, 0.1)
        self.assertAlmostEqual(self.model.h_smooth(mag), 0.46)

        # Test 2: Bad magnitude
        mag = np.array([6.5])
        self.assertAlmostEqual(self.model.h_smooth(mag), 0.0)

    def test_gauss_cdf(self):
        # Tests the Gaussian cumulative distribution function

        # Simple case where x = -3 to 3 with a step of 1.
        xvals = np.arange(-7., 8., 1.)
        yvals_expected = np.array([
            0.00000000e+00, 0.00000000e+00, 3.01100756e-05, 8.22638484e-04,
            2.36281702e-02, 2.06039365e-01, 3.39612064e-01, 5.00000000e-01,
            6.60387936e-01, 7.93960635e-01, 9.76371830e-01, 9.99177362e-01,
            9.99969890e-01, 1.00000000e+00, 1.00000000e+00
        ])
        self.assertTrue(
            np.allclose(yvals_expected, self.model._gauss_cdf_hastings(xvals)))

    def test_kijko_npg_intfunc_simps(self):
        '''
        Tests the integration function using Simpson's rule
        '''
        # Simple test using test catalogue data - verified against
        # implementation in Kijko's own code

        # Get the largest 100 events from the catalogue
        idx = np.flipud(np.argsort(self.catalogue.data['magnitude']))
        test_mag = self.catalogue.data['magnitude'][idx[:100]]
        h_fact = self.model.h_smooth(test_mag)
        mvals = _get_exponential_spaced_values(np.min(test_mag),
                                               np.max(test_mag), 51)
        self.assertAlmostEqual(
            0.11026752,
            self.model._kijko_npg_intfunc_simps(mvals, test_mag,
                                                np.max(test_mag), h_fact,
                                                100.))

    def test_get_mmax(self):
        # Tests the main get_mmax function. These test results are derived by
        # applying Kijko's implementation to the top 100 events in the test
        # catalogue
        mmax, mmax_sig = self.model.get_mmax(self.catalogue, self.config)

        self.assertAlmostEqual(mmax, 7.5434318)
        self.assertAlmostEqual(mmax_sig, 0.17485045)
class TestKijkoNPG(unittest.TestCase):
    '''
    Class to test the Kijko Nonparametric Gaussian function
    '''
    def setUp(self):
        parser0 = CsvCatalogueParser(TEST_CAT_1)
        self.catalogue = parser0.read_file()
        self.config = {'maximum_iterations': 1000,
                       'number_earthquakes': 100,
                       'number_samples': 51,
                       'tolerance': 0.05}
        self.model = KijkoNonParametricGaussian()


    def test_get_exponential_values(self):
        '''
        Tests the function to derive an exponentially spaced set of values.
        Tested against Kijko implementation
        '''
        min_mag = 5.8
        max_mag = 7.4
        expected_output = np.array(
            [5.8, 5.87609089, 5.94679912, 6.01283617, 6.07478116, 6.13311177,
             6.18822664, 6.24046187, 6.29010351, 6.33739696, 6.38255438,
             6.42576041, 6.46717674, 6.50694576, 6.5451935 , 6.58203209, 
             6.61756168, 6.65187211, 6.68504428, 6.71715129, 6.74825943, 
             6.77842898, 6.80771492, 6.83616754, 6.86383296, 6.89075356, 
             6.9169684 , 6.94251354, 6.96742235, 6.99172576, 7.0154525, 
             7.0386293 , 7.06128109, 7.08343111, 7.10510113, 7.1263115, 
             7.14708132, 7.16742851, 7.18736994, 7.20692147, 7.22609806, 
             7.24491382, 7.26338207, 7.28151542, 7.2993258, 7.31682451, 
             7.33402228, 7.35092928, 7.36755517, 7.38390916, 7.4])
        self.assertTrue(np.allclose(expected_output, 
            _get_exponential_spaced_values(min_mag, max_mag, 51)))


    def test_h_smooth(self):
        '''
        Function to test the smoothing factor functiob h_smooth
        '''
        # Test 1: Good magnitude range (4.0 - 8.0)
        mag = np.arange(4.5, 8.1, 0.1)
        self.assertAlmostEqual(self.model.h_smooth(mag), 0.46)

        # Test 2: Bad magnitude 
        mag = np.array([6.5])
        self.assertAlmostEqual(self.model.h_smooth(mag), 0.0)

    def test_gauss_cdf(self):
        '''
        Tests the Gaussian cumulative distribution function
        '''
        # Simple case where x = -3 to 3 with a step of 1.
        xvals = np.arange(-7., 8., 1.)
        yvals_expected = np.array(
            [0.00000000e+00, 0.00000000e+00, 3.01100756e-05, 8.22638484e-04, 
             2.36281702e-02, 2.06039365e-01, 3.39612064e-01, 5.00000000e-01, 
             6.60387936e-01, 7.93960635e-01, 9.76371830e-01, 9.99177362e-01, 
             9.99969890e-01, 1.00000000e+00, 1.00000000e+00])
        self.assertTrue(np.allclose(yvals_expected, 
                                    self.model._gauss_cdf_hastings(xvals)))

    def test_kijko_npg_intfunc_simps(self):
        '''
        Tests the integration function using Simpson's rule
        '''
        # Simple test using test catalogue data - verified against 
        # implementation in Kijko's own code
        
        # Get the largest 100 events from the catalogue
        idx = np.flipud(np.argsort(self.catalogue.data['magnitude']))
        test_mag = self.catalogue.data['magnitude'][idx[:100]]
        h_fact = self.model.h_smooth(test_mag)
        mvals = _get_exponential_spaced_values(np.min(test_mag), 
                                               np.max(test_mag), 
                                               51)
        
        self.assertAlmostEqual(0.11026752,
            self.model._kijko_npg_intfunc_simps(mvals, test_mag, 
            np.max(test_mag), h_fact, 100.))

        
    def test_get_mmax(self):
        '''
        Tests the main get_mmax function. These test results are derived by
        applying Kijko's implementation to the top 100 events in the test 
        catalogue
        '''

        mmax, mmax_sig = self.model.get_mmax(self.catalogue, self.config)

        self.assertAlmostEqual(mmax, 7.5434318)
        self.assertAlmostEqual(mmax_sig, 0.17485045)
Beispiel #4
0
}

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)