Ejemplo n.º 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)
Ejemplo n.º 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))
Ejemplo n.º 3
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))
Ejemplo n.º 4
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))
Ejemplo n.º 5
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)
Ejemplo n.º 6
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)
Ejemplo n.º 7
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
Ejemplo n.º 8
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))
Ejemplo n.º 9
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)]]))
Ejemplo n.º 10
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))
Ejemplo n.º 11
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))
Ejemplo n.º 12
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]))
Ejemplo n.º 13
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))
Ejemplo n.º 14
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))
Ejemplo n.º 15
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))
Ejemplo n.º 16
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)
Ejemplo n.º 17
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))