本文整理汇总了Python中nhlib.geo.mesh.Mesh类的典型用法代码示例。如果您正苦于以下问题:Python Mesh类的具体用法?Python Mesh怎么用?Python Mesh使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mesh类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_nine_positions
def test_nine_positions(self):
def v2p(*vectors): # "vectors to points"
return [Point(*coords)
for coords in zip(*geo_utils.cartesian_to_spherical(
numpy.array(vectors, dtype=float)
))]
corners = v2p([6370, 0, -0.5], [6370, 0, 0.5],
[6369, 2, 0.5], [6369, 2, -0.5])
surface = PlanarSurface(1, 2, 3, *corners)
# first three positions: point projection is above the top edge
dists = surface.get_min_distance(Mesh.from_points_list(
v2p([6371, 0, -1.5], [6371, 0, 1.5], [6371, 0, 0.33])
))
self.assertTrue(numpy.allclose(dists, [2 ** 0.5, 2 ** 0.5, 1.0],
atol=1e-4))
# next three positions: point projection is below the bottom edge
dists = surface.get_min_distance(Mesh.from_points_list(
v2p([6368, 2, -1.5], [6368, 2, 1.5], [6368, 2, -0.45])
))
self.assertTrue(numpy.allclose(dists, [2 ** 0.5, 2 ** 0.5, 1.0],
atol=1e-4))
# next three positions: point projection is left to rectangle,
# right to it or lies inside
dists = surface.get_min_distance(Mesh.from_points_list(
v2p([6369.5, 1, -1.5], [6369.5, 1, 1.5], [6369.5, 1, -0.1])
))
self.assertTrue(numpy.allclose(dists, [1, 1, 0], atol=1e-4))
示例2: _test
def _test(self, mesh_points, target_points, expected_distance_indexes):
mesh = Mesh.from_points_list(mesh_points)
target_mesh = Mesh.from_points_list(target_points)
dists = mesh.get_min_distance(target_mesh)
expected_dists = [mesh_points[mi].distance(target_points[ti])
for ti, mi in enumerate(expected_distance_indexes)]
self.assertEqual(list(dists), expected_dists)
示例3: test_many_points
def test_many_points(self):
lons = numpy.array([0.7, 0.6, 0.4, 0.6, 0.3, 0.9, 0.5, 0.4])
lats = numpy.array([0.8, 0.5, 0.2, 0.7, 0.2, 0.4, 0.9, 0.4])
mesh = Mesh(lons, lats, None)
polygon = mesh.get_convex_hull()
elons = [0.4, 0.3, 0.5, 0.7, 0.9]
elats = [0.2, 0.2, 0.9, 0.8, 0.4]
numpy.testing.assert_allclose(polygon.lons, elons)
numpy.testing.assert_allclose(polygon.lats, elats)
示例4: test_two_points
def test_two_points(self):
mesh = Mesh(numpy.array([-10., -11.]), numpy.array([-12., -13.]), None)
polygon = mesh.get_convex_hull()
self.assertIsInstance(polygon, Polygon)
elons = [-10.99996704, -11.0000323, -11.00003296, -10.00003295,
-9.99996795, -9.99996705]
elats = [-13.00003147, -13.00003212, -12.99996853, -11.99996865,
-11.99996776, -12.00003135]
numpy.testing.assert_allclose(polygon.lons, elons)
numpy.testing.assert_allclose(polygon.lats, elats)
示例5: test
def test(self):
mesh = Mesh(numpy.array([0., 1., 2., 3.]), numpy.zeros(4), None)
matrix = mesh.get_distance_matrix()
aaae = numpy.testing.assert_array_almost_equal
aaae(matrix[0], [[0, 111.2, 222.4, 333.6]], decimal=1)
aaae(matrix[1], [[111.2, 0, 111.2, 222.4]], decimal=1)
aaae(matrix[2], [[222.4, 111.2, 0, 111.2]], decimal=1)
aaae(matrix[3], [[333.6, 222.4, 111.2, 0]], decimal=1)
for i in xrange(4):
for j in xrange(i, 4):
self.assertEqual(matrix[i, j], matrix[j, i])
示例6: test_point_on_the_border
def test_point_on_the_border(self):
corners = [[(0.1, -0.1, 1), (-0.1, -0.1, 1)], [(0.1, 0.1, 2), (-0.1, 0.1, 2)]]
surface = DummySurface(corners)
sites = Mesh.from_points_list([Point(-0.1, 0.04), Point(0.1, 0.03)])
dists = surface.get_joyner_boore_distance(sites)
expected_dists = [0] * 2
self.assertTrue(numpy.allclose(dists, expected_dists, atol=1e-4))
示例7: test_point_inside
def test_point_inside(self):
corners = [[(-1, -1, 1), (1, -1, 1)], [(-1, 1, 2), (1, 1, 2)]]
surface = DummySurface(corners)
sites = Mesh.from_points_list([Point(0, 0), Point(0, 0, 20), Point(0.1, 0.3)])
dists = surface.get_joyner_boore_distance(sites)
expected_dists = [0] * 3
self.assertTrue(numpy.allclose(dists, expected_dists))
示例8: test_left_or_right_edge_is_closest
def test_left_or_right_edge_is_closest(self):
sites = Mesh.from_points_list([Point(-0.24, -0.08, 0.55), Point(0.17, 0.07, 0)])
res = self.surface.get_closest_points(sites)
aae = numpy.testing.assert_almost_equal
aae(res.lons, [-0.1, 0.1], decimal=5)
aae(res.lats, [-0.08, 0.07], decimal=3)
aae(res.depths, [0.20679306, 1.69185737])
示例9: test_top_or_bottom_edge_is_closest
def test_top_or_bottom_edge_is_closest(self):
sites = Mesh.from_points_list([Point(-0.04, -0.28, 0), Point(0.033, 0.15, 0)])
res = self.surface.get_closest_points(sites)
aae = numpy.testing.assert_almost_equal
aae(res.lons, [-0.04, 0.033], decimal=5)
aae(res.lats, [-0.1, 0.1], decimal=5)
aae(res.depths, [0, 2], decimal=2)
示例10: test_point_outside
def test_point_outside(self):
corners = [Point(0.1, -0.1, 1), Point(-0.1, -0.1, 1), Point(-0.1, 0.1, 2), Point(0.1, 0.1, 2)]
surface = PlanarSurface(1, 270, 45, *corners)
sites = Mesh.from_points_list(
[
Point(-0.2, -0.2),
Point(1, 1, 1),
Point(4, 5),
Point(0.8, 0.01),
Point(0.2, -0.15),
Point(0.02, -0.12),
Point(-0.14, 0),
Point(-3, 3),
Point(0.05, 0.15, 10),
]
)
dists = surface.get_joyner_boore_distance(sites)
expected_dists = [
Point(-0.2, -0.2).distance(Point(-0.1, -0.1)),
Point(1, 1).distance(Point(0.1, 0.1)),
Point(4, 5).distance(Point(0.1, 0.1)),
Point(0.8, 0.01).distance(Point(0.1, 0.01)),
Point(0.2, -0.15).distance(Point(0.1, -0.1)),
Point(0.02, -0.12).distance(Point(0.02, -0.1)),
Point(-0.14, 0).distance(Point(-0.1, 0)),
Point(-3, 3).distance(Point(-0.1, 0.1)),
Point(0.05, 0.15).distance(Point(0.05, 0.1)),
]
self.assertTrue(numpy.allclose(dists, expected_dists, atol=0.05))
示例11: test_point_on_the_border
def test_point_on_the_border(self):
corners = [Point(0.1, -0.1, 1), Point(-0.1, -0.1, 1), Point(-0.1, 0.1, 2), Point(0.1, 0.1, 2)]
surface = PlanarSurface(1, 270, 45, *corners)
sites = Mesh.from_points_list([Point(-0.1, 0.04), Point(0.1, 0.03)])
dists = surface.get_joyner_boore_distance(sites)
expected_dists = [0] * 2
self.assertTrue(numpy.allclose(dists, expected_dists))
示例12: test4_site_along_strike
def test4_site_along_strike(self):
surface = self._test1to7surface()
sites = Mesh.from_points_list([Point(0.2, 0), Point(67.6, 0),
Point(90.33, 0)])
dists = surface.get_rx_distance(sites)
expected_dists = [0] * 3
self.assertTrue(numpy.allclose(dists, expected_dists))
示例13: test_one_point
def test_one_point(self):
mesh = Mesh.from_points_list([Point(7, 7)])
polygon = mesh.get_convex_hull()
elons = [7.0000453, 7., 6.9999547, 7]
elats = [7., 6.99995503, 7., 7.00004497]
numpy.testing.assert_allclose(polygon.lons, elons)
numpy.testing.assert_allclose(polygon.lats, elats)
示例14: test_simple
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)
示例15: test8_strike_of_45_degrees
def test8_strike_of_45_degrees(self):
corners = [Point(-0.05, -0.05, 8), Point(0.05, 0.05, 8),
Point(0.05, 0.05, 9), Point(-0.05, -0.05, 9)]
surface = PlanarSurface(1, 45, 60, *corners)
sites = Mesh.from_points_list([Point(0.05, 0)])
self.assertAlmostEqual(surface.get_rx_distance(sites)[0],
3.9313415355436705, places=4)