Example #1
0
    def test_simple(self):
        lons = numpy.array([numpy.arange(-1, 1.2, 0.2)] * 11)
        lats = lons.transpose() + 1
        depths = lats + 10
        mesh = RectangularMesh(lons, lats, depths)

        check = lambda lon, lat, depth, expected_distance, **kwargs: \
            self.assertAlmostEqual(
                mesh.get_joyner_boore_distance(
                    Mesh.from_points_list([Point(lon, lat, depth)])
                )[0],
                expected_distance, **kwargs
            )

        check(lon=0, lat=0.5, depth=0, expected_distance=0)
        check(lon=1, lat=1, depth=0, expected_distance=0)
        check(lon=0.6,
              lat=-1,
              depth=0,
              expected_distance=Point(0.6, -1).distance(Point(0.6, 0)),
              delta=0.1)
        check(lon=-0.8,
              lat=2.1,
              depth=10,
              expected_distance=Point(-0.8, 2.1).distance(Point(-0.8, 2)),
              delta=0.02)
        check(lon=0.75,
              lat=2.3,
              depth=3,
              expected_distance=Point(0.75, 2.3).distance(Point(0.75, 2)),
              delta=0.04)
Example #2
0
 def test_even_rows_even_columns_with_depths(self):
     lons = numpy.array([[10, 20], [12, 22]])
     lats = numpy.array([[10, -10], [8, -9]])
     depths = numpy.array([[2, 3], [4, 5]])
     mesh = RectangularMesh(lons, lats, depths=depths)
     self.assertEqual(mesh.get_middle_point(),
                      Point(15.996712, -0.250993, 3.5))
Example #3
0
    def test_rectangular(self):
        lons = numpy.array(range(100)).reshape((10, 10))
        lats = numpy.negative(lons)

        mesh = RectangularMesh(lons, lats, depths=None)
        bounding_mesh = mesh._get_bounding_mesh()
        expected_lons = numpy.array([
            0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
            19, 29, 39, 49, 59, 69, 79, 89,
            99, 98, 97, 96, 95, 94, 93, 92, 91,
            90, 80, 70, 60, 50, 40, 30, 20, 10
        ])
        expected_lats = numpy.negative(expected_lons)
        self.assertTrue((bounding_mesh.lons == expected_lons).all())
        self.assertTrue((bounding_mesh.lats == expected_lats).all())
        self.assertIsNone(bounding_mesh.depths)

        depths = lons + 10
        mesh = RectangularMesh(lons, lats, depths)
        expected_depths = expected_lons + 10
        bounding_mesh = mesh._get_bounding_mesh()
        self.assertIsNotNone(bounding_mesh.depths)
        self.assertTrue((bounding_mesh.depths
                         == expected_depths.flatten()).all())

        bounding_mesh = mesh._get_bounding_mesh(with_depths=False)
        self.assertIsNone(bounding_mesh.depths)
Example #4
0
    def test_simple(self):
        lons = numpy.array([numpy.arange(-1, 1.2, 0.2)] * 11)
        lats = lons.transpose() + 1
        depths = lats + 10
        mesh = RectangularMesh(lons, lats, depths)

        check = lambda lon, lat, depth, expected_distance, **kwargs: \
            self.assertAlmostEqual(
                mesh.get_joyner_boore_distance(
                    Mesh.from_points_list([Point(lon, lat, depth)])
                )[0],
                expected_distance, **kwargs
            )

        check(lon=0, lat=0.5, depth=0, expected_distance=0)
        check(lon=1, lat=1, depth=0, expected_distance=0)
        check(lon=0.6, lat=-1, depth=0,
              expected_distance=Point(0.6, -1).distance(Point(0.6, 0)),
              delta=0.1)
        check(lon=-0.8, lat=2.1, depth=10,
              expected_distance=Point(-0.8, 2.1).distance(Point(-0.8, 2)),
              delta=0.02)
        check(lon=0.75, lat=2.3, depth=3,
              expected_distance=Point(0.75, 2.3).distance(Point(0.75, 2)),
              delta=0.04)
Example #5
0
 def test_even_rows_even_columns_with_depths(self):
     lons = numpy.array([[10, 20], [12, 22]])
     lats = numpy.array([[10, -10], [8, -9]])
     depths = numpy.array([[2, 3], [4, 5]])
     mesh = RectangularMesh(lons, lats, depths=depths)
     self.assertEqual(mesh.get_middle_point(),
                      Point(15.996712, -0.250993, 3.5))
Example #6
0
 def test_mesh_of_two_points(self):
     lons = numpy.array([[0, 0.5, 1]], float)
     lats = numpy.array([[0, 0, 0]], float)
     depths = numpy.array([[1, 0, 1]], float)
     mesh = RectangularMesh(lons, lats, depths)
     target_mesh = Mesh.from_points_list([Point(0.5, 1), Point(0.5, 0)])
     dists = mesh.get_joyner_boore_distance(target_mesh)
     expected_dists = [Point(0.5, 1).distance(Point(0.5, 0)), 0]
     numpy.testing.assert_almost_equal(dists, expected_dists)
Example #7
0
 def test_mesh_of_one_point(self):
     lons = numpy.array([[1]])
     lats = numpy.array([[0]])
     depths = numpy.array([[1]])
     mesh = RectangularMesh(lons, lats, depths)
     target_mesh = Mesh.from_points_list([Point(1, 0), Point(0.5, 0)])
     dists = mesh.get_joyner_boore_distance(target_mesh)
     expected_dists = [0, Point(0.5, 0).distance(Point(1, 0))]
     self.assertTrue(numpy.allclose(dists, expected_dists, atol=0.2))
