Пример #1
0
 def test_bounding_box(self):
     surf = MultiSurface(self.surfaces_mesh2D)
     west, east, north, south = surf.get_bounding_box()
     self.assertEqual(0.1, west)
     self.assertEqual(4.6, east)
     self.assertEqual(5.6, north)
     self.assertEqual(1.1, south)
Пример #2
0
 def test_bounding_box(self):
     surf = MultiSurface(self.surfaces_mesh2D)
     west, east, north, south = surf.get_bounding_box()
     self.assertEqual(0.1, west)
     self.assertEqual(4.6, east)
     self.assertEqual(5.6, north)
     self.assertEqual(1.1, south)
Пример #3
0
    def get_rupture_enclosing_polygon(self, dilation=0):
        """
        Create instance of
        :class:`openquake.hazardlib.geo.surface.multi.MultiSurface` from all
        ruptures' surfaces and compute its bounding box. Calculate convex hull
        of bounding box, and return it dilated by ``dilation``.

        :param dilation:
            A buffer distance in km to extend the polygon borders to.
        :returns:
            Instance of :class:`openquake.hazardlib.geo.polygon.Polygon`.
        """
        surfaces = []
        for rup, _ in self.data:
            if isinstance(rup.surface, MultiSurface):
                for s in rup.surface.surfaces:
                    surfaces.append(s)
            else:
                surfaces.append(rup.surface)
        multi_surf = MultiSurface(surfaces)

        west, east, north, south = multi_surf.get_bounding_box()
        mesh = RectangularMesh(numpy.array([[west, east], [west, east]]),
                               numpy.array([[north, north], [south, south]]),
                               None)
        poly = mesh.get_convex_hull()

        return poly if dilation == 0 else poly.dilate(dilation)
Пример #4
0
 def get_bounding_box(self, maxdist):
     """
     Bounding box containing all surfaces, enlarged by the maximum distance
     """
     surfaces = []
     for rup, _ in self.data:
         if isinstance(rup.surface, MultiSurface):
             for s in rup.surface.surfaces:
                 surfaces.append(s)
         else:
             surfaces.append(rup.surface)
     multi_surf = MultiSurface(surfaces)
     west, east, north, south = multi_surf.get_bounding_box()
     a1 = maxdist * KM_TO_DEGREES
     a2 = angular_distance(maxdist, north, south)
     return west - a2, south - a1, east + a2, north + a1
Пример #5
0
 def get_bounding_box(self, maxdist):
     """
     Bounding box containing all surfaces, enlarged by the maximum distance
     """
     surfaces = []
     for rup, _ in self.data:
         if isinstance(rup.surface, MultiSurface):
             for s in rup.surface.surfaces:
                 surfaces.append(s)
         else:
             surfaces.append(rup.surface)
     multi_surf = MultiSurface(surfaces)
     west, east, north, south = multi_surf.get_bounding_box()
     a1 = maxdist * KM_TO_DEGREES
     a2 = angular_distance(maxdist, north, south)
     return west - a2, south - a1, east + a2, north + a1
Пример #6
0
    def get_rupture_enclosing_polygon(self, dilation=0):
        """
        Create instance of
        :class:`openquake.hazardlib.geo.surface.multi.MultiSurface` from all
        ruptures' surfaces and compute its bounding box. Calculate convex hull
        of bounding box, and return it dilated by ``dilation``.

        :param dilation:
            A buffer distance in km to extend the polygon borders to.
        :returns:
            Instance of :class:`openquake.hazardlib.geo.polygon.Polygon`.
        """
        surfaces = [rup.surface for (rup, _) in self.data]
        multi_surf = MultiSurface(surfaces)

        west, east, north, south = multi_surf.get_bounding_box()
        mesh = RectangularMesh(numpy.array([[west, east], [west, east]]),
                               numpy.array([[north, north], [south, south]]),
                               None)
        poly = mesh.get_convex_hull()

        return poly if dilation == 0 else poly.dilate(dilation)
