def test_get_number_faults(self): # Tests the count of the number of faults # No faults self.model = mtkActiveFaultModel('001', 'A Fault Model', faults=[]) self.assertEqual(self.model.get_number_faults(), 0) # Two faults self.model = mtkActiveFaultModel( identifier='001', name='A Fault Model', faults=[mtkActiveFault, mtkActiveFault]) self.assertEqual(self.model.get_number_faults(), 2)
def test_instantiation_no_data(self): ''' Tests instantiation of the class with no information ''' self.model = mtkActiveFaultModel() self.assertIsNone(self.model.id) self.assertIsNone(self.model.name) self.assertListEqual(self.model.faults, [])
def test_instantiation_bad_fault(self): # Tests instantiation with a bad fault input - should raise error with self.assertRaises(ValueError) as ae: self.model = mtkActiveFaultModel('001', 'A Fault Model', 'bad input') self.assertEqual(str(ae.exception), 'Faults must be input as list')
def read_file(self, mesh_spacing=1.0): ''' Reads the file and returns an instance of the FaultSource class. :param float mesh_spacing: Fault mesh spacing (km) ''' # Process the tectonic regionalisation tectonic_reg = self.process_tectonic_regionalisation() model = mtkActiveFaultModel(self.data['Fault_Model_ID'], self.data['Fault_Model_Name']) for fault in self.data['Fault_Model']: fault_geometry = self.read_fault_geometry(fault['Fault_Geometry'], mesh_spacing) if fault['Shear_Modulus']: fault['Shear_Modulus'] = weight_list_to_tuple( fault['Shear_Modulus'], '%s Shear Modulus' % fault['ID']) if fault['Displacement_Length_Ratio']: fault['Displacement_Length_Ratio'] = weight_list_to_tuple( fault['Displacement_Length_Ratio'], '%s Displacement to Length Ratio' % fault['ID']) fault_source = mtkActiveFault( fault['ID'], fault['Fault_Name'], fault_geometry, weight_list_to_tuple(fault['Slip'], '%s - Slip' % fault['ID']), float(fault['Rake']), fault['Tectonic_Region'], float(fault['Aseismic']), weight_list_to_tuple( fault['Scaling_Relation_Sigma'], '%s Scaling_Relation_Sigma' % fault['ID']), neotectonic_fault=None, scale_rel=get_scaling_relation_tuple( fault['Magnitude_Scaling_Relation']), aspect_ratio=fault['Aspect_Ratio'], shear_modulus=fault['Shear_Modulus'], disp_length_ratio=fault['Displacement_Length_Ratio']) if tectonic_reg: fault_source.get_tectonic_regionalisation( tectonic_reg, fault['Tectonic_Region']) assert isinstance(fault['MFD_Model'], list) fault_source.generate_config_set(fault['MFD_Model']) model.faults.append(fault_source) return model, tectonic_reg
def test_instatiation_all_correct(self): # Tests instatiation of the class with correct data self.model = mtkActiveFaultModel('001', 'A Fault Model', faults=[]) self.assertEqual(self.model.id, '001') self.assertEqual(self.model.name, 'A Fault Model') self.assertListEqual(self.model.faults, [])
def test_build_fault_model(self): # Tests the constuction of a fault model with two faults (1 simple, # 1 complex) each with two mfd rates - should produce four sources self.model = mtkActiveFaultModel('001', 'A Fault Model', faults=[]) x0 = Point(30., 30., 0.) x1 = x0.point_at(30., 0., 30.) x2 = x1.point_at(30., 0., 60.) # Total length is 60 km trace = Line([x0, x1, x2]) simple_fault = SimpleFaultGeometry(trace, 90., 0., 20.) # Creates a trace ~60 km long made of 3 points upper_edge = Line([x0, x1, x2]) lower_edge = Line([ x0.point_at(40., 20., 130.), x1.point_at(42., 25., 130.), x2.point_at(41., 22., 130.) ]) complex_fault = ComplexFaultGeometry([upper_edge, lower_edge], 2.0) config = [{ 'MFD_spacing': 0.1, 'Maximum_Magnitude': 7.0, 'Maximum_Uncertainty': None, 'Model_Name': 'Characteristic', 'Model_Weight': 0.5, 'Sigma': 0.1, 'Lower_Bound': -1., 'Upper_Bound': 1. }, { 'MFD_spacing': 0.1, 'Maximum_Magnitude': 7.5, 'Maximum_Uncertainty': None, 'Model_Name': 'Characteristic', 'Model_Weight': 0.5, 'Sigma': 0.1, 'Lower_Bound': -1., 'Upper_Bound': 1. }] fault1 = mtkActiveFault('001', 'Simple Fault 1', simple_fault, [(10.0, 1.0)], -90., None, aspect_ratio=1.0, scale_rel=[(WC1994(), 1.0)], shear_modulus=[(30.0, 1.0)], disp_length_ratio=[(1E-5, 1.0)]) fault1.generate_config_set(config) fault2 = mtkActiveFault('002', 'Complex Fault 1', complex_fault, [(10.0, 1.0)], -90., None, aspect_ratio=1.0, scale_rel=[(WC1994(), 1.0)], shear_modulus=[(30.0, 1.0)], disp_length_ratio=[(1E-5, 1.0)]) fault2.generate_config_set(config) self.model.faults = [fault1, fault2] # Generate source model self.model.build_fault_model() self.assertEqual(len(self.model.source_model.sources), 4) # First source should be an instance of a mtkSimpleFaultSource model1 = self.model.source_model.sources[0] self.assertTrue(isinstance(model1, mtkSimpleFaultSource)) self.assertEqual(model1.id, '001_1') self.assertAlmostEqual(model1.mfd.min_mag, 6.9) np.testing.assert_array_almost_equal( np.log10(np.array(model1.mfd.occurrence_rates)), np.array([-2.95320041, -2.54583708, -2.953200413])) # Second source should be an instance of a mtkSimpleFaultSource model2 = self.model.source_model.sources[1] self.assertTrue(isinstance(model2, mtkSimpleFaultSource)) self.assertEqual(model2.id, '001_2') self.assertAlmostEqual(model2.mfd.min_mag, 7.4) np.testing.assert_array_almost_equal( np.log10(np.array(model2.mfd.occurrence_rates)), np.array([-3.70320041, -3.29583708, -3.70320041])) # Third source should be an instance of a mtkComplexFaultSource model3 = self.model.source_model.sources[2] self.assertTrue(isinstance(model3, mtkComplexFaultSource)) self.assertEqual(model3.id, '002_1') self.assertAlmostEqual(model3.mfd.min_mag, 6.9) np.testing.assert_array_almost_equal( np.log10(np.array(model3.mfd.occurrence_rates)), np.array([-2.59033387, -2.18297054, -2.59033387])) # Fourth source should be an instance of a mtkComplexFaultSource model4 = self.model.source_model.sources[3] self.assertTrue(isinstance(model4, mtkComplexFaultSource)) self.assertEqual(model4.id, '002_2') self.assertAlmostEqual(model4.mfd.min_mag, 7.4) np.testing.assert_array_almost_equal( np.log10(np.array(model4.mfd.occurrence_rates)), np.array([-3.34033387, -2.93297054, -3.34033387]))
def test_build_fault_model(self): # Tests the constuction of a fault model with two faults (1 simple, # 1 complex) each with two mfd rates - should produce four sources self.model = mtkActiveFaultModel('001', 'A Fault Model', faults=[]) x0 = Point(30., 30., 0.) x1 = x0.point_at(30., 0., 30.) x2 = x1.point_at(30., 0., 60.) # Total length is 60 km trace = Line([x0, x1, x2]) simple_fault = SimpleFaultGeometry(trace, 90., 0., 20.) # Creates a trace ~60 km long made of 3 points upper_edge = Line([x0, x1, x2]) lower_edge = Line( [x0.point_at(40., 20., 130.), x1.point_at(42., 25., 130.), x2.point_at(41., 22., 130.)]) complex_fault = ComplexFaultGeometry([upper_edge, lower_edge], 2.0) config = [{'MFD_spacing': 0.1, 'Maximum_Magnitude': 7.0, 'Maximum_Uncertainty': None, 'Model_Name': 'Characteristic', 'Model_Weight': 0.5, 'Sigma': 0.1, 'Lower_Bound': -1., 'Upper_Bound': 1.}, {'MFD_spacing': 0.1, 'Maximum_Magnitude': 7.5, 'Maximum_Uncertainty': None, 'Model_Name': 'Characteristic', 'Model_Weight': 0.5, 'Sigma': 0.1, 'Lower_Bound': -1., 'Upper_Bound': 1.}] fault1 = mtkActiveFault('001', 'Simple Fault 1', simple_fault, [(10.0, 1.0)], -90., None, aspect_ratio=1.0, scale_rel=[(WC1994(), 1.0)], shear_modulus=[(30.0, 1.0)], disp_length_ratio=[(1E-5, 1.0)]) fault1.generate_config_set(config) fault2 = mtkActiveFault('002', 'Complex Fault 1', complex_fault, [(10.0, 1.0)], -90., None, aspect_ratio=1.0, scale_rel=[(WC1994(), 1.0)], shear_modulus=[(30.0, 1.0)], disp_length_ratio=[(1E-5, 1.0)]) fault2.generate_config_set(config) self.model.faults = [fault1, fault2] # Generate source model self.model.build_fault_model() self.assertEqual(len(self.model.source_model.sources), 4) # First source should be an instance of a mtkSimpleFaultSource model1 = self.model.source_model.sources[0] self.assertTrue(isinstance(model1, mtkSimpleFaultSource)) self.assertEqual(model1.id, '001_1') self.assertAlmostEqual(model1.mfd.min_mag, 6.9) np.testing.assert_array_almost_equal( np.log10(np.array(model1.mfd.occurrence_rates)), np.array([-2.95320041, -2.54583708, -2.953200413])) # Second source should be an instance of a mtkSimpleFaultSource model2 = self.model.source_model.sources[1] self.assertTrue(isinstance(model2, mtkSimpleFaultSource)) self.assertEqual(model2.id, '001_2') self.assertAlmostEqual(model2.mfd.min_mag, 7.4) np.testing.assert_array_almost_equal( np.log10(np.array(model2.mfd.occurrence_rates)), np.array([-3.70320041, -3.29583708, -3.70320041])) # Third source should be an instance of a mtkComplexFaultSource model3 = self.model.source_model.sources[2] self.assertTrue(isinstance(model3, mtkComplexFaultSource)) self.assertEqual(model3.id, '002_1') self.assertAlmostEqual(model3.mfd.min_mag, 6.9) np.testing.assert_array_almost_equal( np.log10(np.array(model3.mfd.occurrence_rates)), np.array([-2.59033387, -2.18297054, -2.59033387])) # Fourth source should be an instance of a mtkComplexFaultSource model4 = self.model.source_model.sources[3] self.assertTrue(isinstance(model4, mtkComplexFaultSource)) self.assertEqual(model4.id, '002_2') self.assertAlmostEqual(model4.mfd.min_mag, 7.4) np.testing.assert_array_almost_equal( np.log10(np.array(model4.mfd.occurrence_rates)), np.array([-3.34033387, -2.93297054, -3.34033387]))