Exemplo n.º 1
0
 def test_vertical_surf_from_corner_points(self):
     # vertical surface pointing North
     surf = PlanarSurface.from_corner_points(
         Point(0, 0, 0), Point(0, 1, 0), Point(0, 1, 5), Point(0, 0, 5))
     self.assertAlmostEqual(surf.strike, 0.)
     self.assertAlmostEqual(surf.dip, 90.)
     self.assertEqual(surf.top_left, Point(0, 0, 0))
     self.assertEqual(surf.top_right, Point(0, 1, 0))
     self.assertEqual(surf.bottom_left, Point(0, 0, 5))
     self.assertEqual(surf.bottom_right, Point(0, 1, 5))
Exemplo n.º 2
0
 def test_vertical_surf_from_corner_points(self):
     # vertical surface pointing North
     surf = PlanarSurface.from_corner_points(Point(0, 0, 0), Point(0, 1, 0),
                                             Point(0, 1, 5), Point(0, 0, 5))
     self.assertAlmostEqual(surf.strike, 0.)
     self.assertAlmostEqual(surf.dip, 90.)
     self.assertEqual(surf.top_left, Point(0, 0, 0))
     self.assertEqual(surf.top_right, Point(0, 1, 0))
     self.assertEqual(surf.bottom_left, Point(0, 0, 5))
     self.assertEqual(surf.bottom_right, Point(0, 1, 5))
Exemplo n.º 3
0
 def test_inclined_surf_from_corner_points_topo(self):
     # inclined surface (dip = 45) with 45 degrees strike
     surf = PlanarSurface.from_corner_points(
         Point(0, 0, -1), Point(0.5, 0.5, -1),
         Point(0.563593, 0.436408, 9.), Point(0.063592, -0.063592, 9))
     self.assertAlmostEqual(surf.strike, 45., delta=0.1)
     self.assertAlmostEqual(surf.dip, 45., delta=0.1)
     self.assertEqual(surf.top_left, Point(0, 0, -1))
     self.assertEqual(surf.top_right, Point(0.5, 0.5, -1))
     self.assertEqual(surf.bottom_left, Point(0.063592, -0.063592, 9))
     self.assertEqual(surf.bottom_right, Point(0.563593, 0.436408, 9.))
Exemplo n.º 4
0
 def test_inclined_surf_from_corner_points_topo(self):
     # inclined surface (dip = 45) with 45 degrees strike
     surf = PlanarSurface.from_corner_points(
         Point(0, 0, -1), Point(0.5, 0.5, -1),
         Point(0.563593, 0.436408, 9.), Point(0.063592, -0.063592, 9))
     self.assertAlmostEqual(surf.strike, 45., delta=0.1)
     self.assertAlmostEqual(surf.dip, 45., delta=0.1)
     self.assertEqual(surf.top_left, Point(0, 0, -1))
     self.assertEqual(surf.top_right, Point(0.5, 0.5, -1))
     self.assertEqual(surf.bottom_left, Point(0.063592, -0.063592, 9))
     self.assertEqual(surf.bottom_right, Point(0.563593, 0.436408, 9.))
Exemplo n.º 5
0
 def test_vertical_surf_from_corner_points_topo(self):
     # vertical surface pointing North
     surf = PlanarSurface.from_corner_points(
         2., Point(0, 0, -1), Point(0, 1, -1), Point(0, 1, 4), Point(0, 0, 4)
     )
     self.assertEqual(surf.mesh_spacing, 2.)
     self.assertAlmostEqual(surf.strike, 0.)
     self.assertAlmostEqual(surf.dip, 90.)
     self.assertEqual(surf.top_left, Point(0, 0, -1))
     self.assertEqual(surf.top_right, Point(0, 1, -1))
     self.assertEqual(surf.bottom_left, Point(0, 0, 4))
     self.assertEqual(surf.bottom_right, Point(0, 1, 4))
Exemplo n.º 6
0
 def test_inclined_surf_from_corner_points(self):
     # inclined surface (dip = 45) with 45 degrees strike
     surf = PlanarSurface.from_corner_points(
         2.0, Point(0, 0, 0), Point(0.5, 0.5, 0), Point(0.563593, 0.436408, 10.0), Point(0.063592, -0.063592, 10)
     )
     self.assertEqual(surf.mesh_spacing, 2.0)
     self.assertAlmostEqual(surf.strike, 45.0, delta=0.1)
     self.assertAlmostEqual(surf.dip, 45.0, delta=0.1)
     self.assertEqual(surf.top_left, Point(0, 0, 0))
     self.assertEqual(surf.top_right, Point(0.5, 0.5, 0))
     self.assertEqual(surf.bottom_left, Point(0.063592, -0.063592, 10))
     self.assertEqual(surf.bottom_right, Point(0.563593, 0.436408, 10.0))
