예제 #1
0
class MultiSurfaceOneTestCase(unittest.TestCase):
    def setUp(self):
        # First surface - Almost vertical dipping to south
        prf1 = Line([Point(0, 0, 0), Point(0, -0.00001, 20.)])
        prf2 = Line([Point(0.15, 0, 0), Point(0.15, -0.00001, 20.)])
        prf3 = Line([Point(0.3, 0, 0), Point(0.3, -0.00001, 20.)])
        sfca = KiteSurface.from_profiles([prf1, prf2, prf3], 1., 1.)
        self.msrf = MultiSurface([sfca])

    def test_get_width(self):
        # Surface is almost vertical. The width must be equal to the depth
        # difference between the points at the top and bottom
        width = self.msrf.get_width()
        msg = 'Multi fault surface: width is wrong'
        self.assertAlmostEqual(20.0, width, places=2, msg=msg)

    def test_get_dip(self):
        # Surface is almost vertical. The dip must be equal to 90
        dip = self.msrf.get_dip()
        msg = 'Multi fault surface: dip is wrong'
        self.assertAlmostEqual(90.0, dip, places=2, msg=msg)

    def test_get_area(self):
        computed = self.msrf.get_area()
        length = geodetic_distance(0.0, 0.0, 0.3, 0.0)
        expected = length * 20.0
        perc_diff = abs(computed - expected) / computed * 100
        msg = 'Multi fault surface: area is wrong'
        self.assertTrue(perc_diff < 2, msg=msg)

    def test_get_area1(self):
        pntsa = npoints_towards(lon=0.32,
                                lat=0.0,
                                depth=0.0,
                                azimuth=45,
                                hdist=10.0,
                                vdist=0.0,
                                npoints=2)
        pntsb = npoints_towards(lon=pntsa[0][1],
                                lat=pntsa[1][1],
                                depth=pntsa[2][1],
                                azimuth=45 + 90,
                                hdist=10.0,
                                vdist=10.0,
                                npoints=2)
        pntsc = npoints_towards(lon=0.32,
                                lat=0.0,
                                depth=0.0,
                                azimuth=45 + 90,
                                hdist=10.0,
                                vdist=10.0,
                                npoints=2)
        tmp = Point(pntsc[0][1], pntsc[1][1], pntsc[2][1])
        prf3 = Line([Point(0.32, 0, 0), tmp])
        tmp1 = Point(pntsa[0][1], pntsa[1][1], pntsa[2][1])
        tmp2 = Point(pntsb[0][1], pntsb[1][1], pntsb[2][1])
        prf4 = Line([tmp1, tmp2])
        sfcb = KiteSurface.from_profiles([prf3, prf4], 0.2, 0.2)

        computed = sfcb.get_area()
        expected = 10.0 * 14.14
        msg = 'Multi fault surface: area is wrong'
        aae(expected, computed, decimal=-1, err_msg=msg)
예제 #2
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)
예제 #3
0
 def test_get_dip(self):
     surf = MultiSurface(self.surfaces_mesh2D)
     self.assertAlmostEqual(53.33333333, surf.get_dip())
예제 #4
0
 def test_get_dip(self):
     surf = MultiSurface(self.surfaces_mesh2D)
     self.assertAlmostEqual(53.33333333, surf.get_dip())
예제 #5
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)
예제 #6
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)