Example #8
0
 def test_mesh_of_two_points(self):
     lons = numpy.array([[0, 0.5, 1]], float)
     lats = numpy.array([[0, 0, 0]], float)
     depths = numpy.array([[1, 0, 1]], float)
     mesh = RectangularMesh(lons, lats, depths)
     target_mesh = Mesh.from_points_list([Point(0.5, 1), Point(0.5, 0)])
     dists = mesh.get_joyner_boore_distance(target_mesh)
     expected_dists = [Point(0.5, 1).distance(Point(0.5, 0)), 0]
     numpy.testing.assert_almost_equal(dists, expected_dists)
Example #9
0
 def _test(self, lons, lats, depths, expected_coords):
     mesh = RectangularMesh(lons, lats, depths)
     proj, polygon = mesh._get_proj_enclosing_polygon()
     self.assertTrue(polygon.is_valid)
     self.assertEqual(list(polygon.interiors), [])
     coords = numpy.array(proj(*numpy.array(polygon.exterior).transpose(),
                               reverse=True)).transpose()
     numpy.testing.assert_almost_equal(coords, expected_coords, decimal=4)
     return polygon
Example #10
0
 def test_mesh_of_one_point(self):
     lons = numpy.array([[1.]])
     lats = numpy.array([[0.]])
     depths = numpy.array([[1.]])
     mesh = RectangularMesh(lons, lats, depths)
     target_mesh = Mesh.from_points_list([Point(1, 0), Point(0.5, 0)])
     dists = mesh.get_joyner_boore_distance(target_mesh)
     expected_dists = [0, Point(0.5, 0).distance(Point(1, 0))]
     self.assertTrue(numpy.allclose(dists, expected_dists, atol=0.2))
Example #11
0
 def _test(self, points, site, expected_distance):
     lons, lats, depths = numpy.array(points).transpose()
     lons = lons.transpose()
     lats = lats.transpose()
     depths = depths.transpose()
     mesh = RectangularMesh(lons, lats, depths)
     distance = mesh.get_joyner_boore_distance(
         Mesh.from_points_list([Point(*site)]))[0]
     self.assertAlmostEqual(distance, expected_distance, delta=0.02)
Example #12
0
 def _test(self, lons, lats, depths, expected_coords):
     mesh = RectangularMesh(lons, lats, depths)
     proj, polygon = mesh._get_proj_enclosing_polygon()
     self.assertTrue(polygon.is_valid)
     self.assertEqual(list(polygon.interiors), [])
     coords = numpy.array(
         proj(*numpy.array(polygon.exterior).transpose(),
              reverse=True)).transpose()
     numpy.testing.assert_almost_equal(coords, expected_coords, decimal=4)
     return polygon
Example #13
0
 def _test(self, points, site, expected_distance):
     lons, lats, depths = numpy.array(points).transpose()
     lons = lons.transpose()
     lats = lats.transpose()
     depths = depths.transpose()
     mesh = RectangularMesh(lons, lats, depths)
     distance = mesh.get_joyner_boore_distance(
         Mesh.from_points_list([Point(*site)])
     )[0]
     self.assertAlmostEqual(distance, expected_distance, delta=0.02)
Example #14
0
 def test_mesh_width(self):
     lons = numpy.array([[0.1, 0.1, 0.1, 0.1],
                         [0.1, 0.1, 0.1, 0.1],
                         [0.1, 0.1, 0.1, 0.1]])
     lats = numpy.array([[0.1, 0.10899322, 0.11798643, 0.12697965],
                         [0.1, 0.10899322, 0.11798643, 0.12697965],
                         [0.1, 0.10899322, 0.11798643, 0.12697965]])
     depths = numpy.array([[2.0, 2.0, 2.0, 2.0],
                           [3.0, 3.0, 3.0, 3.0],
                           [4.0, 4.0, 4.0, 4.0]])
     mesh = RectangularMesh(lons, lats, depths)
     self.assertAlmostEqual(mesh.get_mean_width(), 2.0)
Example #15
0
 def test_vertical_mesh(self):
     lons = numpy.array([[0, 1, 2], [0, 1, 2]])
     lats = numpy.array([[0, 0, 0], [0, 0, 0]])
     depths = numpy.array([[1, 1, 1], [2, 2, 2]])
     mesh = RectangularMesh(lons, lats, depths)
     target_mesh = Mesh.from_points_list([Point(0.5, 0), Point(0.5, 1),
                                          Point(0.5, 5)])
     dists = mesh.get_joyner_boore_distance(target_mesh)
     expected_dists = [
         0, Point(0.5, 1).distance(Point(0.5, 0)),
         Point(0.5, 5).distance(Point(0.5, 0))
     ]
     self.assertTrue(numpy.allclose(dists, expected_dists, atol=3))
Example #16
0
 def _test(self, points, centroids, lengths, widths, areas):
     fake_coords = numpy.array([[0]])
     self.points = numpy.array(points, dtype=float)
     mesh = RectangularMesh(fake_coords, fake_coords, fake_coords)
     cell_center, cell_length, cell_width, cell_area \
             = mesh.get_cell_dimensions()
     self.assertTrue(numpy.allclose(cell_length, lengths),
                     '%s != %s' % (cell_length, lengths))
     self.assertTrue(numpy.allclose(cell_width, widths),
                     '%s != %s' % (cell_width, widths))
     self.assertTrue(numpy.allclose(cell_area, areas),
                     '%s != %s' % (cell_area, areas))
     self.assertTrue(numpy.allclose(cell_center, centroids),
                     '%s != %s' % (cell_center, centroids))