Пример #7
0
class MultiSurfaceWithNaNsTestCase(unittest.TestCase):

    NAME = 'MultiSurfaceWithNaNsTestCase'

    def setUp(self):
        path = os.path.join(BASE_DATA_PATH, 'profiles08')

        hsmpl = 2
        vsmpl = 2
        idl = False
        alg = False

        # Read the profiles with prefix cs_50. These profiles dip toward
        # north
        prf, _ = _read_profiles(path, 'cs_50')
        srfc50 = KiteSurface.from_profiles(prf, vsmpl, hsmpl, idl, alg)

        # Read the profiles with prefix cs_52. These profiles dip toward
        # north. This section is west to the section defined by cs_50
        prf, _ = _read_profiles(path, 'cs_51')
        srfc51 = KiteSurface.from_profiles(prf, vsmpl, hsmpl, idl, alg)

        clo = []
        cla = []
        step = 0.01
        for lo in np.arange(-71.8, -69, step):
            tlo = []
            tla = []
            for la in np.arange(19.25, 20.25, step):
                tlo.append(lo)
                tla.append(la)
            clo.append(tlo)
            cla.append(tla)
        self.clo = np.array(clo)
        self.cla = np.array(cla)
        mesh = Mesh(lons=self.clo.flatten(), lats=self.cla.flatten())

        # Define multisurface and mesh of sites
        self.srfc50 = srfc50
        self.srfc51 = srfc51

        self.msrf = MultiSurface([srfc50, srfc51])
        self.mesh = mesh

        self.los = [
            self.msrf.surfaces[0].mesh.lons, self.msrf.surfaces[1].mesh.lons
        ]
        self.las = [
            self.msrf.surfaces[0].mesh.lats, self.msrf.surfaces[1].mesh.lats
        ]

    def test_get_edge_set(self):

        # The vertexes of the expected edges are the first and last vertexes of
        # the topmost row of the mesh
        expected = [
            np.array([[-70.33, 19.65, 0.], [-70.57722702, 19.6697801, 0.0]]),
            np.array([[-70.10327766, 19.67957463, 0.0], [-70.33, 19.65, 0.0]])
        ]

        if PLOTTING:
            _, ax = plt.subplots(1, 1)
            for sfc in self.msrf.surfaces:
                col = np.random.rand(3)
                mesh = sfc.mesh
                ax.plot(mesh.lons, mesh.lats, '.', color=col)
                ax.plot(mesh.lons[0, :], mesh.lats[0, :], lw=3)
            for edge in self.msrf.edge_set:
                ax.plot(edge[:, 0], edge[:, 1], 'x-r')
            plt.show()

        # Note that method is executed when the object is initialized
        ess = self.msrf.edge_set
        for es, expct in zip(ess, expected):
            np.testing.assert_array_almost_equal(es, expct, decimal=2)

    def test_get_strike(self):
        # Since the two surfaces dip to the north, we expect the strike to
        # point toward W
        msg = 'Multi fault surface: strike is wrong'
        strike = self.msrf.get_strike()
        self.assertAlmostEqual(268.867, strike, places=2, msg=msg)

    def test_get_dip(self):
        dip = self.msrf.get_dip()
        expected = 69.649
        msg = 'Multi fault surface: dip is wrong'
        aae(dip, expected, err_msg=msg, decimal=2)

    def test_get_width(self):
        """ check the width """
        # Measuring the width
        width = self.msrf.get_width()
        np.testing.assert_allclose(width, 20.44854)

    def test_get_area(self):
        # The area is computed by summing the areas of each section.
        a1 = self.msrf.surfaces[0].get_area()
        a2 = self.msrf.surfaces[1].get_area()
        area = self.msrf.get_area()
        aae(a1 + a2, area)

    def test_get_bounding_box(self):
        bb = self.msrf.get_bounding_box()

        if PLOTTING:
            _, ax = plt.subplots(1, 1)
            ax.plot([bb.west, bb.east, bb.east, bb.west],
                    [bb.south, bb.south, bb.north, bb.north], '-')
            ax.plot(self.los[0], self.las[0], '.')
            ax.plot(self.los[1], self.las[1], '.')
            plt.show()

        aae([bb.west, bb.east, bb.south, bb.north],
            [-70.5772, -70.1032, 19.650, 19.7405],
            decimal=2)

    def test_get_middle_point(self):
        # The computed middle point is the mid point of the first surface
        midp = self.msrf.get_middle_point()
        expected = [-70.453372, 19.695377, 10.2703]
        computed = [midp.longitude, midp.latitude, midp.depth]
        aae(expected, computed, decimal=4)

    def test_get_surface_boundaries01(self):
        # This checks the boundary of the first surface. The result is checked
        # visually
        blo, bla = self.srfc50.get_surface_boundaries()

        # Saving data
        fname = os.path.join(BASE_PATH, 'results', 'results_t01.npz')
        if OVERWRITE:
            np.savez_compressed(fname, blo=blo, bla=bla)

        # Load expected results
        er = np.load(fname)

        if PLOTTING:
            _, ax = plt.subplots(1, 1)
            ax.plot(er['blo'], er['bla'], '-r')
            plt.show()

        # Testing
        aae(er['blo'], blo, decimal=1)
        aae(er['bla'], bla, decimal=1)

    @unittest.skip("skipping due to differences betweeen various architectures"
                   )
    def test_get_surface_boundaries(self):
        # The result is checked visually
        blo, bla = self.msrf.get_surface_boundaries()

        # Saving data
        fname = os.path.join(BASE_PATH, 'results', 'results_t02.npz')
        if OVERWRITE:
            np.savez_compressed(fname, blo=blo, bla=bla)

        # Load expected results
        er = np.load(fname)

        if PLOTTING:
            _, ax = plt.subplots(1, 1)
            ax.plot(blo, bla, '-r')
            ax.plot(self.los[0], self.las[0], '.')
            ax.plot(self.los[1], self.las[1], '.')
            plt.show()

        # Testing
        aae(er['blo'], blo, decimal=2)
        aae(er['bla'], bla, decimal=2)

    def test_get_rx(self):
        # Results visually inspected
        dst = self.msrf.get_rx_distance(self.mesh)

        if PLOTTING:
            title = f'{self.NAME} - Rx'
            _plt_results(self.clo, self.cla, dst, self.msrf, title)

    def test_get_ry0(self):
        # Results visually inspected
        dst = self.msrf.get_ry0_distance(self.mesh)

        if PLOTTING:
            title = f'{self.NAME} - Rx'
            _plt_results(self.clo, self.cla, dst, self.msrf, title)
