Esempio n. 1
0
 def test_create_oqhazardlib_complex_fault_source(self):
     """
     Tests the conversion of a point source to an instance of the :class:
     openquake.hazardlib.source.complex_fault.ComplexFaultSource
     """
     complex_edges = [
         line.Line([point.Point(11., 10., 0.),
                    point.Point(10., 10., 0.)]),
         line.Line(
             [point.Point(11.5, 10., 21.),
              point.Point(10.0, 10., 21.)])
     ]
     self.fault_source = mtkComplexFaultSource('001',
                                               'A Fault Source',
                                               trt='Active Shallow Crust',
                                               geometry=None,
                                               mag_scale_rel=None,
                                               rupt_aspect_ratio=1.0,
                                               mfd=models.TGRMFD(
                                                   a_val=3.,
                                                   b_val=1.0,
                                                   min_mag=5.0,
                                                   max_mag=8.0),
                                               rake=0.)
     self.fault_source.create_geometry(complex_edges, 2.0)
     test_source = self.fault_source.create_oqhazardlib_source(
         TOM, 5.0, True)
     self.assertIsInstance(test_source, ComplexFaultSource)
     self.assertIsInstance(test_source.mfd, TruncatedGRMFD)
     self.assertAlmostEqual(test_source.mfd.b_val, 1.0)
     self.assertIsInstance(test_source.magnitude_scaling_relationship,
                           WC1994)
Esempio n. 2
0
 def setUp(self):
     warnings.simplefilter("ignore")
     self.catalogue = Catalogue()
     self.fault_source = None
     self.trace_line = [line.Line([point.Point(1.0, 0.0, 1.0),
                                   point.Point(0.0, 1.0, 0.9)])]
     self.trace_line.append(line.Line([point.Point(1.2, 0.0, 40.),
                                       point.Point(1.0, 1.0, 45.),
                                       point.Point(0.0, 1.3, 42.)]))
     self.trace_array = [np.array([[1.0, 0.0, 1.0], [0.0, 1.0, 0.9]])]
     self.trace_array.append(np.array([[1.2, 0.0, 40.],
                                       [1.0, 1.0, 45.],
                                       [0.0, 1.3, 42.]]))
Esempio n. 3
0
    def test_create_oqnmrl_complex_fault_source(self):
        '''
        Tests the conversion of a point source to an instance of the :class:
        oqnrmllib.models.AreaSource 
        '''
        # Define a complete source
        complex_edges = [
            line.Line([point.Point(10., 10., 0.),
                       point.Point(11., 10., 0.)]),
            line.Line(
                [point.Point(10., 10., 20.),
                 point.Point(11.5, 10., 21.)])
        ]
        self.fault_source = mtkComplexFaultSource('001',
                                                  'A Fault Source',
                                                  trt='Active Shallow Crust',
                                                  geometry=None,
                                                  mag_scale_rel=None,
                                                  rupt_aspect_ratio=1.0,
                                                  mfd=models.TGRMFD(
                                                      a_val=3.,
                                                      b_val=1.0,
                                                      min_mag=5.0,
                                                      max_mag=8.0),
                                                  rake=0.)
        self.fault_source.create_geometry(complex_edges, 2.0)

        expected_geometry = models.ComplexFaultGeometry(
            top_edge_wkt='LINESTRING (10.0 10.0 0.0, 11.0 10.0 0.0)',
            bottom_edge_wkt='LINESTRING (10.0 10.0 20.0, 11.5 10.0 21.0)')

        expected_source = models.ComplexFaultSource('001',
                                                    'A Fault Source',
                                                    trt='Active Shallow Crust',
                                                    geometry=expected_geometry,
                                                    mag_scale_rel='WC1994',
                                                    rupt_aspect_ratio=1.0,
                                                    mfd=models.TGRMFD(
                                                        a_val=3.,
                                                        b_val=1.0,
                                                        min_mag=5.0,
                                                        max_mag=8.0),
                                                    rake=90.)

        test_source = self.fault_source.create_oqnrml_source(use_defaults=True)
        self.assertTrue(isinstance(test_source, models.ComplexFaultSource))
        self.assertEqual(test_source.id, expected_source.id)
        self.assertEqual(test_source.name, expected_source.name)
        self.assertAlmostEqual(test_source.mfd.b_val,
                               expected_source.mfd.b_val)