Example #17
0
 def _test(self, points, centroids, lengths, widths, areas):
     fake_coords = numpy.array([[0]])
     self.points = numpy.array(points, dtype=float)
     mesh = RectangularMesh(fake_coords, fake_coords, fake_coords)
     cell_center, cell_length, cell_width, cell_area \
             = mesh.get_cell_dimensions()
     self.assertTrue(numpy.allclose(cell_length, lengths),
                     '%s != %s' % (cell_length, lengths))
     self.assertTrue(numpy.allclose(cell_width, widths),
                     '%s != %s' % (cell_width, widths))
     self.assertTrue(numpy.allclose(cell_area, areas),
                     '%s != %s' % (cell_area, areas))
     self.assertTrue(numpy.allclose(cell_center, centroids),
                     '%s != %s' % (cell_center, centroids))
Example #18
0
 def _create_mesh(self):
     """
     See :meth:`nhlib.geo.surface.base.BaseSurface._create_mesh`.
     """
     llons, llats, ldepths = geodetic.intervals_between(
         self.top_left.longitude, self.top_left.latitude,
         self.top_left.depth,
         self.bottom_left.longitude, self.bottom_left.latitude,
         self.bottom_left.depth,
         self.mesh_spacing
     )
     rlons, rlats, rdepths = geodetic.intervals_between(
         self.top_right.longitude, self.top_right.latitude,
         self.top_right.depth,
         self.bottom_right.longitude, self.bottom_right.latitude,
         self.bottom_right.depth,
         self.mesh_spacing
     )
     mlons, mlats, mdepths = [], [], []
     for i in xrange(len(llons)):
         lons, lats, depths = geodetic.intervals_between(
             llons[i], llats[i], ldepths[i], rlons[i], rlats[i], rdepths[i],
             self.mesh_spacing
         )
         mlons.append(lons)
         mlats.append(lats)
         mdepths.append(depths)
     return RectangularMesh(numpy.array(mlons), numpy.array(mlats),
                            numpy.array(mdepths))
Example #19
0
    def test_single_column(self):
        lons = numpy.array([[0], [1], [2], [3], [4], [5]])
        lats = numpy.array([[-1], [-2], [-3], [-4], [-5], [-6]])
        mesh = RectangularMesh(lons, lats, depths=None)
        bounding_mesh = mesh._get_bounding_mesh()
        self.assertTrue((bounding_mesh.lons == lons.flatten()).all())
        self.assertTrue((bounding_mesh.lats == lats.flatten()).all())
        self.assertIsNone(bounding_mesh.depths)

        depths = numpy.array([[10], [11], [12], [13], [14], [15]])
        mesh = RectangularMesh(lons, lats, depths)
        bounding_mesh = mesh._get_bounding_mesh()
        self.assertIsNotNone(bounding_mesh.depths)
        self.assertTrue((bounding_mesh.depths == depths.flatten()).all())

        bounding_mesh = mesh._get_bounding_mesh(with_depths=False)
        self.assertIsNone(bounding_mesh.depths)
Example #20
0
    def test_single_row(self):
        lons = numpy.array([[0, 1, 2, 3, 4, 5]])
        lats = numpy.array([[-1, -2, -3, -4, -5, -6]])
        mesh = RectangularMesh(lons, lats, depths=None)
        bounding_mesh = mesh._get_bounding_mesh()
        self.assertIsInstance(bounding_mesh, Mesh)
        self.assertTrue((bounding_mesh.lons == lons[0]).all())
        self.assertTrue((bounding_mesh.lats == lats[0]).all())
        self.assertIsNone(bounding_mesh.depths)

        depths = numpy.array([[10, 11, 12, 13, 14, 15]])
        mesh = RectangularMesh(lons, lats, depths)
        bounding_mesh = mesh._get_bounding_mesh()
        self.assertIsNotNone(bounding_mesh.depths)
        self.assertTrue((bounding_mesh.depths == depths[0]).all())

        bounding_mesh = mesh._get_bounding_mesh(with_depths=False)
        self.assertIsNone(bounding_mesh.depths)
Example #21
0
 def test_simple(self):
     lons = numpy.array([[0, 0.0089946277931563321],
                         [0, 0.0089974527390248322]])
     lats = numpy.array([[0, 0], [0, 0]], dtype=float)
     depths = numpy.array([[1, 0.99992150706475513],
                           [3, 2.9999214824129012]])
     mesh = RectangularMesh(lons, lats, depths)
     points, along_azimuth, updip, diag = mesh.triangulate()
     self.assertTrue(
         numpy.allclose(points, [[(6370, 0, 0),
                                  (6370, 1, 0)], [(6368, 0, 0),
                                                  (6368, 1, 0)]]))
     self.assertTrue(
         numpy.allclose(along_azimuth, [[(0, 1, 0)], [(0, 1, 0)]]))
     self.assertTrue(numpy.allclose(updip, [
         [(2, 0, 0)],
         [(2, 0, 0)],
     ]))
     self.assertTrue(numpy.allclose(diag, [[(2, 1, 0)]]))
Example #22
0
    def test_dip_over_90_degree(self):
        top = [Point(0, -0.01), Point(0, 0.01)]
        bottom = [Point(-0.01, -0.01, 1.11), Point(-0.01, 0.01, 1.11)]

        mesh = RectangularMesh.from_points_list([top, bottom])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        # dip must be still in a range 0..90
        self.assertAlmostEqual(dip, 45, delta=0.05)
        # strike must be reversed
        self.assertAlmostEqual(strike, 180, delta=0.05)
Example #23
0
    def test_dip_over_90_degree(self):
        top = [Point(0, -0.01), Point(0, 0.01)]
        bottom = [Point(-0.01, -0.01, 1.11), Point(-0.01, 0.01, 1.11)]

        mesh = RectangularMesh.from_points_list([top, bottom])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        # dip must be still in a range 0..90
        self.assertAlmostEqual(dip, 45, delta=0.05)
        # strike must be reversed
        self.assertAlmostEqual(strike, 180, delta=0.05)
