Exemplo n.º 1
0
    def test_get_mmax(self):
        '''
        Tests the function to get Mmax
        Values come from WC1994 (tested in openquake.hazardlib) - only 
        functionality is tested for here!
        '''
        # Case 1 MMmax and uncertainty specified in config
        self.config['Maximum_Magnitude'] = 8.0
        self.config['Maximum_Magnitude_Uncertainty'] = 0.2

        self.model = AndersonLucoArbitrary()
        self.model.setUp(self.config)
        self.model.get_mmax(self.config, self.msr, 0., 8500.)
        self.assertAlmostEqual(self.model.mmax, 8.0)
        self.assertAlmostEqual(self.model.mmax_sigma, 0.2)

        # Case 2: Mmax and uncertainty not specified in config
        self.config['Maximum_Magnitude'] = None
        self.config['Maximum_Magnitude_Uncertainty'] = None

        self.model = AndersonLucoArbitrary()
        self.model.setUp(self.config)
        self.model.get_mmax(self.config, self.msr, 0., 8500.)
        self.assertAlmostEqual(self.model.mmax, 7.9880073)
        self.assertAlmostEqual(self.model.mmax_sigma, 0.23)
    def test_get_mmax(self):
        '''
        Tests the function to get Mmax
        Values come from WC1994 (tested in openquake.hazardlib) - only
        functionality is tested for here!
        '''
        # Case 1 MMmax and uncertainty specified in config
        self.config['Maximum_Magnitude'] = 8.0
        self.config['Maximum_Magnitude_Uncertainty'] = 0.2

        self.model = AndersonLucoArbitrary()
        self.model.setUp(self.config)
        self.model.get_mmax(self.config, self.msr, 0., 8500.)
        self.assertAlmostEqual(self.model.mmax, 8.0)
        self.assertAlmostEqual(self.model.mmax_sigma, 0.2)

        # Case 2: Mmax and uncertainty not specified in config
        self.config['Maximum_Magnitude'] = None
        self.config['Maximum_Magnitude_Uncertainty'] = None

        self.model = AndersonLucoArbitrary()
        self.model.setUp(self.config)
        self.model.get_mmax(self.config, self.msr, 0., 8500.)
        self.assertAlmostEqual(self.model.mmax, 7.9880073)
        self.assertAlmostEqual(self.model.mmax_sigma, 0.23)
Exemplo n.º 3
0
    def setUp(self):
        self.model = AndersonLucoArbitrary()
        self.config = {
            'Model_Type': 'First',
            'MFD_spacing': 0.1,
            'Model_Weight': 1.0,
            'Minimum_Magnitude': 5.0,
            'Maximum_Magnitude': None,
            'b_value': [1.0, 0.1]
        }

        self.msr = WC1994()
    def setUp(self):
        self.model = AndersonLucoArbitrary()
        self.config = {'Model_Type': 'First',
                      'MFD_spacing': 0.1,
                      'Model_Weight': 1.0,
                      'Minimum_Magnitude': 5.0,
                      'Maximum_Magnitude': None,
                      'b_value': [1.0, 0.1]}

        self.msr = WC1994()
Exemplo n.º 5
0
    def test_get_mfd(self):
        '''
        Tests the function to get magnitude frequency distribution
        '''
        self.msr = WC1994()

        # Test 1: For a fault with 20 mm/yr slip, and an area of 30000 km ** 2
        self.msr = WC1994()
        # Testing all three calculators!
        for iloc, model_type in enumerate(['First', 'Second', 'Third']):
            self.model = AndersonLucoArbitrary()

            self.config = {
                'Model_Type': model_type,
                'MFD_spacing': 0.1,
                'Model_Weight': 1.0,
                'Minimum_Magnitude': 5.0,
                'Maximum_Magnitude': None,
                'b_value': [1.0, 0.1]
            }
            self.model.setUp(self.config)
            self.model.get_mmax(self.config, self.msr, 0., 30000.)
            test_output = self.model.get_mfd(20., 30000.)
            print AL83_INC_DATA[:, iloc], test_output[2]
            np.testing.assert_array_almost_equal(AL83_INC_DATA[:, iloc],
                                                 test_output[2])

            # Test case when b-value greater than d-value (raises warning!)
            self.model = AndersonLucoArbitrary()

            self.config = {
                'Model_Type': model_type,
                'MFD_spacing': 0.1,
                'Model_Weight': 1.0,
                'Minimum_Magnitude': 5.0,
                'Maximum_Magnitude': None,
                'b_value': [2.0, 0.1]
            }
            self.model.setUp(self.config)
            self.model.get_mmax(self.config, self.msr, 0., 30000.)
            self.model.get_mfd(20., 30000.)
            self.assertTrue(np.all(np.isnan(self.model.occurrence_rate)))
    def test_get_mfd(self):
        '''
        Tests the function to get magnitude frequency distribution
        '''
        self.msr = WC1994()

        # Test 1: For a fault with 20 mm/yr slip, and an area of 30000 km ** 2
        self.msr = WC1994()
        # Testing all three calculators!
        for iloc, model_type in enumerate(['First', 'Second', 'Third']):
            self.model = AndersonLucoArbitrary()

            self.config = {'Model_Type': model_type,
                          'MFD_spacing': 0.1,
                          'Model_Weight': 1.0,
                          'Minimum_Magnitude': 5.0,
                          'Maximum_Magnitude': None,
                          'b_value': [1.0, 0.1]}
            self.model.setUp(self.config)
            self.model.get_mmax(self.config, self.msr, 0., 30000.)
            test_output = self.model.get_mfd(20., 30000.)
            print AL83_INC_DATA[:, iloc], test_output[2]
            np.testing.assert_array_almost_equal(AL83_INC_DATA[:, iloc],
                                                 test_output[2])

            # Test case when b-value greater than d-value (raises warning!)
            self.model = AndersonLucoArbitrary()

            self.config = {'Model_Type': model_type,
                          'MFD_spacing': 0.1,
                          'Model_Weight': 1.0,
                          'Minimum_Magnitude': 5.0,
                          'Maximum_Magnitude': None,
                          'b_value': [2.0, 0.1]}
            self.model.setUp(self.config)
            self.model.get_mmax(self.config, self.msr, 0., 30000.)
            self.model.get_mfd(20., 30000.)
            self.assertTrue(np.all(np.isnan(self.model.occurrence_rate)))
