def test_get_mfd(self):
     '''
     Tests the function to get the magnitude frequency distribution
     This function essentially wraps the 
     YoungsCoppersmith1985MFD.from_total_moment rate function, which is 
     tested in the openquake.hazardlib.
     '''
     # Simple test using previously defined fault
     # Area = Length x Width (120 km x 60 km)
     # Slip = 1.0 mm/yr
     expected_rates = np.array(
         [1.60861975e-03, 1.27777208e-03, 1.01497044e-03,
          8.06219681e-04, 6.40403056e-04, 5.08690229e-04,
          4.04067011e-04, 3.20961836e-04, 2.54949049e-04,
          2.02513228e-04, 1.60861975e-04, 1.27777208e-04,
          1.01497044e-04, 8.06219681e-05, 6.40403056e-05,
          5.08690229e-05, 4.04067011e-05, 3.20961836e-05,
          2.54949049e-05, 2.02513228e-05, 1.60861975e-05,
          1.27777208e-05, 1.01497044e-05, 8.06219681e-06,
          6.40403056e-06, 5.08690229e-06, 4.04067011e-06,
          3.20961836e-06, 3.20253886e-05, 3.20253886e-05,
          3.20253886e-05, 3.20253886e-05, 3.20253886e-05])
     self.model = YoungsCoppersmithCharacteristic()
     self.config['Maximum_Magnitude'] = 8.0
     self.config['Maximum_Magnitude_Uncertainty'] = None    
     self.model.setUp(self.config)
     self.model.get_mmax(self.config, self.msr, 0., 7200.)
     output1 = self.model.get_mfd(1.0, 7200.)
     np.testing.assert_array_almost_equal(expected_rates, output1[2])
     self.assertAlmostEqual(output1[0], 5.05)
    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 = YoungsCoppersmithCharacteristic()
        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 = YoungsCoppersmithCharacteristic()
        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 = YoungsCoppersmithCharacteristic()
        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 = YoungsCoppersmithCharacteristic()
        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)