Example #24
0
    def test_from_points_list(self):
        lons = [[0, 1], [2, 3], [4, 5]]
        lats = [[1, 2], [-1, -2], [10, 20]]
        depths = [[11.1, 11.2], [11.3, 11.4], [11.5, 11.6]]
        points = [[
            Point(lons[i][j], lats[i][j], depths[i][j])
            for j in xrange(len(lons[i]))
        ] for i in xrange(len(lons))]
        mesh = RectangularMesh.from_points_list(points)
        self.assertTrue((mesh.lons == lons).all())
        self.assertTrue((mesh.lats == lats).all())
        self.assertTrue((mesh.depths == depths).all())

        points = [[
            Point(lons[i][j], lats[i][j], depth=0)
            for j in xrange(len(lons[i]))
        ] for i in xrange(len(lons))]
        mesh = RectangularMesh.from_points_list(points)
        self.assertTrue((mesh.lons == lons).all())
        self.assertTrue((mesh.lats == lats).all())
        self.assertIsNone(mesh.depths)
Example #25
0
 def test_simple(self):
     lons = numpy.array([[0, 0.0089946277931563321],
                         [0, 0.0089974527390248322]])
     lats = numpy.array([[0, 0], [0, 0]], dtype=float)
     depths = numpy.array([[1, 0.99992150706475513],
                           [3, 2.9999214824129012]])
     mesh = RectangularMesh(lons, lats, depths)
     points, along_azimuth, updip, diag = mesh.triangulate()
     self.assertTrue(numpy.allclose(points, [
         [(6370, 0, 0), (6370, 1, 0)],
         [(6368, 0, 0), (6368, 1, 0)]
     ]))
     self.assertTrue(numpy.allclose(along_azimuth, [
         [(0, 1, 0)], [(0, 1, 0)]
     ]))
     self.assertTrue(numpy.allclose(updip, [
         [(2, 0, 0)], [(2, 0, 0)],
     ]))
     self.assertTrue(numpy.allclose(diag, [
         [(2, 1, 0)]
     ]))
Example #26
0
    def from_fault_data(cls, fault_trace, upper_seismogenic_depth,
                        lower_seismogenic_depth, dip, mesh_spacing):
        """
        Create and return a fault surface using fault source data.

        :param fault_trace:
            Geographical line representing the intersection between
            the fault surface and the earth surface, an instance
            of :class:`nhlib.Line`.
        :param upper_seismo_depth:
            Minimum depth ruptures can reach, in km (i.e. depth
            to fault's top edge).
        :param lower_seismo_depth:
            Maximum depth ruptures can reach, in km (i.e. depth
            to fault's bottom edge).
        :param dip:
            Dip angle (i.e. angle between fault surface
            and earth surface), in degrees.
        :param mesh_spacing:
            Distance between two subsequent points in a mesh, in km.
        :returns:
            An instance of :class:`SimpleFaultSurface` created using that data.

        Uses :meth:`check_fault_data` for checking parameters.
        """
        cls.check_fault_data(fault_trace, upper_seismogenic_depth,
                             lower_seismogenic_depth, dip, mesh_spacing)
        # Loops over points in the top edge, for each point
        # on the top edge compute corresponding point on the bottom edge, then
        # computes equally spaced points between top and bottom points.

        vdist_top = upper_seismogenic_depth
        vdist_bottom = lower_seismogenic_depth

        hdist_top = vdist_top / math.tan(math.radians(dip))
        hdist_bottom = vdist_bottom / math.tan(math.radians(dip))

        strike = fault_trace[0].azimuth(fault_trace[-1])
        azimuth = (strike + 90.0) % 360

        mesh = []
        for point in fault_trace.resample(mesh_spacing):
            top = point.point_at(hdist_top, vdist_top, azimuth)
            bottom = point.point_at(hdist_bottom, vdist_bottom, azimuth)
            mesh.append(top.equally_spaced_points(bottom, mesh_spacing))

        # number of rows corresponds to number of points along dip
        # number of columns corresponds to number of points along strike
        surface_points = numpy.array(mesh).transpose().tolist()
        mesh = RectangularMesh.from_points_list(surface_points)
        assert 1 not in mesh.shape
        return cls(mesh)
Example #27
0
    def test_one_cell(self):
        top = [Point(0, -0.01), Point(0, 0.01)]
        bottom = [Point(0.01, -0.01, 1.11), Point(0.01, 0.01, 1.11)]

        mesh = RectangularMesh.from_points_list([top, bottom])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertAlmostEqual(dip, 45, delta=0.05)
        self.assertAlmostEqual(strike, 0, delta=0.05)

        row1 = [Point(45, -0.1), Point(45.2, 0.1)]
        row2 = [Point(45, -0.1, 1), Point(45.2, 0.1, 1)]
        mesh = RectangularMesh.from_points_list([row1, row2])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertAlmostEqual(dip, 90)
        self.assertAlmostEqual(strike, 45, delta=0.1)

        row1 = [Point(90, -0.1), Point(90, 0.1)]
        row2 = [Point(90, -0.1, 1), Point(90, 0.1, 1)]
        mesh = RectangularMesh.from_points_list([row1, row2])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertAlmostEqual(dip, 90)
        self.assertAlmostEqual(strike, 0, delta=0.1)