class TestAndersonLucoArbitrary(unittest.TestCase):
    '''
    Tests the Anderson & Luco Arbitrary models
    :class hmtk.faults.mfd.anderson_luco_arbitrary.AndersonLucoArbitrary
    '''
    def setUp(self):
        self.model = AndersonLucoArbitrary()
        self.config = {'Model_Type': 'First',
                      'MFD_spacing': 0.1,
                      'Model_Weight': 1.0,
                      'Minimum_Magnitude': 5.0,
                      'Maximum_Magnitude': None,
                      'b_value': [1.0, 0.1]}

        self.msr = WC1994()


    def test_case_setup(self):
        '''
        Tests the basic setup
        '''
        expected_dict = {'b_value': 1.0,
                         'b_value_sigma': 0.1,
                         'bin_width': 0.1,
                         'mfd_model': 'Anderson & Luco (Arbitrary) First',
                         'mfd_type': 'First',
                         'mfd_weight': 1.0,
                         'mmax': None,
                         'mmax_sigma': None,
                         'mmin': 5.0,
                         'occurrence_rate': None}
        self.model.setUp(self.config)
        self.assertDictEqual(expected_dict, self.model.__dict__)

    def test_get_mmax(self):
        '''
        Tests the function to get Mmax
        Values come from WC1994 (tested in openquake.hazardlib) - only
        functionality is tested for here!
        '''
        # Case 1 MMmax and uncertainty specified in config
        self.config['Maximum_Magnitude'] = 8.0
        self.config['Maximum_Magnitude_Uncertainty'] = 0.2

        self.model = AndersonLucoArbitrary()
        self.model.setUp(self.config)
        self.model.get_mmax(self.config, self.msr, 0., 8500.)
        self.assertAlmostEqual(self.model.mmax, 8.0)
        self.assertAlmostEqual(self.model.mmax_sigma, 0.2)

        # Case 2: Mmax and uncertainty not specified in config
        self.config['Maximum_Magnitude'] = None
        self.config['Maximum_Magnitude_Uncertainty'] = None

        self.model = AndersonLucoArbitrary()
        self.model.setUp(self.config)
        self.model.get_mmax(self.config, self.msr, 0., 8500.)
        self.assertAlmostEqual(self.model.mmax, 7.9880073)
        self.assertAlmostEqual(self.model.mmax_sigma, 0.23)

    def test_get_mfd(self):
        '''
        Tests the function to get magnitude frequency distribution
        '''
        self.msr = WC1994()

        # Test 1: For a fault with 20 mm/yr slip, and an area of 30000 km ** 2
        self.msr = WC1994()
        # Testing all three calculators!
        for iloc, model_type in enumerate(['First', 'Second', 'Third']):
            self.model = AndersonLucoArbitrary()

            self.config = {'Model_Type': model_type,
                          'MFD_spacing': 0.1,
                          'Model_Weight': 1.0,
                          'Minimum_Magnitude': 5.0,
                          'Maximum_Magnitude': None,
                          'b_value': [1.0, 0.1]}
            self.model.setUp(self.config)
            self.model.get_mmax(self.config, self.msr, 0., 30000.)
            test_output = self.model.get_mfd(20., 30000.)
            print AL83_INC_DATA[:, iloc], test_output[2]
            np.testing.assert_array_almost_equal(AL83_INC_DATA[:, iloc],
                                                 test_output[2])

            # Test case when b-value greater than d-value (raises warning!)
            self.model = AndersonLucoArbitrary()

            self.config = {'Model_Type': model_type,
                          'MFD_spacing': 0.1,
                          'Model_Weight': 1.0,
                          'Minimum_Magnitude': 5.0,
                          'Maximum_Magnitude': None,
                          'b_value': [2.0, 0.1]}
            self.model.setUp(self.config)
            self.model.get_mmax(self.config, self.msr, 0., 30000.)
            self.model.get_mfd(20., 30000.)
            self.assertTrue(np.all(np.isnan(self.model.occurrence_rate)))