Exemplo n.º 7
0
 def test_inclined_surf_from_corner_points(self):
     # inclined surface (dip = 45) with 45 degrees strike
     surf = PlanarSurface.from_corner_points(2., Point(0, 0, 0),
                                             Point(0.5, 0.5, 0),
                                             Point(0.563593, 0.436408, 10.),
                                             Point(0.063592, -0.063592, 10))
     self.assertEqual(surf.mesh_spacing, 2.)
     self.assertAlmostEqual(surf.strike, 45., delta=0.1)
     self.assertAlmostEqual(surf.dip, 45., delta=0.1)
     self.assertEqual(surf.top_left, Point(0, 0, 0))
     self.assertEqual(surf.top_right, Point(0.5, 0.5, 0))
     self.assertEqual(surf.bottom_left, Point(0.063592, -0.063592, 10))
     self.assertEqual(surf.bottom_right, Point(0.563593, 0.436408, 10.))
Exemplo n.º 8
0
    def check_surface_validity(cls, edges):
        """
        Check validity of the surface.

        Project edge points to vertical plane anchored to surface upper left
        edge and with strike equal to top edge strike. Check that resulting
        polygon is valid.

        This method doesn't have to be called by hands before creating the
        surface object, because it is called from :meth:`from_fault_data`.
        """
        # extract coordinates of surface boundary (as defined from edges)
        full_boundary = []
        left_boundary = []
        right_boundary = []

        for i in range(1, len(edges) - 1):
            left_boundary.append(edges[i].points[0])
            right_boundary.append(edges[i].points[-1])

        full_boundary.extend(edges[0].points)
        full_boundary.extend(right_boundary)
        full_boundary.extend(edges[-1].points[::-1])
        full_boundary.extend(left_boundary[::-1])

        lons = [p.longitude for p in full_boundary]
        lats = [p.latitude for p in full_boundary]
        depths = [p.depth for p in full_boundary]

        # define reference plane. Corner points are separated by an arbitrary
        # distance of 10 km. The mesh spacing is set to 2 km. Both corner
        # distance and mesh spacing values do not affect the algorithm results.
        ul = edges[0].points[0]
        strike = ul.azimuth(edges[0].points[-1])
        dist = 10.
        mesh_spacing = 2.

        ur = ul.point_at(dist, 0, strike)
        bl = Point(ul.longitude, ul.latitude, ul.depth + dist)
        br = bl.point_at(dist, 0, strike)

        # project surface boundary to reference plane and check for
        # validity.
        ref_plane = PlanarSurface.from_corner_points(
            mesh_spacing, ul, ur, br, bl
        )
        _, xx, yy = ref_plane._project(lons, lats, depths)
        coords = [(x, y) for x, y in zip(xx, yy)]
        p = shapely.geometry.Polygon(coords)
        if not p.is_valid:
            raise ValueError('Edges points are not in the right order')
Exemplo n.º 9
0
    def check_surface_validity(cls, edges):
        """
        Check validity of the surface.

        Project edge points to vertical plane anchored to surface upper left
        edge and with strike equal to top edge strike. Check that resulting
        polygon is valid.

        This method doesn't have to be called by hands before creating the
        surface object, because it is called from :meth:`from_fault_data`.
        """
        # extract coordinates of surface boundary (as defined from edges)
        full_boundary = []
        left_boundary = []
        right_boundary = []

        for i in range(1, len(edges) - 1):
            left_boundary.append(edges[i].points[0])
            right_boundary.append(edges[i].points[-1])

        full_boundary.extend(edges[0].points)
        full_boundary.extend(right_boundary)
        full_boundary.extend(edges[-1].points[::-1])
        full_boundary.extend(left_boundary[::-1])

        lons = [p.longitude for p in full_boundary]
        lats = [p.latitude for p in full_boundary]
        depths = [p.depth for p in full_boundary]

        # define reference plane. Corner points are separated by an arbitrary
        # distance of 10 km. The mesh spacing is set to 2 km. Both corner
        # distance and mesh spacing values do not affect the algorithm results.
        ul = edges[0].points[0]
        strike = ul.azimuth(edges[0].points[-1])
        dist = 10.
        mesh_spacing = 2.

        ur = ul.point_at(dist, 0, strike)
        bl = Point(ul.longitude, ul.latitude, ul.depth + dist)
        br = bl.point_at(dist, 0, strike)

        # project surface boundary to reference plane and check for
        # validity.
        ref_plane = PlanarSurface.from_corner_points(mesh_spacing, ul, ur, br,
                                                     bl)
        _, xx, yy = ref_plane._project(lons, lats, depths)
        coords = [(x, y) for x, y in zip(xx, yy)]
        p = shapely.geometry.Polygon(coords)
        if not p.is_valid:
            raise ValueError('Edges points are not in the right order')