Example #28
0
    def test_one_cell(self):
        top = [Point(0, -0.01), Point(0, 0.01)]
        bottom = [Point(0.01, -0.01, 1.11), Point(0.01, 0.01, 1.11)]

        mesh = RectangularMesh.from_points_list([top, bottom])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertAlmostEqual(dip, 45, delta=0.05)
        self.assertAlmostEqual(strike, 0, delta=0.05)

        row1 = [Point(45, -0.1), Point(45.2, 0.1)]
        row2 = [Point(45, -0.1, 1), Point(45.2, 0.1, 1)]
        mesh = RectangularMesh.from_points_list([row1, row2])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertAlmostEqual(dip, 90)
        self.assertAlmostEqual(strike, 45, delta=0.1)

        row1 = [Point(90, -0.1), Point(90, 0.1)]
        row2 = [Point(90, -0.1, 1), Point(90, 0.1, 1)]
        mesh = RectangularMesh.from_points_list([row1, row2])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertAlmostEqual(dip, 90)
        self.assertAlmostEqual(strike, 0, delta=0.1)
Example #29
0
    def from_fault_data(cls, fault_trace, upper_seismogenic_depth,
                        lower_seismogenic_depth, dip, mesh_spacing):
        """
        Create and return a fault surface using fault source data.

        :param nhlib.geo.line.Line fault_trace:
            Geographical line representing the intersection between
            the fault surface and the earth surface.
        :param upper_seismo_depth:
            Minimum depth ruptures can reach, in km (i.e. depth
            to fault's top edge).
        :param lower_seismo_depth:
            Maximum depth ruptures can reach, in km (i.e. depth
            to fault's bottom edge).
        :param dip:
            Dip angle (i.e. angle between fault surface
            and earth surface), in degrees.
        :param mesh_spacing:
            Distance between two subsequent points in a mesh, in km.
        :returns:
            An instance of :class:`SimpleFaultSurface` created using that data.

        Uses :meth:`check_fault_data` for checking parameters.
        """
        cls.check_fault_data(fault_trace, upper_seismogenic_depth,
                             lower_seismogenic_depth, dip, mesh_spacing)
        # Loops over points in the top edge, for each point
        # on the top edge compute corresponding point on the bottom edge, then
        # computes equally spaced points between top and bottom points.

        vdist_top = upper_seismogenic_depth
        vdist_bottom = lower_seismogenic_depth

        hdist_top = vdist_top / math.tan(math.radians(dip))
        hdist_bottom = vdist_bottom / math.tan(math.radians(dip))

        strike = fault_trace[0].azimuth(fault_trace[-1])
        azimuth = (strike + 90.0) % 360

        mesh = []
        for point in fault_trace.resample(mesh_spacing):
            top = point.point_at(hdist_top, vdist_top, azimuth)
            bottom = point.point_at(hdist_bottom, vdist_bottom, azimuth)
            mesh.append(top.equally_spaced_points(bottom, mesh_spacing))

        # number of rows corresponds to number of points along dip
        # number of columns corresponds to number of points along strike
        surface_points = numpy.array(mesh).transpose().tolist()
        mesh = RectangularMesh.from_points_list(surface_points)
        assert 1 not in mesh.shape
        return cls(mesh)
Example #30
0
    def test_one_cell_unequal_area(self):
        # top-left triangle is vertical, has dip of 90 degrees, zero
        # strike and area of 1 by 1 over 2. bottom-right one has dip
        # of atan2(1, sqrt(2) / 2.0) which is 54.73561 degrees, strike
        # of 45 degrees and area that is 1.73246136 times area of the
        # first one's. weighted mean dip is 67.5 degrees and weighted
        # mean strike is 28.84 degrees
        top = [Point(0, -0.01), Point(0, 0.01)]
        bottom = [Point(0, -0.01, 2.22), Point(0.02, 0.01, 2.22)]

        mesh = RectangularMesh.from_points_list([top, bottom])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertAlmostEqual(dip, 67.5, delta=0.05)
        self.assertAlmostEqual(strike, 28.84, delta=0.05)
Example #31
0
    def test_one_cell_unequal_area(self):
        # top-left triangle is vertical, has dip of 90 degrees, zero
        # strike and area of 1 by 1 over 2. bottom-right one has dip
        # of atan2(1, sqrt(2) / 2.0) which is 54.73561 degrees, strike
        # of 45 degrees and area that is 1.73246136 times area of the
        # first one's. weighted mean dip is 67.5 degrees and weighted
        # mean strike is 28.84 degrees
        top = [Point(0, -0.01), Point(0, 0.01)]
        bottom = [Point(0, -0.01, 2.22), Point(0.02, 0.01, 2.22)]

        mesh = RectangularMesh.from_points_list([top, bottom])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertAlmostEqual(dip, 67.5, delta=0.05)
        self.assertAlmostEqual(strike, 28.84, delta=0.05)
Example #32
0
    def test_from_points_list(self):
        lons = [[0, 1], [2, 3], [4, 5]]
        lats = [[1, 2], [-1, -2], [10, 20]]
        depths = [[11.1, 11.2], [11.3, 11.4], [11.5, 11.6]]
        points = [
            [Point(lons[i][j], lats[i][j], depths[i][j])
             for j in xrange(len(lons[i]))]
            for i in xrange(len(lons))
        ]
        mesh = RectangularMesh.from_points_list(points)
        self.assertTrue((mesh.lons == lons).all())
        self.assertTrue((mesh.lats == lats).all())
        self.assertTrue((mesh.depths == depths).all())

        points = [
            [Point(lons[i][j], lats[i][j], depth=0)
             for j in xrange(len(lons[i]))]
            for i in xrange(len(lons))
        ]
        mesh = RectangularMesh.from_points_list(points)
        self.assertTrue((mesh.lons == lons).all())
        self.assertTrue((mesh.lats == lats).all())
        self.assertIsNone(mesh.depths)
