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 = AndersonLucoAreaMmax() 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 = AndersonLucoAreaMmax() 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 setUp(self): self.model = AndersonLucoAreaMmax() 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_get_mfd(self): ''' Tests the function to get magnitude frequency distribution ''' self.msr = WC1994() # Test 1: For a fault with 5 mm/yr slip, and an area of 7500 km ** 2 self.msr = WC1994() # Testing all three calculators! for iloc, model_type in enumerate(['First', 'Second', 'Third']): self.model = AndersonLucoAreaMmax() 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., 7500.) test_output = self.model.get_mfd(5.0, 37.5) print(AL83_AREA_MMAX_INC[:, iloc], test_output[2]) np.testing.assert_array_almost_equal(AL83_AREA_MMAX_INC[:, iloc], test_output[2]) # Test case when b-value greater than d-value (raises warning!) self.model = AndersonLucoAreaMmax() 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., 7500.) self.model.get_mfd(5.0, 37.5) 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 5 mm/yr slip, and an area of 7500 km ** 2 self.msr = WC1994() # Testing all three calculators! for iloc, model_type in enumerate(['First', 'Second', 'Third']): self.model = AndersonLucoAreaMmax() 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., 7500.) test_output = self.model.get_mfd(5.0, 37.5) print(AL83_AREA_MMAX_INC[:, iloc], test_output[2]) np.testing.assert_array_almost_equal(AL83_AREA_MMAX_INC[:, iloc], test_output[2]) # Test case when b-value greater than d-value (raises warning!) self.model = AndersonLucoAreaMmax() 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., 7500.) self.model.get_mfd(5.0, 37.5) self.assertTrue(np.all(np.isnan(self.model.occurrence_rate)))
class TestAndersonLucoArbitrary(unittest.TestCase): ''' Tests the Anderson & Luco Arbitrary models :class openquake.hmtk.faults.mfd.anderson_luco_arbitrary.AndersonLucoArbitrary ''' def setUp(self): self.model = AndersonLucoAreaMmax() 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 (Mmax) 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 = AndersonLucoAreaMmax() 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 = AndersonLucoAreaMmax() 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 5 mm/yr slip, and an area of 7500 km ** 2 self.msr = WC1994() # Testing all three calculators! for iloc, model_type in enumerate(['First', 'Second', 'Third']): self.model = AndersonLucoAreaMmax() 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., 7500.) test_output = self.model.get_mfd(5.0, 37.5) print(AL83_AREA_MMAX_INC[:, iloc], test_output[2]) np.testing.assert_array_almost_equal(AL83_AREA_MMAX_INC[:, iloc], test_output[2]) # Test case when b-value greater than d-value (raises warning!) self.model = AndersonLucoAreaMmax() 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., 7500.) self.model.get_mfd(5.0, 37.5) self.assertTrue(np.all(np.isnan(self.model.occurrence_rate)))
class TestAndersonLucoArbitrary(unittest.TestCase): ''' Tests the Anderson & Luco Arbitrary models :class openquake.hmtk.faults.mfd.anderson_luco_arbitrary.AndersonLucoArbitrary ''' def setUp(self): self.model = AndersonLucoAreaMmax() 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 (Mmax) 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 = AndersonLucoAreaMmax() 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 = AndersonLucoAreaMmax() 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 5 mm/yr slip, and an area of 7500 km ** 2 self.msr = WC1994() # Testing all three calculators! for iloc, model_type in enumerate(['First', 'Second', 'Third']): self.model = AndersonLucoAreaMmax() 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., 7500.) test_output = self.model.get_mfd(5.0, 37.5) print(AL83_AREA_MMAX_INC[:, iloc], test_output[2]) np.testing.assert_array_almost_equal(AL83_AREA_MMAX_INC[:, iloc], test_output[2]) # Test case when b-value greater than d-value (raises warning!) self.model = AndersonLucoAreaMmax() 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., 7500.) self.model.get_mfd(5.0, 37.5) self.assertTrue(np.all(np.isnan(self.model.occurrence_rate)))