Exemple #4
0
 def test_get_mfd(self):
     '''
     Tests the function to get the magnitude frequency distribution
     This function essentially wraps the
     YoungsCoppersmith1985MFD.from_total_moment rate function, which is
     tested in the openquake.hazardlib.
     '''
     # Simple test using previously defined fault
     # Area = Length x Width (120 km x 60 km)
     # Slip = 1.0 mm/yr
     expected_rates = np.array([
         2.14512891e-03, 1.70393646e-03, 1.35348484e-03, 1.07511122e-03,
         8.53991200e-04, 6.78349322e-04, 5.38832020e-04, 4.28009487e-04,
         3.39980020e-04, 2.70055729e-04, 2.14512891e-04, 1.70393646e-04,
         1.35348484e-04, 1.07511122e-04, 8.53991200e-05, 6.78349322e-05,
         5.38832020e-05, 4.28009487e-05, 3.39980020e-05, 2.70055729e-05,
         2.14512891e-05, 1.70393646e-05, 1.35348484e-05, 1.07511122e-05,
         8.53991200e-06, 7.59441645e-05, 7.59441645e-05, 7.59441645e-05,
         7.59441645e-05, 7.59441645e-05
     ])
     self.model = YoungsCoppersmithCharacteristic()
     self.config['Maximum_Magnitude'] = 8.0
     self.config['Maximum_Magnitude_Uncertainty'] = None
     self.model.setUp(self.config)
     self.model.get_mmax(self.config, self.msr, 0., 7200.)
     output1 = self.model.get_mfd(1.0, 7200.)
     np.testing.assert_array_almost_equal(expected_rates, output1[2])
     self.assertAlmostEqual(output1[0], 5.05)
 def setUp(self):
     '''
     '''
     self.model = YoungsCoppersmithCharacteristic()
     self.msr = WC1994()
     self.config = {'MFD_spacing': 0.1,
                    'Maximum_Magnitude': 8.0,
                    'Maximum_Magnitude_Uncertainty': None,
                    'Minimum_Magnitude': 5.0,
                    'Model_Weight': 1.0,
                    'b_value': [1.0, 0.1],
                    'delta_m': None}
 def test_get_mfd(self):
     '''
     Tests the function to get the magnitude frequency distribution
     This function essentially wraps the
     YoungsCoppersmith1985MFD.from_total_moment rate function, which is
     tested in the openquake.hazardlib.
     '''
     # Simple test using previously defined fault
     # Area = Length x Width (120 km x 60 km)
     # Slip = 1.0 mm/yr
     expected_rates = np.array(
         [1.60861975e-03, 1.27777208e-03, 1.01497044e-03,
          8.06219681e-04, 6.40403056e-04, 5.08690229e-04,
          4.04067011e-04, 3.20961836e-04, 2.54949049e-04,
          2.02513228e-04, 1.60861975e-04, 1.27777208e-04,
          1.01497044e-04, 8.06219681e-05, 6.40403056e-05,
          5.08690229e-05, 4.04067011e-05, 3.20961836e-05,
          2.54949049e-05, 2.02513228e-05, 1.60861975e-05,
          1.27777208e-05, 1.01497044e-05, 8.06219681e-06,
          6.40403056e-06, 5.08690229e-06, 4.04067011e-06,
          3.20961836e-06, 3.20253886e-05, 3.20253886e-05,
          3.20253886e-05, 3.20253886e-05, 3.20253886e-05])
     self.model = YoungsCoppersmithCharacteristic()
     self.config['Maximum_Magnitude'] = 8.0
     self.config['Maximum_Magnitude_Uncertainty'] = None
     self.model.setUp(self.config)
     self.model.get_mmax(self.config, self.msr, 0., 7200.)
     output1 = self.model.get_mfd(1.0, 7200.)
     np.testing.assert_array_almost_equal(expected_rates, output1[2])
     self.assertAlmostEqual(output1[0], 5.05)
 def test_get_mfd(self):
     '''
     Tests the function to get the magnitude frequency distribution
     This function essentially wraps the
     YoungsCoppersmith1985MFD.from_total_moment rate function, which is
     tested in the openquake.hazardlib.
     '''
     # Simple test using previously defined fault
     # Area = Length x Width (120 km x 60 km)
     # Slip = 1.0 mm/yr
     expected_rates = np.array(
         [2.14512891e-03, 1.70393646e-03, 1.35348484e-03,
          1.07511122e-03, 8.53991200e-04, 6.78349322e-04, 
          5.38832020e-04, 4.28009487e-04, 3.39980020e-04,
          2.70055729e-04, 2.14512891e-04, 1.70393646e-04,
          1.35348484e-04, 1.07511122e-04, 8.53991200e-05, 
          6.78349322e-05, 5.38832020e-05, 4.28009487e-05, 
          3.39980020e-05, 2.70055729e-05, 2.14512891e-05,
          1.70393646e-05, 1.35348484e-05, 1.07511122e-05,
          8.53991200e-06, 7.59441645e-05, 7.59441645e-05, 
          7.59441645e-05, 7.59441645e-05, 7.59441645e-05])
     self.model = YoungsCoppersmithCharacteristic()
     self.config['Maximum_Magnitude'] = 8.0
     self.config['Maximum_Magnitude_Uncertainty'] = None
     self.model.setUp(self.config)
     self.model.get_mmax(self.config, self.msr, 0., 7200.)
     output1 = self.model.get_mfd(1.0, 7200.)
     np.testing.assert_array_almost_equal(expected_rates, output1[2])
     self.assertAlmostEqual(output1[0], 5.05)
 def setUp(self):
     '''
     '''
     self.model = YoungsCoppersmithCharacteristic()
     self.msr = WC1994()
     self.config = {'MFD_spacing': 0.1,
                    'Maximum_Magnitude': 8.0,
                    'Maximum_Magnitude_Uncertainty': None,
                    'Minimum_Magnitude': 5.0,
                    'Model_Weight': 1.0,
                    'b_value': [1.0, 0.1],
                    'delta_m': None}