Example #33
0
    def from_fault_data(cls, edges, mesh_spacing):
        """
        Create and return a fault surface using fault source data.

        :param edges:
            A list of at least two horizontal edges of the surface
            as instances of :class:`nhlib.geo.line.Line`. The list
            should be in top-to-bottom order (the shallowest edge
            first).
        :param mesh_spacing:
            Distance between two subsequent points in a mesh, in km.
        :returns:
            An instance of :class:`ComplexFaultSurface` created using
            that data.
        :raises ValueError:
            If requested mesh spacing is too big for the surface geometry
            (doesn't allow to put a single mesh cell along length and/or
            width).

        Uses :meth:`check_fault_data` for checking parameters.
        """
        cls.check_fault_data(edges, mesh_spacing)

        mean_length = numpy.mean([edge.get_length() for edge in edges])
        num_hor_points = int(round(mean_length / mesh_spacing)) + 1
        if num_hor_points <= 1:
            raise ValueError(
                'mesh spacing %.1f km is too big for mean length %.1f km' %
                (mesh_spacing, mean_length))
        edges = [
            edge.resample_to_num_points(num_hor_points).points
            for i, edge in enumerate(edges)
        ]

        vert_edges = [Line(v_edge) for v_edge in zip(*edges)]
        mean_width = numpy.mean([v_edge.get_length() for v_edge in vert_edges])
        num_vert_points = int(round(mean_width / mesh_spacing)) + 1
        if num_vert_points <= 1:
            raise ValueError(
                'mesh spacing %.1f km is too big for mean width %.1f km' %
                (mesh_spacing, mean_width))

        points = zip(*[
            v_edge.resample_to_num_points(num_vert_points).points
            for v_edge in vert_edges
        ])
        mesh = RectangularMesh.from_points_list(points)
        assert 1 not in mesh.shape
        return cls(mesh)
Example #34
0
    def from_fault_data(cls, edges, mesh_spacing):
        """
        Create and return a fault surface using fault source data.

        :param edges:
            A list of at least two horizontal edges of the surface
            as instances of :class:`nhlib.geo.line.Line`. The list
            should be in top-to-bottom order (the shallowest edge
            first).
        :param mesh_spacing:
            Distance between two subsequent points in a mesh, in km.
        :returns:
            An instance of :class:`ComplexFaultSurface` created using
            that data.
        :raises ValueError:
            If requested mesh spacing is too big for the surface geometry
            (doesn't allow to put a single mesh cell along length and/or
            width).

        Uses :meth:`check_fault_data` for checking parameters.
        """
        cls.check_fault_data(edges, mesh_spacing)

        mean_length = numpy.mean([edge.get_length() for edge in edges])
        num_hor_points = int(round(mean_length / mesh_spacing)) + 1
        if num_hor_points <= 1:
            raise ValueError(
                'mesh spacing %.1f km is too big for mean length %.1f km' %
                (mesh_spacing, mean_length)
            )
        edges = [edge.resample_to_num_points(num_hor_points).points
                 for i, edge in enumerate(edges)]

        vert_edges = [Line(v_edge) for v_edge in zip(*edges)]
        mean_width = numpy.mean([v_edge.get_length() for v_edge in vert_edges])
        num_vert_points = int(round(mean_width / mesh_spacing)) + 1
        if num_vert_points <= 1:
            raise ValueError(
                'mesh spacing %.1f km is too big for mean width %.1f km' %
                (mesh_spacing, mean_width)
            )

        points = zip(*[v_edge.resample_to_num_points(num_vert_points).points
                       for v_edge in vert_edges])
        mesh = RectangularMesh.from_points_list(points)
        assert 1 not in mesh.shape
        return cls(mesh)
Example #35
0
    def test_two_cells(self):
        top = [Point(0, -0.01), Point(0, 0.01)]
        middle = [Point(0.01, -0.01, 1.11), Point(0.01, 0.01, 1.11)]
        bottom = [Point(0.01, -0.01, 2.22), Point(0.01, 0.01, 2.22)]

        mesh = RectangularMesh.from_points_list([top, middle, bottom])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertAlmostEqual(dip, math.degrees(math.atan2(2, 1)), delta=0.1)
        self.assertAlmostEqual(strike, 0, delta=0.02)

        bottom = [Point(0.01, -0.01, 3.33), Point(0.01, 0.01, 3.33)]
        mesh = RectangularMesh.from_points_list([top, middle, bottom])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertAlmostEqual(dip, math.degrees(math.atan2(3, 1)), delta=0.1)
        self.assertAlmostEqual(strike, 0, delta=0.02)

        row1 = [Point(90, -0.1), Point(90, 0), Point(90, 0.1)]
        row2 = [Point(90, -0.1, 1), Point(90, 0, 1), Point(90, 0.1, 1)]
        mesh = RectangularMesh.from_points_list([row1, row2])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertAlmostEqual(dip, 90)
        assert_angles_equal(self, strike, 360, delta=1e-7)

        row1 = [Point(-90.1, -0.1), Point(-90, 0), Point(-89.9, 0.1)]
        row2 = [
            Point(-90.0, -0.1, 1),
            Point(-89.9, 0, 1),
            Point(-89.8, 0.1, 1)
        ]
        mesh = RectangularMesh.from_points_list([row1, row2])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertAlmostEqual(strike, 45, delta=1e-4)

        row1 = [Point(-90.1, -0.1), Point(-90, 0), Point(-89.9, 0.1)]
        row2 = [
            Point(-90.0, -0.1, 1),
            Point(-89.9, 0, 1),
            Point(-89.8, 0.1, 1)
        ]
        mesh = RectangularMesh.from_points_list([row1, row2])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertAlmostEqual(strike, 45, delta=1e-3)

        row1 = [Point(-90.1, -0.1), Point(-90, 0), Point(-89.9, 0.1)]
        row2 = [Point(-90.2, -0.1, 1), Point(-90.1, 0, 1), Point(-90, 0.1, 1)]
        mesh = RectangularMesh.from_points_list([row1, row2])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertAlmostEqual(strike, 225, delta=1e-3)
