예제 #1
0
    def test_rx(self):
        mesh = Mesh(numpy.array([-118.]), numpy.array([33]))   # 1 point
        surf18 = MultiSurface.from_csv(cd / 'msurface18.csv')  # 2 planes
        surf19 = MultiSurface.from_csv(cd / 'msurface19.csv')  # 2 planes
        surf20 = MultiSurface.from_csv(cd / 'msurface20.csv')  # 1 plane
        rx18 = surf18.get_rx_distance(mesh)[0]
        rx19 = surf19.get_rx_distance(mesh)[0]
        rx20 = surf20.get_rx_distance(mesh)[0]
        aac([rx18, rx19, rx20], [51.610675, 54.441119, -60.205692])

        surfa = MultiSurface(surf18.surfaces + surf19.surfaces)
        surfb = MultiSurface(surf19.surfaces + surf20.surfaces)
        rxa = surfa.get_rx_distance(mesh)[0]
        rxb = surfb.get_rx_distance(mesh)[0]
        aac([rxa, rxb], [53.034889, -56.064366])
예제 #2
0
class ConcordantSurfaceTestCase(unittest.TestCase):
    """
    Tests the verification of the GC2 module for the Concordant Test case
    """
    def setUp(self):
        self.data = numpy.genfromtxt(CONCORDANT_FILE, delimiter=",")
        self.mesh = Mesh(self.data[:, 0], self.data[:, 1], self.data[:, 2])
        self.model = MultiSurface(FRANK1.surfaces)

    def test_gc2_coords(self):
        """
        Verifies the GC2U, GC2T coordinate for the concordant case
        """
        expected_t = self.data[:, 3]
        expected_u = self.data[:, 4]
        gc2t, gc2u = self.model.get_generalised_coordinates(
            self.mesh.lons, self.mesh.lats)
        numpy.testing.assert_array_almost_equal(expected_t, gc2t)
        numpy.testing.assert_array_almost_equal(expected_u, gc2u)

    def test_gc2_rx(self):
        """
        Verifies Rx for the concordant case
        """
        expected_rx = self.data[:, 5]
        r_x = self.model.get_rx_distance(self.mesh)
        numpy.testing.assert_array_almost_equal(expected_rx, r_x)

    def test_gc2_ry0(self):
        """
        Verifies Ry0 for the concordant case
        """
        expected_ry0 = self.data[:, 6]
        ry0 = self.model.get_ry0_distance(self.mesh)
        numpy.testing.assert_array_almost_equal(expected_ry0, ry0)
예제 #3
0
class ConcordantSurfaceTestCase(unittest.TestCase):
    """
    Tests the verification of the GC2 module for the Concordant Test case
    """
    def setUp(self):
        self.data = numpy.genfromtxt(CONCORDANT_FILE, delimiter=",")
        self.mesh = Mesh(self.data[:, 0], self.data[:, 1], self.data[:, 2])
        self.model = MultiSurface(FRANK1.surfaces)

    def test_gc2_coords(self):
        """
        Verifies the GC2U, GC2T coordinate for the concordant case
        """
        expected_t = self.data[:, 3]
        expected_u = self.data[:, 4]
        gc2t, gc2u = self.model.get_generalised_coordinates(self.mesh.lons,
                                                            self.mesh.lats)
        numpy.testing.assert_array_almost_equal(expected_t, gc2t)
        numpy.testing.assert_array_almost_equal(expected_u, gc2u)

    def test_gc2_rx(self):
        """
        Verifies Rx for the concordant case
        """
        expected_rx = self.data[:, 5]
        r_x = self.model.get_rx_distance(self.mesh)
        numpy.testing.assert_array_almost_equal(expected_rx, r_x)

    def test_gc2_ry0(self):
        """
        Verifies Ry0 for the concordant case
        """
        expected_ry0 = self.data[:, 6]
        ry0 = self.model.get_ry0_distance(self.mesh)
        numpy.testing.assert_array_almost_equal(expected_ry0, ry0)
예제 #4
0
class MultiSurfaceTestCase(unittest.TestCase):

    def setUp(self):

        # First surface
        prf1 = Line([Point(0, 0, 0), Point(0, -0.001, 20.)])
        prf2 = Line([Point(0.15, 0, 0), Point(0.15, -0.001, 20.)])
        prf3 = Line([Point(0.3, 0, 0), Point(0.3, -0.001, 20.)])
        sfcA = KiteSurface.from_profiles([prf1, prf2, prf3], 5., 5.)

        # Second surface
        prf3 = Line([Point(0.32, 0, 0), Point(0.32, 0.001, 20.)])
        prf4 = Line([Point(0.45, 0.15, 0), Point(0.45, 0.1501, 20.)])
        sfcB = KiteSurface.from_profiles([prf3, prf4], 5., 5.)

        self.msrf = MultiSurface([sfcA, sfcB])

        coo = np.array([[-0.1, 0.0], [0.0, 0.1]])
        self.mesh = Mesh(coo[:, 0], coo[:, 1])

    def test_rx(self):
        # Test Rx
        expected = np.array([-3.492642, -13.384149])
        computed = self.msrf.get_rx_distance(self.mesh)
        np.testing.assert_allclose(computed, expected)
예제 #5
0
 def test_rx_kite(self):
     spc = 2.0
     pro1 = Line([Point(0.2, 0.0, 0.0), Point(0.2, 0.05, 15.0)])
     pro2 = Line([Point(0.0, 0.0, 0.0), Point(0.0, 0.05, 15.0)])
     sfc1 = KiteSurface.from_profiles([pro1, pro2], spc, spc)
     msurf = MultiSurface([sfc1])
     pcoo = numpy.array([[0.2, 0.1], [0.0, -0.1]])
     mesh = Mesh(pcoo[:, 0], pcoo[:, 1])
     # Compute expected distances
     lo = pro1.points[0].longitude
     la = pro1.points[0].longitude
     tmp0 = geodetic_distance(lo, la, pcoo[0, 0], pcoo[0, 1])
     lo = pro2.points[0].longitude
     la = pro2.points[0].longitude
     tmp1 = geodetic_distance(lo, la, pcoo[1, 0], pcoo[1, 1])
     # Checking
     rx = msurf.get_rx_distance(mesh)
     expected = numpy.array([tmp0, -tmp1])
     numpy.testing.assert_almost_equal(expected, rx, decimal=5)
예제 #6
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)
예제 #7
0
 def test_rx_distance_mesh1D(self):
     surf = MultiSurface(self.surfaces_mesh1D)
     numpy.testing.assert_equal(surf.get_rx_distance(self.mesh1D),
                                numpy.array([-1., 2., 2.]))
예제 #8
0
 def test_rx_distance_mesh2D(self):
     surf = MultiSurface(self.surfaces_mesh2D)
     numpy.testing.assert_equal(surf.get_rx_distance(self.mesh2D), numpy.array([[-1.0, 2.0, 2.0], [4.0, 4.0, 5.0]]))
예제 #9
0
 def test_rx_distance_mesh1D(self):
     surf = MultiSurface(self.surfaces_mesh1D)
     numpy.testing.assert_equal(surf.get_rx_distance(self.mesh1D),
                                numpy.array([-1., 2., 2.]))
예제 #10
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)
예제 #11
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)