Esempio n. 4
0
 def test_create_oqhazardlib_source(self):
     # Tests to ensure the hazardlib source is created
     trace = line.Line([point.Point(10., 10.), point.Point(11., 10.)])
     mfd1 = TruncatedGRMFD(5.0, 8.0, 0.1, 3.0, 1.0)
     self.fault_source = mtkSimpleFaultSource(
         '001',
         'A Fault Source',
         trt='Active Shallow Crust',
         geometry=None,
         dip=90.,
         upper_depth=0.,
         lower_depth=20.,
         mag_scale_rel=None,
         rupt_aspect_ratio=1.0,
         mfd=mfd1,
         rake=0.)
     self.fault_source.create_geometry(trace, 90., 0., 20., 1.0)
     test_source = self.fault_source.create_oqhazardlib_source(TOM,
                                                               2.0,
                                                               True)
     self.assertIsInstance(test_source, SimpleFaultSource)
     self.assertIsInstance(test_source.mfd, TruncatedGRMFD)
     self.assertAlmostEqual(test_source.mfd.b_val, 1.0)
     self.assertIsInstance(test_source.magnitude_scaling_relationship,
                           WC1994)
Esempio n. 5
0
    def test_select_within_fault_distance(self):
        # Tests the selection of events within a distance from the fault
        # Set up catalouge
        self.catalogue = Catalogue()
        self.catalogue.data['longitude'] = np.arange(0., 5.5, 0.5)
        self.catalogue.data['latitude'] = np.arange(0., 5.5, 0.5)
        self.catalogue.data['depth'] = np.zeros(11, dtype=float)
        self.catalogue.data['eventID'] = np.arange(0, 11, 1)
        self.fault_source = mtkSimpleFaultSource('101', 'A simple fault')
        trace_as_line = line.Line([point.Point(2.0, 3.0),
                                   point.Point(3.0, 2.0)])
        self.fault_source.create_geometry(trace_as_line, 30., 0., 30.)
        selector0 = CatalogueSelector(self.catalogue)

        # Test 1 - simple case Joyner-Boore distance
        self.fault_source.select_catalogue(selector0, 40.)
        np.testing.assert_array_almost_equal(
            np.array([2., 2.5]),
            self.fault_source.catalogue.data['longitude'])
        np.testing.assert_array_almost_equal(
            np.array([2., 2.5]),
            self.fault_source.catalogue.data['latitude'])

        # Test 2 - simple case Rupture distance
        self.fault_source.catalogue = None
        self.fault_source.select_catalogue(selector0, 40., 'rupture')
        np.testing.assert_array_almost_equal(
            np.array([2.5]),
            self.fault_source.catalogue.data['longitude'])
        np.testing.assert_array_almost_equal(
            np.array([2.5]),
            self.fault_source.catalogue.data['latitude'])

        # Test 3 - for vertical fault ensure that Joyner-Boore distance
        # behaviour is the same as for rupture distance
        fault1 = mtkSimpleFaultSource('102', 'A vertical fault')
        fault1.create_geometry(trace_as_line, 90., 0., 30.)
        self.fault_source.create_geometry(trace_as_line, 90., 0., 30.)

        # Joyner-Boore
        self.fault_source.select_catalogue(selector0, 40.)
        # Rupture
        fault1.select_catalogue(selector0, 40., 'rupture')
        np.testing.assert_array_almost_equal(
            self.fault_source.catalogue.data['longitude'],
            fault1.catalogue.data['longitude'])
        np.testing.assert_array_almost_equal(
            self.fault_source.catalogue.data['latitude'],
            fault1.catalogue.data['latitude'])

        # The usual test to ensure error is raised when no events in catalogue
        self.catalogue = Catalogue()
        selector0 = CatalogueSelector(self.catalogue)
        with self.assertRaises(ValueError) as ver:
            self.fault_source.select_catalogue(selector0, 40.0)
        self.assertEqual(str(ver.exception),
                         'No events found in catalogue!')