Example #36
0
    def test_on_surface(self):
        row1 = [Point(0, 0), Point(0, 1)]
        row2 = [Point(1, 0), Point(1, 1)]
        mesh = RectangularMesh.from_points_list([row1, row2])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertEqual(dip, 0)
        self.assertAlmostEqual(strike, 0, delta=0.5)

        row1 = [Point(0, 0), Point(0, -1)]
        row2 = [Point(1, 0), Point(1, -1)]
        mesh = RectangularMesh.from_points_list([row1, row2])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertEqual(dip, 0)
        self.assertAlmostEqual(strike, 180, delta=0.5)

        row1 = [Point(0, 0), Point(1, 1)]
        row2 = [Point(1, 0), Point(2, 1)]
        mesh = RectangularMesh.from_points_list([row1, row2])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertEqual(dip, 0)
        self.assertAlmostEqual(strike, 45, delta=0.01)

        row1 = [Point(0, 0), Point(1, -1)]
        row2 = [Point(1, 0), Point(2, -1)]
        mesh = RectangularMesh.from_points_list([row1, row2])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertEqual(dip, 0)
        self.assertAlmostEqual(strike, 135, delta=0.01)

        row1 = [Point(0, 0), Point(-1, -1)]
        row2 = [Point(-1, 0), Point(-2, -1)]
        mesh = RectangularMesh.from_points_list([row1, row2])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertEqual(dip, 0)
        self.assertAlmostEqual(strike, 225, delta=0.01)

        row1 = [Point(0, 0), Point(-1, 1)]
        row2 = [Point(-1, 0), Point(-2, 1)]
        mesh = RectangularMesh.from_points_list([row1, row2])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertEqual(dip, 0)
        self.assertAlmostEqual(strike, 315, delta=0.01)
Example #37
0
    def test_on_surface(self):
        row1 = [Point(0, 0), Point(0, 1)]
        row2 = [Point(1, 0), Point(1, 1)]
        mesh = RectangularMesh.from_points_list([row1, row2])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertEqual(dip, 0)
        self.assertAlmostEqual(strike, 0, delta=0.5)

        row1 = [Point(0, 0), Point(0, -1)]
        row2 = [Point(1, 0), Point(1, -1)]
        mesh = RectangularMesh.from_points_list([row1, row2])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertEqual(dip, 0)
        self.assertAlmostEqual(strike, 180, delta=0.5)

        row1 = [Point(0, 0), Point(1, 1)]
        row2 = [Point(1, 0), Point(2, 1)]
        mesh = RectangularMesh.from_points_list([row1, row2])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertEqual(dip, 0)
        self.assertAlmostEqual(strike, 45, delta=0.01)

        row1 = [Point(0, 0), Point(1, -1)]
        row2 = [Point(1, 0), Point(2, -1)]
        mesh = RectangularMesh.from_points_list([row1, row2])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertEqual(dip, 0)
        self.assertAlmostEqual(strike, 135, delta=0.01)

        row1 = [Point(0, 0), Point(-1, -1)]
        row2 = [Point(-1, 0), Point(-2, -1)]
        mesh = RectangularMesh.from_points_list([row1, row2])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertEqual(dip, 0)
        self.assertAlmostEqual(strike, 225, delta=0.01)

        row1 = [Point(0, 0), Point(-1, 1)]
        row2 = [Point(-1, 0), Point(-2, 1)]
        mesh = RectangularMesh.from_points_list([row1, row2])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertEqual(dip, 0)
        self.assertAlmostEqual(strike, 315, delta=0.01)
Example #38
0
    def test_two_cells(self):
        top = [Point(0, -0.01), Point(0, 0.01)]
        middle = [Point(0.01, -0.01, 1.11), Point(0.01, 0.01, 1.11)]
        bottom = [Point(0.01, -0.01, 2.22), Point(0.01, 0.01, 2.22)]

        mesh = RectangularMesh.from_points_list([top, middle, bottom])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertAlmostEqual(dip, math.degrees(math.atan2(2, 1)), delta=0.1)
        self.assertAlmostEqual(strike, 0, delta=0.02)

        bottom = [Point(0.01, -0.01, 3.33), Point(0.01, 0.01, 3.33)]
        mesh = RectangularMesh.from_points_list([top, middle, bottom])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertAlmostEqual(dip, math.degrees(math.atan2(3, 1)), delta=0.1)
        self.assertAlmostEqual(strike, 0, delta=0.02)

        row1 = [Point(90, -0.1), Point(90, 0), Point(90, 0.1)]
        row2 = [Point(90, -0.1, 1), Point(90, 0, 1), Point(90, 0.1, 1)]
        mesh = RectangularMesh.from_points_list([row1, row2])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertAlmostEqual(dip, 90)
        assert_angles_equal(self, strike, 360, delta=1e-7)

        row1 = [Point(-90.1, -0.1), Point(-90, 0), Point(-89.9, 0.1)]
        row2 = [Point(-90.0, -0.1, 1), Point(-89.9, 0, 1), Point(-89.8, 0.1, 1)]
        mesh = RectangularMesh.from_points_list([row1, row2])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertAlmostEqual(strike, 45, delta=1e-4)

        row1 = [Point(-90.1, -0.1), Point(-90, 0), Point(-89.9, 0.1)]
        row2 = [Point(-90.0, -0.1, 1), Point(-89.9, 0, 1), Point(-89.8, 0.1, 1)]
        mesh = RectangularMesh.from_points_list([row1, row2])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertAlmostEqual(strike, 45, delta=1e-3)

        row1 = [Point(-90.1, -0.1), Point(-90, 0), Point(-89.9, 0.1)]
        row2 = [Point(-90.2, -0.1, 1), Point(-90.1, 0, 1), Point(-90, 0.1, 1)]
        mesh = RectangularMesh.from_points_list([row1, row2])
        dip, strike = mesh.get_mean_inclination_and_azimuth()
        self.assertAlmostEqual(strike, 225, delta=1e-3)