Пример #8
0
class MultiSurfaceWithNaNsTestCase(unittest.TestCase):

    def setUp(self):
        path = os.path.join(BASE_DATA_PATH, 'profiles08')

        hsmpl = 5
        vsmpl = 5
        idl = False
        alg = False

        prf, _ = _read_profiles(path, 'cs_50')
        srfc50 = KiteSurface.from_profiles(prf, vsmpl, hsmpl, idl, alg)

        prf, _ = _read_profiles(path, 'cs_51')
        srfc51 = KiteSurface.from_profiles(prf, vsmpl, hsmpl, idl, alg)

        coo = []
        step = 0.5
        for lo in np.arange(-74, -68, step):
            for la in np.arange(17, 20, step):
                coo.append([lo, la])
        coo = np.array(coo)
        mesh = Mesh(coo[:, 0], coo[:, 1])
        # Define multisurface and mesh of sites
        self.msrf = MultiSurface([srfc50, srfc51])
        self.mesh = mesh

    def test_get_edge_set(self):
        expected = [np.array([[-70.33338023, 19.7128312, 18.75134376],
                              [-70.38083767, 19.71732142, 18.7242976],
                              [-70.42829775, 19.72179906, 18.69725144],
                              [-70.47576048, 19.72626415, 18.67020527],
                              [-70.52322584, 19.73071666, 18.64315911],
                              [-70.57069383, 19.7351566, 18.61611295]]),
                    np.array([[-70.14923984, 19.73051498, 18.96965629],
                              [-70.19675982, 19.72669428, 18.88126907],
                              [-70.24427754, 19.72286097, 18.79288186],
                              [-70.29179300, 19.71901507, 18.70449464],
                              [-70.33930617, 19.71515658, 18.61610742]])]

        # Note that method is executed when the object is initialized
        ess = self.msrf.edge_set
        for es, expct in zip(ess, expected):
            np.testing.assert_array_almost_equal(es, expct)

    # TODO
    def test_get_cartesian_edge_set(self):
        es = self.msrf._get_cartesian_edge_set()

    # TODO
    def test_get_strike(self):
        strike = self.msrf.get_strike()

    # TODO
    def test_get_dip(self):
        dip = self.msrf.get_dip()
        expected = 69.57436082462769
        msg = 'Multi fault surface: dip is wrong'
        aae(dip, expected, err_msg=msg)

    # TODO
    def test_get_width(self):
        width = self.msrf.get_width()
        print(width)

    # TODO
    def test_get_area(self):
        area = self.msrf.get_area()

    # TODO
    def test_get_bounding_box(self):
        bb = self.msrf.get_bounding_box()

    # TODO
    def test_get_middle_point(self):
        midp = self.msrf.get_middle_point()

    # TODO remove NaNs
    def test_get_surface_boundaries(self):
        bnd = self.msrf.get_surface_boundaries()

    # TODO test the updated attributes
    def test_setup_gc2_framework(self):
        gc2f = self.msrf._setup_gc2_framework()

    # TODO
    def test_get_gc2_coordinates_for_rupture(self):
        es = self.msrf._get_cartesian_edge_set()
        gc2c = self.msrf._get_gc2_coordinates_for_rupture(es)

    # TODO
    def test_get_generalised_coordinates(self):
        gcoo = self.msrf.get_generalised_coordinates(self.mesh.lons,
                                                     self.mesh.lats)

    # TODO fix the error
    def test_get_rx(self):
        dsts = self.msrf.get_rx_distance(self.mesh)

    # TODO fix the error
    def test_get_ry0(self):
        dsts = self.msrf.get_ry0_distance(self.mesh)
