예제 #1
0
def build_complex_surface_from_edges(foldername):
    """
    :parameter str foldername:
        The folder containing the `edge_*` files
    :return:
        An instance of :class:`openquake.hazardlib.geo.surface`
    """
    #
    # read edges
    tedges = _read_edges(foldername)
    #
    # check edges
    try:
        chks = _check_edges(tedges)
    except ValueError:
        msg = 'Error while checking the edges in {.s}'.format(foldername)
        print(msg)
    #
    # fix edges
    if np.any(chks > 0.):
        for i, chk in enumerate(chks):
            if chk < 0:
                edge = tedges[i]
                tedges[i].points = edge.points[::-1]
                print('flipping')
    #
    # build complex fault surface
    surface = ComplexFaultSurface.from_fault_data(tedges, mesh_spacing=5.0)
    return surface
def fix_source_node(node):
    if node.tag.endswith('complexFaultSource'):
        geom = node.complexFaultGeometry
        top = geom.faultTopEdge
        intermediate = [edge for edge in geom.getnodes('intermediateEdge')]
        bottom = geom.faultBottomEdge
        edges = list(map(make_edge, [top] + intermediate + [bottom]))
        try:
            ComplexFaultSurface.from_fault_data(edges, mesh_spacing=4.)
        except ValueError as excp:
            if AKI_RICH_ERR_MSG in str(excp):
                print(excp)
                print('Reverting edges ...')
                reverse(geom.faultTopEdge)
                reverse(geom.faultBottomEdge)
            elif WRONG_ORDER_ERR_MSG in str(excp):
                print(excp)
                print('reverting bottom edge ...')
                reverse(geom.faultBottomEdge)
            else:
                raise
예제 #3
0
def fix_source_node(node):
    if node.tag.endswith('complexFaultSource'):
        geom = node.complexFaultGeometry
        top = geom.faultTopEdge
        intermediate = [edge for edge in geom.getnodes('intermediateEdge')]
        bottom = geom.faultBottomEdge
        edges = map(make_edge, [top] + intermediate + [bottom])
        try:
            ComplexFaultSurface.from_fault_data(edges, mesh_spacing=4.)
        except ValueError as excp:
            if AKI_RICH_ERR_MSG in str(excp):
                print str(excp)
                print 'Reverting edges ...'
                reverse(geom.faultTopEdge)
                reverse(geom.faultBottomEdge)
            elif WRONG_ORDER_ERR_MSG in str(excp):
                print str(excp)
                print 'reverting bottom edge ...'
                reverse(geom.faultBottomEdge)
            else:
                raise
예제 #4
0
def create_ruptures(folder, mesh_spacing, slab_thickness, h_grid_spacing,
                    v_grid_spacing):
    """
    :parameter path:
        Path to the folder containing a number of edges defining the top of
        the slab.
    :parameter mesh_spacing:
        Mesh spacing used to discretize the complex fault [km]
    :parameter slab_thickness:
        Thickness of the slab [km]
    :parameter h_grid_spacing:
        Horizontal spacing of the grid used to describe the slab
    :parameter v_grid_spacing:
        Vertical spacing of the grid used to describe the slab
    """
    #
    # read the edges from the text files in the user-provided folder
    path = os.path.join(folder, 'edge*.*')
    tedges = []
    for fle in glob.glob(path):
        tedges.append(_read_edge(fle))
    #
    # create the complex fault surface
    surface = ComplexFaultSurface.from_fault_data(tedges,
                                                  mesh_spacing=mesh_spacing)
    #
    # build the lower surface i.e. the surface describing the bottom of the
    # slab
    lower_mesh = create_lower_surface_mesh(surface.mesh, slab_thickness)
    #
    # computing the limits of the grid
    minlo = np.amin([np.amin(lower_mesh.lons), np.amin(surface.mesh.lons)])
    maxlo = np.amax([np.amax(lower_mesh.lons), np.amax(surface.mesh.lons)])
    minla = np.amin([np.amin(lower_mesh.lats), np.amin(surface.mesh.lats)])
    maxla = np.amax([np.amax(lower_mesh.lats), np.amax(surface.mesh.lats)])
    minde = np.amin([np.amin(lower_mesh.depths), np.amin(surface.mesh.depths)])
    maxde = np.amax([np.amax(lower_mesh.depths), np.amax(surface.mesh.depths)])
    #
    # creating the regular grid describing the slab
    grd = Grid3d(minlo, minla, minde, maxlo, maxla, maxde, h_grid_spacing,
                 v_grid_spacing)
    gx, gy, gz = grd.select_nodes_within_two_meshes(surface.mesh, lower_mesh)
    #
    #
    return surface.mesh, lower_mesh, gx, gy, gz, grd
def main(fname_config: str,
         edges_folder: str,
         source_id: str,
         epsilon: float = 0.0,
         selected_msr: str = None):
    """
    Computes the mmax given the path to the folder containing the files with
    edges that describe the subduction interface surface.
    """

    # Load the config file
    config = toml.load(fname_config)

    # Check
    msg = "The config file does not contain information about this source"
    assert source_id in config["sources"], msg

    # Get the TR
    trt = config["sources"][source_id]["tectonic_region_type"]

    msg = "The config file does not contain magnitude-scaling relatioships"
    assert trt in config["msr"], msg

    edges = _read_edges(edges_folder)
    fault_surface = ComplexFaultSurface.from_fault_data(edges, 10.)
    fault_surface_area = fault_surface.get_area()

    fmt = "{:30s}: {:5.2f} {:5.3f} {:5.2f}"
    for i, msr_lab in enumerate(config["msr"][trt]):
        my_class = getattr(MODULE, msr_lab)
        msr = my_class()
        magnitude = msr.get_median_mag(fault_surface_area, 90.0)
        standard_dev = msr.get_std_dev_mag(90.0)
        mag_plus_eps = magnitude + (epsilon * standard_dev)
        print(fmt.format(msr_lab, magnitude, standard_dev, mag_plus_eps))
        tmp = "{:.3f}".format(mag_plus_eps)
        if selected_msr is None and i == 0:
            trt = config["sources"][source_id]["mmax"] = float(tmp)
        elif selected_msr == msr_lab:
            trt = config["sources"][source_id]["mmax"] = float(tmp)

    # Updating the config file
    with open(fname_config, "w") as toml_file:
        toml.dump(config, toml_file)
    """
    assert "complexFaultGeometry" in node.tag
    intermediate_edges = []
    for edge in node.nodes:
        if "faultTopEdge" in edge.tag:
            top_edge = [node_to_edge(edge)]
        elif "faultBottomEdge" in edge.tag:
            bottom_edge = [node_to_edge(edge)]
        elif "intermediateEdge" in edge.tag:
            intermediate_edges.append(node_to_edge(edge))
        else:
            pass
    edges = top_edge + intermediate_edges + bottom_edge
    print [edge.points for edge in edges]
    try:
        surface = ComplexFaultSurface.from_fault_data(edges,
                                                      mesh_spacing)
    except ValueError as excp:
        if AKI_RICH_ERR_MSG in str(excp):
            # Reverse top and bottom edges
            edges[0].points = edges[0].points[::-1]
            edges[-1].points = edges[-1].points[::-1]
        elif WRONG_ORDER_ERR_MSG in str(excp):
            # Revese bottom edge only
            edges[-1].points = edges[-1].points[::-1]
        else:
            raise
        print [edge.points for edge in edges]
        surface = ComplexFaultSurface.from_fault_data(edges,
                                                      mesh_spacing)
    return edges