Exemplo n.º 10
0
def get_ucerf_rupture(hdf5,
                      iloc,
                      idx_set,
                      tom,
                      sites,
                      integration_distance,
                      mesh_spacing=DEFAULT_MESH_SPACING,
                      trt=DEFAULT_TRT):
    """
    :param hdf5:
        Source Model hdf5 object as instance of :class: h5py.File
    :param int iloc:
        Location of the rupture plane in the hdf5 file
    :param dict idx_set:
        Set of indices for the branch
    Generates a rupture set from a sample of the background model
    :param tom:
        Temporal occurrence model as instance of :class:
        openquake.hazardlib.tom.TOM
    :param sites:
        Sites for consideration (can be None!)
    """
    ridx = hdf5[idx_set["geol_idx"] + "/RuptureIndex"][iloc]
    surface_set = []
    if not prefilter_ruptures(hdf5, ridx, idx_set, sites,
                              integration_distance):
        return None, None
    for idx in ridx:
        # Build simple fault surface
        trace_idx = "{:s}/{:s}".format(idx_set["sec_idx"], str(idx))
        rup_plane = hdf5[trace_idx + "/RupturePlanes"][:].astype("float64")
        for jloc in range(0, rup_plane.shape[2]):
            top_left = Point(rup_plane[0, 0, jloc], rup_plane[0, 1, jloc],
                             rup_plane[0, 2, jloc])
            top_right = Point(rup_plane[1, 0, jloc], rup_plane[1, 1, jloc],
                              rup_plane[1, 2, jloc])
            bottom_right = Point(rup_plane[2, 0, jloc], rup_plane[2, 1, jloc],
                                 rup_plane[2, 2, jloc])
            bottom_left = Point(rup_plane[3, 0, jloc], rup_plane[3, 1, jloc],
                                rup_plane[3, 2, jloc])
            try:
                surface_set.append(
                    PlanarSurface.from_corner_points(mesh_spacing, top_left,
                                                     top_right, bottom_right,
                                                     bottom_left))
            except ValueError as evl:
                raise ValueError(evl, trace_idx, top_left, top_right,
                                 bottom_right, bottom_left)

    rupture = ParametricProbabilisticRupture(
        hdf5[idx_set["mag_idx"]][iloc],  # Magnitude
        hdf5[idx_set["rake_idx"]][iloc],  # Rake
        trt,  # Tectonic Region Type
        surface_set[len(surface_set) / 2].get_middle_point(),  # Hypocentre
        MultiSurface(surface_set),
        CharacteristicFaultSource,
        hdf5[idx_set["rate_idx"]][iloc],  # Rate of events
        tom)

    # Get rupture index code string
    ridx_string = "-".join(str(val) for val in ridx)
    return rupture, ridx_string
Exemplo n.º 11
0
def get_ucerf_rupture(hdf5, iloc, idx_set, tom, sites,
                      integration_distance, mesh_spacing=DEFAULT_MESH_SPACING,
                      trt=DEFAULT_TRT):
    """
    :param hdf5:
        Source Model hdf5 object as instance of :class: h5py.File
    :param int iloc:
        Location of the rupture plane in the hdf5 file
    :param dict idx_set:
        Set of indices for the branch
    Generates a rupture set from a sample of the background model
    :param tom:
        Temporal occurrence model as instance of :class:
        openquake.hazardlib.tom.TOM
    :param sites:
        Sites for consideration (can be None!)
    """
    ridx = hdf5[idx_set["geol_idx"] + "/RuptureIndex"][iloc]
    surface_set = []
    if not prefilter_ruptures(
            hdf5, ridx, idx_set, sites, integration_distance):
        return None, None
    for idx in ridx:
        # Build simple fault surface
        trace_idx = "{:s}/{:s}".format(idx_set["sec_idx"], str(idx))
        rup_plane = hdf5[trace_idx + "/RupturePlanes"][:].astype("float64")
        for jloc in range(0, rup_plane.shape[2]):
            top_left = Point(rup_plane[0, 0, jloc],
                             rup_plane[0, 1, jloc],
                             rup_plane[0, 2, jloc])
            top_right = Point(rup_plane[1, 0, jloc],
                              rup_plane[1, 1, jloc],
                              rup_plane[1, 2, jloc])
            bottom_right = Point(rup_plane[2, 0, jloc],
                                 rup_plane[2, 1, jloc],
                                 rup_plane[2, 2, jloc])
            bottom_left = Point(rup_plane[3, 0, jloc],
                                rup_plane[3, 1, jloc],
                                rup_plane[3, 2, jloc])
            try:
                surface_set.append(PlanarSurface.from_corner_points(
                    mesh_spacing,
                    top_left,
                    top_right,
                    bottom_right,
                    bottom_left))
            except ValueError as evl:
                raise ValueError(evl, trace_idx, top_left, top_right,
                                 bottom_right, bottom_left)

    rupture = ParametricProbabilisticRupture(
        hdf5[idx_set["mag_idx"]][iloc],  # Magnitude
        hdf5[idx_set["rake_idx"]][iloc],  # Rake
        trt,  # Tectonic Region Type
        surface_set[len(surface_set)/2].get_middle_point(),  # Hypocentre
        MultiSurface(surface_set),
        CharacteristicFaultSource,
        hdf5[idx_set["rate_idx"]][iloc],  # Rate of events
        tom)

    # Get rupture index code string
    ridx_string = "-".join(str(val) for val in ridx)
    return rupture, ridx_string