예제 #1
0
 def test_segment_inside_face(self):
     """The segment is completely within a face (no intersection)"""
     segment = (2.2, 2.1), (2.8, 2.1)
     profile = mesh.ElevationProfile(self.mesh, segment)
     # Any point inside segment has the face altitude (interpolation is not
     # used).
     assert_array_equal(profile([0, 0.3, 0.6]), [3, 3, 3])
예제 #2
0
 def test_no_point_inside(self):
     """Segment is outside mesh convex hull"""
     segment = (0.2, 0.2), (1, 0.2)
     profile = mesh.ElevationProfile(self.mesh, segment)
     self.assertEqual(profile.points, [])
     assert_almost_equal(profile.point_altitude(0), np.nan)
     assert_almost_equal(profile.point_altitude(1), np.nan)
예제 #3
0
 def test_point_altitude(self):
     segment = LineString([(2.5, 0), (2.5, 4)])
     profile = mesh.ElevationProfile(self.mesh, segment)
     self.assertIs(profile.point_altitude(0.5),
                   mesh.UNSPECIFIED_ALTITUDE)
     self.assertEqual(profile.point_altitude(2.5), 3.0)
     self.assertEqual(profile.point_altitude(1.5), 2.0)
예제 #4
0
 def test__point_at_distance(self):
     segment = LineString([(2, 2), (3, 2)])
     origin = Point(segment.coords[0])
     profile = mesh.ElevationProfile(self.mesh, segment)
     p = profile._point_at_distance(0)
     self.assertEqual(origin.distance(p), 0)
     self.assertEqual(p.coords[0], origin.coords[0])
     p = profile._point_at_distance(3)
     self.assertEqual(origin.distance(p), 3)
     self.assertEqual(p.coords[0], (5, 2))
예제 #5
0
 def test_point_data_vertex(self):
     """Test `point_data` method when the point is on a vertex."""
     # Beginning of segment is on a vertex of the mesh (first point of
     # outer rectangle).
     segment = LineString([(1, 1), (2, 3)])
     profile = mesh.ElevationProfile(self.mesh, segment)
     # Point on a vertex.
     p = self.rectangles[0][0]
     fh, vh = self.mesh.locate_point(p)
     self.assertIsInstance(vh, mesh.Vertex_handle)
     d = profile.point_data(0, face_data=self._material_by_face())
     self.assertEqual(d.id, 0)
예제 #6
0
 def test_sigma_interpolation(self):
     segment = LineString([(2.5, 0), (2.5, 5)])
     profile = mesh.ElevationProfile(self.mesh, segment)
     material_by_face = self._material_by_face()
     # Build an interpolator `sigma` on material resistivity.
     sigma_by_face = dict((fh, mat.resistivity)
                          for fh, mat in list(material_by_face.items()))
     sigma = profile.face_data_interpolator(sigma_by_face)
     # Inside first rectangle.
     self.assert_within(sigma(1.2), [0, 1])
     self.assert_within(sigma(3.6), [0, 1])
     # Inside second rectangle.
     self.assert_within(sigma(1.7), [1, 2])
     # Middle of inner-most rectangle.
     self.assertGreaterEqual(sigma(2.5), 2)
예제 #7
0
 def test_point_data_with_material(self):
     """Test `point_data` method, using `material_by_face` dict."""
     segment = LineString([(2.5, 0), (2.5, 5)])
     profile = mesh.ElevationProfile(self.mesh, segment)
     # `point_material` returns the material at a given point.
     point_material = partial(profile.point_data,
                              face_data=self._material_by_face())
     # Ouside domain.
     self.assertIs(point_material(0.1), mesh.UNSPECIFIED_MATERIAL)
     # Inside first rectangle.
     self.assertEqual(point_material(1.2).id, 0)
     # Inside second rectangle.
     self.assertEqual(point_material(1.7).id, 1)
     # Inside inner-most rectangle.
     self.assertEqual(point_material(2.5).id, 2)
예제 #8
0
 def test_interpolation(self):
     segment = LineString([(2.5, 0), (2.5, 5)])
     profile = mesh.ElevationProfile(self.mesh, segment)
     self.assertEqual(profile(1), 1)
     self.assertEqual(profile(2), 3)
     self.assertTrue(2 < profile(1.7) < 3)
예제 #9
0
 def test_direction(self):
     segment = LineString([(2, 0), (2, 4)])
     profile = mesh.ElevationProfile(self.mesh, segment)
     assert_array_equal(profile.direction, [0, 1])