Ejemplo n.º 1
0
def compute_model(model: Project,
                  output=None,
                  at: np.ndarray = None,
                  compute_mesh=True,
                  reset_weights=False,
                  reset_scalar=False,
                  reset_block=False,
                  sort_surfaces=True,
                  debug=False,
                  set_solutions=True,
                  **kwargs) -> Solution:
    """Computes the geological model and any extra output given in the
    additional data option.

    Args:
        model (Project): [s0]
        output (str {'geology', 'gravity'}): Compute the lithologies or gravity
        at (np.ndarray):
        compute_mesh (bool): if True compute marching cubes: [s1]
        reset_weights (bool): Not Implemented
        reset_scalar (bool): Not Implemented
        reset_block (bool): Not Implemented
        sort_surfaces (bool): if True call
            Project.set_surface_order_from_solution: [s2]
        debug (bool): if True, the computed interpolation are not stored in any
            object but instead returned
        set_solutions (bool): Default True. If True set the results into the
            :class:`Solutions` linked object.
        **kwargs:

    Keyword Args:
        compute_mesh_options (dict): options for the marching cube function. 1)
            rescale: True

    Returns:
        :class:`Solutions`
    """

    # Check config
    # ------------
    assert model._interpolator.theano_function is not None, 'You need to compile' \
                                                           'graph before. See `gempy.set_interpolator`.'

    assert model._additional_data.structure_data.df.loc['values', 'len surfaces surface_points'].min() > 1, \
        'To compute the model is necessary at least 2 interface points per layer'
    assert len(model._interpolator.len_series_i) == len(model._interpolator.len_series_o), \
        'Every Series/Fault need at least 1 orientation and 2 surfaces points.'

    if output is not None:
        warnings.warn(
            'Argument output has no effect anymore and will be deprecated in GemPy 2.2.'
            'Set the output only in gempy.set_interpolator.',
            DeprecationWarning,
        )
    if at is not None:
        model._grid.deactivate_all_grids()
        model.set_custom_grid(at)

    # ------------

    i = model._interpolator.get_python_input_block(append_control=True,
                                                   fault_drift=None)
    model._interpolator.reset_flow_control_initial_results(
        reset_weights, reset_scalar, reset_block)

    sol = model._interpolator.theano_function(*i)

    if debug is True or set_solutions is False:
        return sol

    elif set_solutions is True:

        # Set geology:
        model.solutions.set_values_to_surface_points(sol)

        if model._grid.active_grids[0] is np.True_:
            model.solutions.set_solution_to_regular_grid(
                sol, compute_mesh=compute_mesh, **kwargs)
        if model._grid.active_grids[1] is np.True_:
            model.solutions.set_solution_to_custom(sol)
        if model._grid.active_grids[2] is np.True_:
            model.solutions.set_solution_to_topography(sol)
        if model._grid.active_grids[3] is np.True_:
            model.solutions.set_solution_to_sections(sol)
        # Set gravity
        model.solutions.fw_gravity = sol[12]

        # TODO: [X] Set magnetcs and [ ] set topology @A.Schaaf probably it should populate the topology object?
        model.solutions.fw_magnetics = sol[13]

        if sort_surfaces:
            model.set_surface_order_from_solution()
        return model.solutions
Ejemplo n.º 2
0
def compute_model(model: Project,
                  output=None,
                  at: np.ndarray = None,
                  compute_mesh=True,
                  reset_weights=False,
                  reset_scalar=False,
                  reset_block=False,
                  sort_surfaces=True,
                  debug=False,
                  set_solutions=True,
                  **kwargs) -> Solution:
    """Computes the geological model and any extra output given in the
    additional data option.

    Args:
        model (Project): [s0]
        output (str {'geology', 'gravity'}): Compute the lithologies or gravity
        at (np.ndarray):
        compute_mesh (bool): if True compute marching cubes: [s1]
        reset_weights (bool): Not Implemented
        reset_scalar (bool): Not Implemented
        reset_block (bool): Not Implemented
        sort_surfaces (bool): if True call
            Project.set_surface_order_from_solution: [s2]
        debug (bool): if True, the computed interpolation are not stored in any
            object but instead returned
        set_solutions (bool): Default True. If True set the results into the
            :class:`Solutions` linked object.
        **kwargs:

    Keyword Args:
        compute_mesh_options (dict): options for the marching cube function. 1)
            rescale: True

    Returns:
        :class:`Solutions`
    """

    # Check config
    # ------------
    _check_valid_model_input(model)

    if output is not None:
        warnings.warn(
            'Argument output has no effect anymore and will be deprecated in GemPy 2.2.'
            'Set the output only in gempy.set_interpolator.',
            DeprecationWarning,
        )
    if at is not None:
        model._grid.deactivate_all_grids()
        model.set_custom_grid(at)

    # ------------

    i = model._interpolator.get_python_input_block(append_control=True,
                                                   fault_drift=None)
    model._interpolator.reset_flow_control_initial_results(
        reset_weights, reset_scalar, reset_block)

    sol = model._interpolator.theano_function(*i)

    if debug is True or set_solutions is False:
        return sol

    elif set_solutions is True:

        model.solutions.set_solutions(sol, compute_mesh, sort_surfaces,
                                      **kwargs)

        if sort_surfaces:
            model.set_surface_order_from_solution()
        return model.solutions