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))
def make_rupture(rupture_class, **kwargs): default_arguments = { 'mag': 5.5, 'rake': 123.45, 'tectonic_region_type': const.TRT.STABLE_CONTINENTAL, 'hypocenter': Point(5, 6, 7), 'surface': PlanarSurface(10, 11, 12, Point(0, 0, 1), Point(1, 0, 1), Point(1, 0, 2), Point(0, 0, 2)), 'source_typology': object() } default_arguments.update(kwargs) kwargs = default_arguments rupture = rupture_class(**kwargs) for key in kwargs: assert getattr(rupture, key) is kwargs[key] return rupture
def test(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) self.assertEqual(surface.get_top_edge_depth(), 8)
def _test1to7surface(self): corners = [Point(0, 0, 8), Point(-0.1, 0, 8), Point(-0.1, 0, 9), Point(0, 0, 9)] surface = PlanarSurface(1, 90, 60, *corners) return surface
def assert_failed_creation(self, mesh_spacing, strike, dip, corners, exc, msg): with self.assertRaises(exc) as ae: PlanarSurface(mesh_spacing, strike, dip, *corners) self.assertEqual(ae.exception.message, msg)
def test_4(self): surface = PlanarSurface(1, 2, 3, *test_data.TEST_7_RUPTURE_2_CORNERS) sites = Mesh.from_points_list([Point(-0.3, 0.4)]) self.assertAlmostEqual(55.6159556, surface.get_min_distance(sites)[0], delta=0.6)
def test_3(self): surface = PlanarSurface(1, 2, 3, *test_data.TEST_7_RUPTURE_2_CORNERS) sites = Mesh.from_points_list([Point(0, 0)]) self.assertAlmostEqual(7.01186304977, surface.get_min_distance(sites)[0], places=2)
def test_2(self): surface = PlanarSurface(1, 2, 3, *test_data.TEST_7_RUPTURE_6_CORNERS) sites = Mesh.from_points_list([Point(-0.25, 0.25)]) self.assertAlmostEqual(40.1213468, surface.get_min_distance(sites)[0], places=1)
def _surface(self, corners): return PlanarSurface(1.0, 0.0, 90.0, *corners)
def _get_rupture_surface(self, mag, nodal_plane, hypocenter): """ Create and return rupture surface object with given properties. :param mag: Magnitude value, used to calculate rupture dimensions, see :meth:`_get_rupture_dimensions`. :param nodal_plane: Instance of :class:`nhlib.geo.nodalplane.NodalPlane` describing the rupture orientation. :param hypocenter: Point representing rupture's hypocenter. :returns: Instance of :class:`~nhlib.geo.surface.planar.PlanarSurface`. """ assert self.upper_seismogenic_depth <= hypocenter.depth \ and self.lower_seismogenic_depth >= hypocenter.depth rdip = math.radians(nodal_plane.dip) # precalculated azimuth values for horizontal-only and vertical-only # moves from one point to another on the plane defined by strike # and dip: azimuth_right = nodal_plane.strike azimuth_down = (azimuth_right + 90) % 360 azimuth_left = (azimuth_down + 90) % 360 azimuth_up = (azimuth_left + 90) % 360 rup_length, rup_width = self._get_rupture_dimensions(mag, nodal_plane) # calculate the height of the rupture being projected # on the vertical plane: rup_proj_height = rup_width * math.sin(rdip) # and it's width being projected on the horizontal one: rup_proj_width = rup_width * math.cos(rdip) # half height of the vertical component of rupture width # is the vertical distance between the rupture geometrical # center and it's upper and lower borders: hheight = rup_proj_height / 2 # calculate how much shallower the upper border of the rupture # is than the upper seismogenic depth: vshift = self.upper_seismogenic_depth - hypocenter.depth + hheight # if it is shallower (vshift > 0) than we need to move the rupture # by that value vertically. if vshift < 0: # the top edge is below upper seismogenic depth. now we need # to check that we do not cross the lower border. vshift = self.lower_seismogenic_depth - hypocenter.depth - hheight if vshift > 0: # the bottom edge of the rupture is above the lower sesmogenic # depth. that means that we don't need to move the rupture # as it fits inside seismogenic layer. vshift = 0 # if vshift < 0 than we need to move the rupture up by that value. # now we need to find the position of rupture's geometrical center. # in any case the hypocenter point must lie on the surface, however # the rupture center might be off (below or above) along the dip. rupture_center = hypocenter if vshift != 0: # we need to move the rupture center to make the rupture fit # inside the seismogenic layer. hshift = abs(vshift / math.tan(rdip)) rupture_center = rupture_center.point_at( horizontal_distance=hshift, vertical_increment=vshift, azimuth=(azimuth_up if vshift < 0 else azimuth_down)) # now we can find four corner points of the rupture rectangle. # we find the point that is on the same depth than the rupture # center but lies on the right border of its surface: right_center = rupture_center.point_at(horizontal_distance=rup_length / 2.0, vertical_increment=0, azimuth=azimuth_right) # than we get the right bottom corner: right_bottom = right_center.point_at( horizontal_distance=rup_proj_width / 2.0, vertical_increment=rup_proj_height / 2.0, azimuth=azimuth_down) # and other three points can be easily found by stepping from # already known points horizontally only by rupture length # (to get to left point from right one) or horizontally and # vertically (to get to top edge from bottom). right_top = right_bottom.point_at(horizontal_distance=rup_proj_width, vertical_increment=-rup_proj_height, azimuth=azimuth_up) left_top = right_top.point_at(horizontal_distance=rup_length, vertical_increment=0, azimuth=azimuth_left) left_bottom = right_bottom.point_at(horizontal_distance=rup_length, vertical_increment=0, azimuth=azimuth_left) return PlanarSurface(self.rupture_mesh_spacing, nodal_plane.strike, nodal_plane.dip, left_top, right_top, right_bottom, left_bottom)