예제 #1
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.16239062e-03, 1.71764792e-03, 1.36437624e-03, 1.08376257e-03,
         8.60863210e-04, 6.83807954e-04, 5.43167965e-04, 4.31453651e-04,
         3.42715817e-04, 2.72228850e-04, 2.16239062e-04, 1.71764792e-04,
         1.36437624e-04, 1.08376257e-04, 8.60863210e-05, 6.83807954e-05,
         5.43167965e-05, 4.31453651e-05, 3.42715817e-05, 2.72228850e-05,
         2.16239062e-05, 1.71764792e-05, 1.36437624e-05, 1.08376257e-05,
         8.60863210e-06, 7.65552821e-05, 7.65552821e-05, 7.65552821e-05,
         7.65552821e-05, 7.65552821e-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)
예제 #3
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 = 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(
         [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(
         [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 build_fault_model(area, slip, mmax, config={}, mu=30.0, coupling=1.0):
    """
    
    """
    if not config:
        # Simple Dirac function
        geological_moment = coupling * (mu * 1.0E9) * (area * 1.0E6) * (slip *
                                                                        1.0E-3)
        mmax_moment = moment_function(mmax)
        rate = geological_moment / mmax_moment
        mf_dist = EvenlyDiscretizedMFD(mmax, 0.1, [rate])
        return get_incremental_cumulative(mf_dist)

    d_m = config["MFD_spacing"]
    config["Model_Weight"] = 1.0

    if config["model"] == "Characteristic":
        # Try characteristic
        for key in ["MFD_spacing", "Lower_Bound", "Upper_Bound", "Sigma"]:
            # Verify everything is present
            assert key in config and config[key] is not None
        rec_model = Characteristic()
        rec_model.setUp(config)
        rec_model.mmax = mmax
    elif config["model"] == "Hybrid":
        # Try Hybrid
        for key in ["Minimum_Magnitude", "b_value"]:
            # Verify everything is present
            assert key in config and config[key] is not None
        rec_model = YoungsCoppersmithCharacteristic()
        rec_model.setUp(config)
        rec_model.mmax = mmax
    elif config["model"] == "Exponential":
        # Try exponential
        for key in ["Minimum_Magnitude", "b_value"]:
            # Verify everything is present
            assert key in config and config[key] is not None
        rec_model = YoungsCoppersmithExponential()
        rec_model.setUp(config)
        rec_model.mmax = mmax
        rec_model.mmin += (config["MFD_spacing"] / 2.)
    else:
        raise ValueError("Model %s not recognised" % config["model"])

    mmin, bin_width, rate = rec_model.get_mfd(slip, area, mu)
    mf_dist = EvenlyDiscretizedMFD(mmin, bin_width, rate.tolist())
    return get_incremental_cumulative(mf_dist)
예제 #9
0
class TestYoungsCoppersmithCharacteristic(unittest.TestCase):
    '''
    Tests the
    :class: openquake.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([
            2.16239062e-03, 1.71764792e-03, 1.36437624e-03, 1.08376257e-03,
            8.60863210e-04, 6.83807954e-04, 5.43167965e-04, 4.31453651e-04,
            3.42715817e-04, 2.72228850e-04, 2.16239062e-04, 1.71764792e-04,
            1.36437624e-04, 1.08376257e-04, 8.60863210e-05, 6.83807954e-05,
            5.43167965e-05, 4.31453651e-05, 3.42715817e-05, 2.72228850e-05,
            2.16239062e-05, 1.71764792e-05, 1.36437624e-05, 1.08376257e-05,
            8.60863210e-06, 7.65552821e-05, 7.65552821e-05, 7.65552821e-05,
            7.65552821e-05, 7.65552821e-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: openquake.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(
            [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)