Exemplo n.º 8
0
class TestAndersonLucoArbitrary(unittest.TestCase):
    '''
    Tests the Anderson & Luco Arbitrary models
    :class hmtk.faults.mfd.anderson_luco_arbitrary.AndersonLucoArbitrary
    '''
    def setUp(self):
        self.model = AndersonLucoArbitrary()
        self.config = {
            'Model_Type': 'First',
            'MFD_spacing': 0.1,
            'Model_Weight': 1.0,
            'Minimum_Magnitude': 5.0,
            'Maximum_Magnitude': None,
            'b_value': [1.0, 0.1]
        }

        self.msr = WC1994()

    def test_case_setup(self):
        '''
        Tests the basic setup
        '''
        expected_dict = {
            'b_value': 1.0,
            'b_value_sigma': 0.1,
            'bin_width': 0.1,
            'mfd_model': 'Anderson & Luco (Arbitrary) First',
            'mfd_type': 'First',
            'mfd_weight': 1.0,
            'mmax': None,
            'mmax_sigma': None,
            'mmin': 5.0,
            'occurrence_rate': None
        }
        self.model.setUp(self.config)
        self.assertDictEqual(expected_dict, self.model.__dict__)

    def test_get_mmax(self):
        '''
        Tests the function to get Mmax
        Values come from WC1994 (tested in openquake.hazardlib) - only 
        functionality is tested for here!
        '''
        # Case 1 MMmax and uncertainty specified in config
        self.config['Maximum_Magnitude'] = 8.0
        self.config['Maximum_Magnitude_Uncertainty'] = 0.2

        self.model = AndersonLucoArbitrary()
        self.model.setUp(self.config)
        self.model.get_mmax(self.config, self.msr, 0., 8500.)
        self.assertAlmostEqual(self.model.mmax, 8.0)
        self.assertAlmostEqual(self.model.mmax_sigma, 0.2)

        # Case 2: Mmax and uncertainty not specified in config
        self.config['Maximum_Magnitude'] = None
        self.config['Maximum_Magnitude_Uncertainty'] = None

        self.model = AndersonLucoArbitrary()
        self.model.setUp(self.config)
        self.model.get_mmax(self.config, self.msr, 0., 8500.)
        self.assertAlmostEqual(self.model.mmax, 7.9880073)
        self.assertAlmostEqual(self.model.mmax_sigma, 0.23)

    def test_get_mfd(self):
        '''
        Tests the function to get magnitude frequency distribution
        '''
        self.msr = WC1994()

        # Test 1: For a fault with 20 mm/yr slip, and an area of 30000 km ** 2
        self.msr = WC1994()
        # Testing all three calculators!
        for iloc, model_type in enumerate(['First', 'Second', 'Third']):
            self.model = AndersonLucoArbitrary()

            self.config = {
                'Model_Type': model_type,
                'MFD_spacing': 0.1,
                'Model_Weight': 1.0,
                'Minimum_Magnitude': 5.0,
                'Maximum_Magnitude': None,
                'b_value': [1.0, 0.1]
            }
            self.model.setUp(self.config)
            self.model.get_mmax(self.config, self.msr, 0., 30000.)
            test_output = self.model.get_mfd(20., 30000.)
            print AL83_INC_DATA[:, iloc], test_output[2]
            np.testing.assert_array_almost_equal(AL83_INC_DATA[:, iloc],
                                                 test_output[2])

            # Test case when b-value greater than d-value (raises warning!)
            self.model = AndersonLucoArbitrary()

            self.config = {
                'Model_Type': model_type,
                'MFD_spacing': 0.1,
                'Model_Weight': 1.0,
                'Minimum_Magnitude': 5.0,
                'Maximum_Magnitude': None,
                'b_value': [2.0, 0.1]
            }
            self.model.setUp(self.config)
            self.model.get_mmax(self.config, self.msr, 0., 30000.)
            self.model.get_mfd(20., 30000.)
            self.assertTrue(np.all(np.isnan(self.model.occurrence_rate)))