Esempio n. 6
0
    def test_create_complex_geometry(self):
        '''
        Tests the complex geometry creation
        '''
        self.fault_source = mtkComplexFaultSource('101', 'A complex fault')
        # Test case when input as list of nhlib.geo.line.Line
        self.fault_source.create_geometry(self.trace_line, mesh_spacing=2.0)
        self.assertIsInstance(self.fault_source.geometry, ComplexFaultSurface)
        # Use the dip as a simple indicator of geometrical success!
        self.assertAlmostEqual(self.fault_source.dip, 40.5398531, 2)

        # Create a second instance
        fault2 = mtkComplexFaultSource('101', 'A complex fault')
        fault2.create_geometry(self.trace_array, mesh_spacing=2.0)
        self.assertIsInstance(fault2.geometry, ComplexFaultSurface)
        # Compare it to the first
        self.assertAlmostEqual(self.fault_source.dip, fault2.dip)

        # If less than two edges are input ensure error is raised
        bad_traces = [
            line.Line([point.Point(1.0, 0.0, 3.0),
                       point.Point(1.0, 0.0, 3.0)])
        ]

        self.fault_source = mtkComplexFaultSource('101', 'A complex fault')
        with self.assertRaises(ValueError) as ver:
            self.fault_source.create_geometry(bad_traces)
        self.assertEqual(ver.exception.message, 'Complex fault geometry '
                         'incorrectly defined')

        # If an edge is not defined from either a nhlib.geo.line.Line instance
        # or numpy.ndarray then ensure error is raised

        bad_traces = [
            line.Line([point.Point(1.0, 0.0, 3.0),
                       point.Point(1.0, 0.0, 3.0)])
        ]
        bad_traces.append('a bad input')

        self.fault_source = mtkComplexFaultSource('101', 'A complex fault')
        with self.assertRaises(ValueError) as ver:
            self.fault_source.create_geometry(bad_traces)
        self.assertEqual(ver.exception.message, 'Unrecognised or unsupported '
                         'geometry definition')
Esempio n. 7
0
    def test_create_oqnmrl_simple_fault_source(self):
        '''
        Tests the conversion of a point source to an instance of the :class:
        oqnrmllib.models.SimpleFaultSource 
        '''
        trace = line.Line([point.Point(10., 10.), point.Point(11., 10.)])
        #sflt_geom = SimpleFaultSurface.from_fault_data(trace, 0., 20., 90., 1.)

        # Define a complete source
        self.fault_source = mtkSimpleFaultSource('001',
                                                 'A Fault Source',
                                                 trt='Active Shallow Crust',
                                                 geometry=None,
                                                 dip=90.,
                                                 upper_depth=0.,
                                                 lower_depth=20.,
                                                 mag_scale_rel=None,
                                                 rupt_aspect_ratio=1.0,
                                                 mfd=models.TGRMFD(
                                                     a_val=3.,
                                                     b_val=1.0,
                                                     min_mag=5.0,
                                                     max_mag=8.0),
                                                 rake=0.)
        self.fault_source.create_geometry(trace, 90., 0., 20., 1.0)

        expected_geometry = models.SimpleFaultGeometry(
            wkt='LINESTRING (10.0 10.0, 11.0 10.0)',
            dip=90.,
            upper_seismo_depth=0.,
            lower_seismo_depth=20.)
        expected_source = models.SimpleFaultSource('001',
                                                   'A Fault Source',
                                                   trt='Active Shallow Crust',
                                                   geometry=expected_geometry,
                                                   mag_scale_rel='WC1994',
                                                   rupt_aspect_ratio=1.0,
                                                   mfd=models.TGRMFD(
                                                       a_val=3.,
                                                       b_val=1.0,
                                                       min_mag=5.0,
                                                       max_mag=8.0),
                                                   rake=0.)
        test_source = self.fault_source.create_oqnrml_source(use_defaults=True)
        self.assertTrue(isinstance(test_source, models.SimpleFaultSource))
        self.assertEqual(test_source.id, expected_source.id)
        self.assertEqual(test_source.name, expected_source.name)
        self.assertDictEqual(test_source.geometry.__dict__,
                             expected_source.geometry.__dict__)
        self.assertAlmostEqual(test_source.mfd.b_val,
                               expected_source.mfd.b_val)
    def test_create_fault_geometry(self):
        # Tests the creation of the fault geometry. Testing only behaviour
        # for creating SimpleFaultSurface classes - not the values in the
        # class (assumes nhlib implementation is correct)
        # Case 1 - trace input as instance of nhlib.geo.line.Line class
        self.fault_source = mtkSimpleFaultSource('101', 'A simple fault')
        trace_as_line = line.Line(
            [point.Point(2.0, 3.0),
             point.Point(3.0, 2.0)])
        self.fault_source.create_geometry(trace_as_line, 60., 0., 30.)
        self.assertIsInstance(self.fault_source.geometry, SimpleFaultSurface)

        # Case 2 - trace input as numpy array
        trace_as_array = np.array([[2.0, 3.0], [3.0, 2.0]])
        self.fault_source = mtkSimpleFaultSource('101', 'A simple fault')
        self.fault_source.create_geometry(trace_as_array, 60., 0., 30.)
        self.assertIsInstance(self.fault_source.geometry, SimpleFaultSurface)
        # Case 3 - raises error when something else is input
        with self.assertRaises(ValueError) as ver:
            self.fault_source.create_geometry('a bad input!', 60., 0., 30.)
        self.assertEqual(str(ver.exception),
                         'Unrecognised or unsupported geometry definition')