Esempio n. 1
0
 def test_bad_geometry_input(self):
     # Tests that an unknown geomtry error is raised when not recognised
     self.parser = FaultYmltoSource(BAD_GEOMETRY_FILE)
     with self.assertRaises(ValueError) as ae:
         self.parser.read_file()
     self.assertEqual(str(ae.exception),
                      'Unrecognised or unsupported fault geometry!')
Esempio n. 2
0
 def test_bad_input_fault_model(self):
     # Test that when Yaml is missing 'Fault_Model' atribute an error is
     # raised
     with self.assertRaises(ValueError) as ae:
         self.parser = FaultYmltoSource(BAD_INPUT_FILE)
     self.assertEqual(str(ae.exception),
                      'Fault Model not defined in input file!')
Esempio n. 3
0
class TestFaultYamlParser(unittest.TestCase):
    '''
    Main test class of the Fault Yaml Parser function
    '''

    def setUp(self):
        self.parser = None
        self.fault_geometry = None

    def test_bad_input_fault_model(self):
        # Test that when Yaml is missing 'Fault_Model' atribute an error is
        # raised
        with self.assertRaises(ValueError) as ae:
            self.parser = FaultYmltoSource(BAD_INPUT_FILE)
        self.assertEqual(str(ae.exception),
                         'Fault Model not defined in input file!')

    def test_bad_geometry_input(self):
        # Tests that an unknown geomtry error is raised when not recognised
        self.parser = FaultYmltoSource(BAD_GEOMETRY_FILE)
        with self.assertRaises(ValueError) as ae:
            self.parser.read_file()
        self.assertEqual(str(ae.exception),
                         'Unrecognised or unsupported fault geometry!')

    def test_simple_fault_input(self):
        # Tests a simple fault input
        self.parser = FaultYmltoSource(SIMPLE_GEOMETRY_FILE)
        fault_model, tect_reg = self.parser.read_file()
        # Test that the area is correct and the slip rate
        self.assertAlmostEqual(fault_model.faults[0].area,
                               3851.9052498454062)
        expected_slip = [(18.0, 0.3), (20.0, 0.5), (23.0, 0.2)]
        for iloc, slip in enumerate(expected_slip):
            self.assertAlmostEqual(
                slip[0], fault_model.faults[0].slip[iloc][0])
            self.assertAlmostEqual(
                slip[1], fault_model.faults[0].slip[iloc][1])

        self.assertTrue(isinstance(fault_model.faults[0].geometry,
                                   SimpleFaultGeometry))

    def test_complex_fault_input(self):
        # Tests a complex fault input
        # Quick test - just ensure that the area and the slip rate are expected
        self.parser = FaultYmltoSource(COMPLEX_GEOMETRY_FILE)
        fault_model, tect_reg = self.parser.read_file(2.0)
        # Test that the area is correct and the slip rate
        self.assertAlmostEqual(fault_model.faults[0].area,
                               13745.614848626545)
        expected_slip = [(18.0, 0.3), (20.0, 0.5), (23.0, 0.2)]
        for iloc, slip in enumerate(expected_slip):
            self.assertAlmostEqual(
                slip[0], fault_model.faults[0].slip[iloc][0])
            self.assertAlmostEqual(
                slip[1], fault_model.faults[0].slip[iloc][1])

        self.assertTrue(isinstance(fault_model.faults[0].geometry,
                                   ComplexFaultGeometry))
Esempio n. 4
0
class TestFaultYamlParser(unittest.TestCase):
    '''
    Main test class of the Fault Yaml Parser function
    '''
    def setUp(self):
        self.parser = None
        self.fault_geometry = None

    def test_bad_input_fault_model(self):
        # Test that when Yaml is missing 'Fault_Model' atribute an error is
        # raised
        with self.assertRaises(ValueError) as ae:
            self.parser = FaultYmltoSource(BAD_INPUT_FILE)
        self.assertEqual(str(ae.exception),
                         'Fault Model not defined in input file!')

    def test_bad_geometry_input(self):
        # Tests that an unknown geomtry error is raised when not recognised
        self.parser = FaultYmltoSource(BAD_GEOMETRY_FILE)
        with self.assertRaises(ValueError) as ae:
            self.parser.read_file()
        self.assertEqual(str(ae.exception),
                         'Unrecognised or unsupported fault geometry!')

    def test_simple_fault_input(self):
        # Tests a simple fault input
        self.parser = FaultYmltoSource(SIMPLE_GEOMETRY_FILE)
        fault_model, tect_reg = self.parser.read_file()
        # Test that the area is correct and the slip rate
        self.assertAlmostEqual(fault_model.faults[0].area,
                               3851.9052498454062)
        expected_slip = [(18.0, 0.3), (20.0, 0.5), (23.0, 0.2)]
        for iloc, slip in enumerate(expected_slip):
            self.assertAlmostEqual(
                slip[0], fault_model.faults[0].slip[iloc][0])
            self.assertAlmostEqual(
                slip[1], fault_model.faults[0].slip[iloc][1])

        self.assertTrue(isinstance(fault_model.faults[0].geometry,
                                   SimpleFaultGeometry))

    def test_complex_fault_input(self):
        # Tests a complex fault input
        # Quick test - just ensure that the area and the slip rate are expected
        self.parser = FaultYmltoSource(COMPLEX_GEOMETRY_FILE)
        fault_model, tect_reg = self.parser.read_file(2.0)
        # Test that the area is correct and the slip rate
        self.assertAlmostEqual(fault_model.faults[0].area,
                               13745.614848626545)
        expected_slip = [(18.0, 0.3), (20.0, 0.5), (23.0, 0.2)]
        for iloc, slip in enumerate(expected_slip):
            self.assertAlmostEqual(
                slip[0], fault_model.faults[0].slip[iloc][0])
            self.assertAlmostEqual(
                slip[1], fault_model.faults[0].slip[iloc][1])

        self.assertTrue(isinstance(fault_model.faults[0].geometry,
                                   ComplexFaultGeometry))
