def test_poplate_region_with_inputs(self): ''' Tests the population of the tectonic regions with input values ''' region_dict = [{'Code': '001', 'Name': 'Active Shallow', 'Shear_Modulus': [(20., 0.3), (30., 0.7)], 'Displacement_Length_Ratio': [(1.5E-5, 1.0)], 'Magnitude_Scaling_Relation': [(WC1994, 1.0)]}, {'Code': '002', 'Name': 'Stable Continental', 'Shear_Modulus': [(30., 1.0)], 'Displacement_Length_Ratio': [(1.0E-4, 1.0)], 'Magnitude_Scaling_Relation': [(WC1994, 1.0)]} ] expected_key_list = ['Active Shallow', 'Stable Continental'] expected_regions = [{'id': '001', 'region_name': 'Active Shallow', 'shear_modulus': [(20., 0.3), (30., 0.7)], 'disp_length_ratio': [(1.5E-5, 1.0)], 'scaling_rel': [(WC1994, 1.0)]}, {'id': '002', 'region_name': 'Stable Continental', 'shear_modulus': [(30., 1.0)], 'disp_length_ratio': [(1.0E-4, 1.0)], 'scaling_rel': [(WC1994, 1.0)]}] self.tect_reg = TectonicRegionalisation() self.tect_reg.populate_regions(region_dict) for ival, test_reg in enumerate(self.tect_reg.regionalisation): self.assertDictEqual(expected_regions[ival], test_reg.__dict__) self.assertListEqual(expected_key_list, self.tect_reg.key_list) self.assertEqual(2, self.tect_reg.get_number_regions())
def test_basic_instantiation(self): ''' Test simple setup ''' # Test setup self.tect_reg = TectonicRegionalisation() self.assertDictEqual({'regionalisation': [], 'key_list': []}, self.tect_reg.__dict__) # Check number of regions is 0 self.assertEqual(0, self.tect_reg.get_number_regions())
def process_tectonic_regionalisation(self): ''' Processes the tectonic regionalisation from the yaml file ''' if 'tectonic_regionalisation' in self.data.keys(): tectonic_reg = TectonicRegionalisation() tectonic_reg.populate_regions( parse_tect_region_dict_to_tuples( self.data['tectonic_regionalisation'])) else: tectonic_reg = None return tectonic_reg
def process_tectonic_regionalisation(self): ''' Processes the tectonic regionalisation from the yaml file ''' if 'tectonic_regionalisation' in self.data.keys(): tectonic_reg = TectonicRegionalisation() tectonic_reg.populate_regions( parse_tect_region_dict_to_tuples( self.data['tectonic_regionalisation'])) else: tectonic_reg = None return tectonic_reg
def test_get_tectonic_regionalisation_missing_case(self): ''' Test case when no region is defined - should raise error ''' # Set up regionalistion region_dict = [{'Code': '001', 'Name': 'Active Shallow Crust'}] tect_reg = TectonicRegionalisation() tect_reg.populate_regions(region_dict) self.fault = mtkActiveFault('001', 'A Fault', self.simple_fault, self.slip, 0., None) with self.assertRaises(ValueError) as ae: self.fault.get_tectonic_regionalisation(tect_reg, None) self.assertEqual(ae.exception.message, 'Tectonic region classification missing or ' 'not defined in regionalisation')
def test_populate_region_accepting_defaults(self): ''' Tests the population of the tectonic regions with default values ''' region_dict = [{'Code': '001', 'Name': 'Active Shallow'}] expected_key_list = ['Active Shallow'] self.tect_reg = TectonicRegionalisation() self.tect_reg.populate_regions(region_dict) trg = self.tect_reg.regionalisation[0] self.assertEqual(trg.id, '001') self.assertEqual(trg.region_name, 'Active Shallow') self.assertAlmostEqual(trg.shear_modulus[0][0], 30.0) self.assertAlmostEqual(trg.shear_modulus[0][1], 1.0) self.assertAlmostEqual(trg.disp_length_ratio[0][0], 1.25E-5) self.assertAlmostEqual(trg.disp_length_ratio[0][1], 1.0) self.assertTrue(isinstance(trg.scaling_rel[0][0], WC1994)) self.assertAlmostEqual(trg.scaling_rel[0][1], 1.0) self.assertListEqual(expected_key_list, self.tect_reg.key_list) self.assertEqual(1, self.tect_reg.get_number_regions())
def test_get_tectonic_regionalisation(self): ''' Tests the retreival of tectonic regionalisation information ''' # Set up regionalistion region_dict = [{'Code': '001', 'Name': 'Active Shallow Crust'}] tect_reg = TectonicRegionalisation() tect_reg.populate_regions(region_dict) # Test successful case self.fault = mtkActiveFault('001', 'A Fault', self.simple_fault, self.slip, 0., None) self.fault.get_tectonic_regionalisation(tect_reg, 'Active Shallow Crust') self.assertEqual(self.fault.trt, 'Active Shallow Crust') # Should take default values self.assertListEqual(self.fault.shear_modulus, [(30., 1.0)]) self.assertListEqual(self.fault.disp_length_ratio, [(1.25E-5, 1.0)]) self.assertTrue(isinstance(self.fault.msr[0][0], WC1994)) self.assertAlmostEqual(self.fault.msr[0][1], 1.0)
class TestTectonicRegionalisation(unittest.TestCase): ''' Class to test the module hmtk.faults.tectonic_regionalisation.TectonicRegionalisation ''' def setUp(self): ''' ''' self.tect_reg = None def test_basic_instantiation(self): ''' Test simple setup ''' # Test setup self.tect_reg = TectonicRegionalisation() self.assertDictEqual({'regionalisation': [], 'key_list': []}, self.tect_reg.__dict__) # Check number of regions is 0 self.assertEqual(0, self.tect_reg.get_number_regions()) def test_populate_region_accepting_defaults(self): ''' Tests the population of the tectonic regions with default values ''' region_dict = [{'Code': '001', 'Name': 'Active Shallow'}] expected_key_list = ['Active Shallow'] self.tect_reg = TectonicRegionalisation() self.tect_reg.populate_regions(region_dict) trg = self.tect_reg.regionalisation[0] self.assertEqual(trg.id, '001') self.assertEqual(trg.region_name, 'Active Shallow') self.assertAlmostEqual(trg.shear_modulus[0][0], 30.0) self.assertAlmostEqual(trg.shear_modulus[0][1], 1.0) self.assertAlmostEqual(trg.disp_length_ratio[0][0], 1.25E-5) self.assertAlmostEqual(trg.disp_length_ratio[0][1], 1.0) self.assertTrue(isinstance(trg.scaling_rel[0][0], WC1994)) self.assertAlmostEqual(trg.scaling_rel[0][1], 1.0) self.assertListEqual(expected_key_list, self.tect_reg.key_list) self.assertEqual(1, self.tect_reg.get_number_regions()) def test_poplate_region_with_inputs(self): ''' Tests the population of the tectonic regions with input values ''' region_dict = [{'Code': '001', 'Name': 'Active Shallow', 'Shear_Modulus': [(20., 0.3), (30., 0.7)], 'Displacement_Length_Ratio': [(1.5E-5, 1.0)], 'Magnitude_Scaling_Relation': [(WC1994, 1.0)]}, {'Code': '002', 'Name': 'Stable Continental', 'Shear_Modulus': [(30., 1.0)], 'Displacement_Length_Ratio': [(1.0E-4, 1.0)], 'Magnitude_Scaling_Relation': [(WC1994, 1.0)]} ] expected_key_list = ['Active Shallow', 'Stable Continental'] expected_regions = [{'id': '001', 'region_name': 'Active Shallow', 'shear_modulus': [(20., 0.3), (30., 0.7)], 'disp_length_ratio': [(1.5E-5, 1.0)], 'scaling_rel': [(WC1994, 1.0)]}, {'id': '002', 'region_name': 'Stable Continental', 'shear_modulus': [(30., 1.0)], 'disp_length_ratio': [(1.0E-4, 1.0)], 'scaling_rel': [(WC1994, 1.0)]}] self.tect_reg = TectonicRegionalisation() self.tect_reg.populate_regions(region_dict) for ival, test_reg in enumerate(self.tect_reg.regionalisation): self.assertDictEqual(expected_regions[ival], test_reg.__dict__) self.assertListEqual(expected_key_list, self.tect_reg.key_list) self.assertEqual(2, self.tect_reg.get_number_regions())