本文整理汇总了Python中nhlib.geo.mesh.RectangularMesh类的典型用法代码示例。如果您正苦于以下问题:Python RectangularMesh类的具体用法?Python RectangularMesh怎么用?Python RectangularMesh使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RectangularMesh类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_rectangular
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)
示例2: 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)
示例3: test_even_rows_even_columns_with_depths
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))
示例4: test_mesh_of_one_point
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))
示例5: _test
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
示例6: test_mesh_of_two_points
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)
示例7: _test
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)
示例8: test_mesh_width
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)
示例9: test_vertical_mesh
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))
示例10: test_single_column
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)
示例11: test_single_row
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)
示例12: test_dip_over_90_degree
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)
示例13: from_fault_data
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)
示例14: test_one_cell
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)
示例15: test_one_cell_unequal_area
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)