class TestYoungsCoppersmithCharacteristic(unittest.TestCase):
    '''
    Tests the
    :class: hmtk.faults.mfd.youngs_coppersmith.YoungsCoppersmithCharacteristic
    '''
    def setUp(self):
        '''
        '''
        self.model = YoungsCoppersmithCharacteristic()
        self.msr = WC1994()
        self.config = {'MFD_spacing': 0.1,
                       'Maximum_Magnitude': 8.0,
                       'Maximum_Magnitude_Uncertainty': None,
                       'Minimum_Magnitude': 5.0,
                       'Model_Weight': 1.0,
                       'b_value': [1.0, 0.1],
                       'delta_m': None}

    def test_class_setup(self):
        '''
        Tests the basic setup of the class
        '''
        # Test case 1 - delta not set
        expected_dict = {
            'b_value': 1.0,
            'b_value_sigma': 0.1,
            'bin_width': 0.1,
            'mfd_type': 'Youngs & Coppersmith (1985) Characteristic',
            'mfd_weight': 1.0,
            'mmax': None,
            'mmax_sigma': None,
            'mmin': 5.0,
            'occurrence_rate': None,
            'model': 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 = YoungsCoppersmithCharacteristic()
        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 = YoungsCoppersmithCharacteristic()
        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 the magnitude frequency distribution
        This function essentially wraps the
        YoungsCoppersmith1985MFD.from_total_moment rate function, which is
        tested in the openquake.hazardlib.
        '''
        # Simple test using previously defined fault
        # Area = Length x Width (120 km x 60 km)
        # Slip = 1.0 mm/yr
        expected_rates = np.array(
            [1.60861975e-03, 1.27777208e-03, 1.01497044e-03,
             8.06219681e-04, 6.40403056e-04, 5.08690229e-04,
             4.04067011e-04, 3.20961836e-04, 2.54949049e-04,
             2.02513228e-04, 1.60861975e-04, 1.27777208e-04,
             1.01497044e-04, 8.06219681e-05, 6.40403056e-05,
             5.08690229e-05, 4.04067011e-05, 3.20961836e-05,
             2.54949049e-05, 2.02513228e-05, 1.60861975e-05,
             1.27777208e-05, 1.01497044e-05, 8.06219681e-06,
             6.40403056e-06, 5.08690229e-06, 4.04067011e-06,
             3.20961836e-06, 3.20253886e-05, 3.20253886e-05,
             3.20253886e-05, 3.20253886e-05, 3.20253886e-05])
        self.model = YoungsCoppersmithCharacteristic()
        self.config['Maximum_Magnitude'] = 8.0
        self.config['Maximum_Magnitude_Uncertainty'] = None
        self.model.setUp(self.config)
        self.model.get_mmax(self.config, self.msr, 0., 7200.)
        output1 = self.model.get_mfd(1.0, 7200.)
        np.testing.assert_array_almost_equal(expected_rates, output1[2])
        self.assertAlmostEqual(output1[0], 5.05)
class TestYoungsCoppersmithCharacteristic(unittest.TestCase):
    '''
    Tests the
    :class: hmtk.faults.mfd.youngs_coppersmith.YoungsCoppersmithCharacteristic
    '''
    def setUp(self):
        '''
        '''
        self.model = YoungsCoppersmithCharacteristic()
        self.msr = WC1994()
        self.config = {'MFD_spacing': 0.1,
                       'Maximum_Magnitude': 8.0,
                       'Maximum_Magnitude_Uncertainty': None,
                       'Minimum_Magnitude': 5.0,
                       'Model_Weight': 1.0,
                       'b_value': [1.0, 0.1],
                       'delta_m': None}
    
    def test_class_setup(self):
        '''
        Tests the basic setup of the class
        '''
        # Test case 1 - delta not set
        expected_dict = {
            'b_value': 1.0,
            'b_value_sigma': 0.1,
            'bin_width': 0.1,
            'mfd_type': 'Youngs & Coppersmith (1985) Characteristic',
            'mfd_weight': 1.0,
            'mmax': None,
            'mmax_sigma': None,
            'mmin': 5.0,
            'occurrence_rate': None,
            'model': 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 = YoungsCoppersmithCharacteristic()
        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 = YoungsCoppersmithCharacteristic()
        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 the magnitude frequency distribution
        This function essentially wraps the 
        YoungsCoppersmith1985MFD.from_total_moment rate function, which is 
        tested in the openquake.hazardlib.
        '''
        # Simple test using previously defined fault
        # Area = Length x Width (120 km x 60 km)
        # Slip = 1.0 mm/yr
        expected_rates = np.array(
            [1.60861975e-03, 1.27777208e-03, 1.01497044e-03,
             8.06219681e-04, 6.40403056e-04, 5.08690229e-04,
             4.04067011e-04, 3.20961836e-04, 2.54949049e-04,
             2.02513228e-04, 1.60861975e-04, 1.27777208e-04,
             1.01497044e-04, 8.06219681e-05, 6.40403056e-05,
             5.08690229e-05, 4.04067011e-05, 3.20961836e-05,
             2.54949049e-05, 2.02513228e-05, 1.60861975e-05,
             1.27777208e-05, 1.01497044e-05, 8.06219681e-06,
             6.40403056e-06, 5.08690229e-06, 4.04067011e-06,
             3.20961836e-06, 3.20253886e-05, 3.20253886e-05,
             3.20253886e-05, 3.20253886e-05, 3.20253886e-05])
        self.model = YoungsCoppersmithCharacteristic()
        self.config['Maximum_Magnitude'] = 8.0
        self.config['Maximum_Magnitude_Uncertainty'] = None    
        self.model.setUp(self.config)
        self.model.get_mmax(self.config, self.msr, 0., 7200.)
        output1 = self.model.get_mfd(1.0, 7200.)
        np.testing.assert_array_almost_equal(expected_rates, output1[2])
        self.assertAlmostEqual(output1[0], 5.05)