Esempio n. 5
0
    def test_simple_fault_input(self):
        # Tests a simple fault input
        self.parser = FaultYmltoSource(SIMPLE_GEOMETRY_FILE)
        fault_model, tect_reg = self.parser.read_file()
        # Test that the area is correct and the slip rate
        self.assertAlmostEqual(fault_model.faults[0].area, 3851.9052498454062)
        expected_slip = [(18.0, 0.3), (20.0, 0.5), (23.0, 0.2)]
        for iloc, slip in enumerate(expected_slip):
            self.assertAlmostEqual(slip[0],
                                   fault_model.faults[0].slip[iloc][0])
            self.assertAlmostEqual(slip[1],
                                   fault_model.faults[0].slip[iloc][1])

        self.assertTrue(
            isinstance(fault_model.faults[0].geometry, SimpleFaultGeometry))
Esempio n. 6
0
 def test_bad_geometry_input(self):
     # Tests that an unknown geomtry error is raised when not recognised
     self.parser = FaultYmltoSource(BAD_GEOMETRY_FILE)
     with self.assertRaises(ValueError) as ae:
         self.parser.read_file()
     self.assertEqual(str(ae.exception),
                      'Unrecognised or unsupported fault geometry!')
Esempio n. 7
0
 def test_bad_input_fault_model(self):
     # Test that when Yaml is missing 'Fault_Model' atribute an error is
     # raised
     with self.assertRaises(ValueError) as ae:
         self.parser = FaultYmltoSource(BAD_INPUT_FILE)
     self.assertEqual(str(ae.exception),
                      'Fault Model not defined in input file!')
Esempio n. 8
0
    def test_complex_fault_input(self):
        # Tests a complex fault input
        # Quick test - just ensure that the area and the slip rate are expected
        self.parser = FaultYmltoSource(COMPLEX_GEOMETRY_FILE)
        fault_model, tect_reg = self.parser.read_file(2.0)
        # Test that the area is correct and the slip rate
        self.assertAlmostEqual(fault_model.faults[0].area, 13745.614848626545)
        expected_slip = [(18.0, 0.3), (20.0, 0.5), (23.0, 0.2)]
        for iloc, slip in enumerate(expected_slip):
            self.assertAlmostEqual(slip[0],
                                   fault_model.faults[0].slip[iloc][0])
            self.assertAlmostEqual(slip[1],
                                   fault_model.faults[0].slip[iloc][1])

        self.assertTrue(
            isinstance(fault_model.faults[0].geometry, ComplexFaultGeometry))
 def test_collapse_fault_model(self):
     input_file = os.path.join(
         BASE_DATA_PATH, "collapse_test_simple_fault_example_4branch.yml")
     mesh_spacing = 1.0
     reader = FaultYmltoSource(input_file)
     fault_model, tectonic_region = reader.read_file(mesh_spacing)
     fault_model.build_fault_model(collapse=True,
                                   bin_width=0.05,
                                   rendered_msr=WC1994())
     expected_mfd = self.src.incrementalMFD
     model_mfd = fault_model.faults[0].mfd[0][0]
     self.assertAlmostEqual(expected_mfd["binWidth"], model_mfd.bin_width,
                            7)
     self.assertAlmostEqual(expected_mfd["minMag"], model_mfd.min_mag, 7)
     expected_rates = np.array(expected_mfd.occurRates.text)
     np.testing.assert_array_almost_equal(model_mfd.occur_rates,
                                          expected_rates, 7)
Esempio n. 10
0
    def test_simple_fault_input(self):
        # Tests a simple fault input
        self.parser = FaultYmltoSource(SIMPLE_GEOMETRY_FILE)
        fault_model, tect_reg = self.parser.read_file()
        # Test that the area is correct and the slip rate
        self.assertAlmostEqual(fault_model.faults[0].area,
                               3851.9052498454062)
        expected_slip = [(18.0, 0.3), (20.0, 0.5), (23.0, 0.2)]
        for iloc, slip in enumerate(expected_slip):
            self.assertAlmostEqual(
                slip[0], fault_model.faults[0].slip[iloc][0])
            self.assertAlmostEqual(
                slip[1], fault_model.faults[0].slip[iloc][1])

        self.assertTrue(isinstance(fault_model.faults[0].geometry,
                                   SimpleFaultGeometry))
Esempio n. 11
0
    def test_complex_fault_input(self):
        # Tests a complex fault input
        # Quick test - just ensure that the area and the slip rate are expected
        self.parser = FaultYmltoSource(COMPLEX_GEOMETRY_FILE)
        fault_model, tect_reg = self.parser.read_file(2.0)
        # Test that the area is correct and the slip rate
        self.assertAlmostEqual(fault_model.faults[0].area,
                               13745.614848626545)
        expected_slip = [(18.0, 0.3), (20.0, 0.5), (23.0, 0.2)]
        for iloc, slip in enumerate(expected_slip):
            self.assertAlmostEqual(
                slip[0], fault_model.faults[0].slip[iloc][0])
            self.assertAlmostEqual(
                slip[1], fault_model.faults[0].slip[iloc][1])

        self.assertTrue(isinstance(fault_model.faults[0].geometry,
                                   ComplexFaultGeometry))