Пример #9
0
class MultiSurfaceWithNaNsTestCase(unittest.TestCase):
    def setUp(self):
        path = os.path.join(BASE_DATA_PATH, 'profiles08')

        hsmpl = 5
        vsmpl = 5
        idl = False
        alg = False

        prf, _ = _read_profiles(path, 'cs_50')
        srfc50 = KiteSurface.from_profiles(prf, vsmpl, hsmpl, idl, alg)

        prf, _ = _read_profiles(path, 'cs_51')
        srfc51 = KiteSurface.from_profiles(prf, vsmpl, hsmpl, idl, alg)

        coo = []
        step = 0.5
        for lo in np.arange(-74, -68, step):
            for la in np.arange(17, 20, step):
                coo.append([lo, la])
        coo = np.array(coo)
        mesh = Mesh(coo[:, 0], coo[:, 1])
        # Define multisurface and mesh of sites
        self.msrf = MultiSurface([srfc50, srfc51])
        self.mesh = mesh

    def test_get_edge_set(self):

        expected = [
            np.array([[-70.33365959, 19.71037733, 18.85108915],
                      [-70.38106033, 19.71535823, 18.804094],
                      [-70.42846401, 19.72032659, 18.75709885],
                      [-70.47587061, 19.72528241, 18.7101037],
                      [-70.52328014, 19.73022569, 18.66310854],
                      [-70.57069257, 19.73515644, 18.61611339]]),
            np.array([[-70.14910201, 19.7287277, 19.03202724],
                      [-70.19665637, 19.7253538, 18.9280474],
                      [-70.24420873, 19.72196728, 18.82406756],
                      [-70.29175909, 19.71856815, 18.72008771],
                      [-70.33930743, 19.71515642, 18.61610787]])
        ]

        # Note that method is executed when the object is initialized
        ess = self.msrf.edge_set
        for es, expct in zip(ess, expected):
            np.testing.assert_array_almost_equal(es, expct, decimal=2)

    # TODO
    def test_get_cartesian_edge_set(self):
        es = self.msrf._get_cartesian_edge_set()

    # TODO
    def test_get_strike(self):
        strike = self.msrf.get_strike()

    def test_get_dip(self):
        dip = self.msrf.get_dip()
        expected = 69.93
        msg = 'Multi fault surface: dip is wrong'
        aae(dip, expected, err_msg=msg, decimal=2)

    # TODO
    def test_get_width(self):
        width = self.msrf.get_width()

    # TODO
    def test_get_area(self):
        area = self.msrf.get_area()

    # TODO
    def test_get_bounding_box(self):
        bb = self.msrf.get_bounding_box()

    # TODO
    def test_get_middle_point(self):
        midp = self.msrf.get_middle_point()

    # TODO remove NaNs
    def test_get_surface_boundaries(self):
        bnd = self.msrf.get_surface_boundaries()

    # TODO test the updated attributes
    def test_setup_gc2_framework(self):
        gc2f = self.msrf._setup_gc2_framework()

    # TODO
    def test_get_gc2_coordinates_for_rupture(self):
        es = self.msrf._get_cartesian_edge_set()
        gc2c = self.msrf._get_gc2_coordinates_for_rupture(es)

    # TODO
    def test_get_generalised_coordinates(self):
        gcoo = self.msrf.get_generalised_coordinates(self.mesh.lons,
                                                     self.mesh.lats)

    # TODO fix the error
    def test_get_rx(self):
        dsts = self.msrf.get_rx_distance(self.mesh)

    # TODO fix the error
    def test_get_ry0(self):
        dsts = self.msrf.get_ry0_distance(self.mesh)