Example #39
0
 def test_wrong_shape(self):
     with self.assertRaises(AssertionError):
         RectangularMesh(numpy.array([0, 1, 2]), numpy.array([0, 0, 0]),
                         None)
         RectangularMesh(numpy.array([0, -1]), numpy.array([2, 10]),
                         numpy.array([5, 44]))
Example #40
0
 def test_even_rows_odd_columns_with_depth(self):
     lons = numpy.array([[20], [21]])
     lats = numpy.array([[-1], [1]])
     depths = numpy.array([[11.1], [11.3]])
     mesh = RectangularMesh(lons, lats, depths=depths)
     self.assertEqual(mesh.get_middle_point(), Point(20.5, 0, 11.2))
Example #41
0
 def test_even_rows_even_columns_no_depths(self):
     lons = numpy.array([[10, 20], [10.002, 20.002]])
     lats = numpy.array([[10, -10], [8, -8]])
     mesh = RectangularMesh(lons, lats, depths=None)
     self.assertEqual(mesh.get_middle_point(), Point(15.001, 0))
Example #42
0
 def test_even_rows_even_columns_no_depths(self):
     lons = numpy.array([[10, 20], [10.002, 20.002]])
     lats = numpy.array([[10, -10], [8, -8]])
     mesh = RectangularMesh(lons, lats, depths=None)
     self.assertEqual(mesh.get_middle_point(), Point(15.001, 0))
Example #43
0
 def test_even_rows_odd_columns_no_depths(self):
     lons = numpy.array([[-1, 0, 1, 2, 3], [-1.5, 0.5, 1.5, 2.5, 3.5]])
     lats = numpy.array([[-0.01] * 5, [-0.015] * 5])
     mesh = RectangularMesh(lons, lats, depths=None)
     self.assertEqual(mesh.get_middle_point(), Point(1.25, -0.0125, 0))
Example #44
0
 def _create_mesh(self):
     points = [[Point(*coordinates) for coordinates in row] for row in self.coordinates_list]
     return RectangularMesh.from_points_list(points)
Example #45
0
 def test_even_rows_odd_columns_with_depth(self):
     lons = numpy.array([[20], [21]])
     lats = numpy.array([[-1], [1]])
     depths = numpy.array([[11.1], [11.3]])
     mesh = RectangularMesh(lons, lats, depths=depths)
     self.assertEqual(mesh.get_middle_point(), Point(20.5, 0, 11.2))
Example #46
0
 def test_even_rows_odd_columns_no_depths(self):
     lons = numpy.array([[-1, 0, 1, 2, 3], [-1.5, 0.5, 1.5, 2.5, 3.5]])
     lats = numpy.array([[-0.01] * 5, [-0.015] * 5])
     mesh = RectangularMesh(lons, lats, depths=None)
     self.assertEqual(mesh.get_middle_point(), Point(1.25, -0.0125, 0))
Example #47
0
 def test_odd_rows_even_columns_no_depths(self):
     lons = numpy.array([[10, 20, 30, 40]])
     lats = numpy.array([[30] * 4])
     mesh = RectangularMesh(lons, lats, depths=None)
     self.assertEqual(mesh.get_middle_point(), Point(25, 30.094679))
Example #48
0
 def test_odd_rows_even_columns_with_depths(self):
     lons = numpy.array([[0, 20, 30, 90]])
     lats = numpy.array([[30] * 4])
     depths = numpy.array([[2, 7, 8, 10]])
     mesh = RectangularMesh(lons, lats, depths=depths)
     self.assertEqual(mesh.get_middle_point(), Point(25, 30.094679, 7.5))
Example #49
0
 def test_odd_rows_odd_columns_with_depths(self):
     lons = numpy.array([numpy.arange(-1, 1.2, 0.2)] * 11)
     lats = lons.transpose() * 10
     depths = lats + 10
     mesh = RectangularMesh(lons, lats, depths)
     self.assertEqual(mesh.get_middle_point(), Point(0, 0, 10))
Example #50
0
 def test_odd_rows_even_columns_no_depths(self):
     lons = numpy.array([[10, 20, 30, 40]])
     lats = numpy.array([[30] * 4])
     mesh = RectangularMesh(lons, lats, depths=None)
     self.assertEqual(mesh.get_middle_point(), Point(25, 30.094679))
Example #51
0
 def test_preserving_the_type(self):
     lons = lats = numpy.array(range(100)).reshape((10, 10))
     mesh = RectangularMesh(lons, lats, depths=None)
     submesh = mesh[1:2, 3:4]
     self.assertIsInstance(submesh, RectangularMesh)
Example #52
0
 def test_odd_rows_even_columns_with_depths(self):
     lons = numpy.array([[0, 20, 30, 90]])
     lats = numpy.array([[30] * 4])
     depths = numpy.array([[2, 7, 8, 10]])
     mesh = RectangularMesh(lons, lats, depths=depths)
     self.assertEqual(mesh.get_middle_point(), Point(25, 30.094679, 7.5))
Example #53
0
 def test_odd_rows_odd_columns_with_depths(self):
     lons = numpy.array([numpy.arange(-1, 1.2, 0.2)] * 11)
     lats = lons.transpose() * 10
     depths = lats + 10
     mesh = RectangularMesh(lons, lats, depths)
     self.assertEqual(mesh.get_middle_point(), Point(0, 0, 10))
Example #54
0
 def _create_mesh(self):
     points = [[Point(*coordinates) for coordinates in row]
               for row in self.coordinates_list]
     return RectangularMesh.from_points_list(points)