Ejemplo n.º 1
0
def compute_model_at(new_grid: Union[ndarray], model: Project, **kwargs):
    """This function creates a new custom grid and deactivate all the other
    grids and compute the model there:

    This function does the same as  plus the addition functionallity of
        :func:`compute_model`
        passing a given array of points where evaluate the model instead of
        using the :class:`gempy_lite.core.data.GridClass`.

    Args:
        new_grid:
        model (Project):
        kwargs: :func:`compute_model` arguments

    Returns:
        :class:`Solution`
    """
    # #TODO create backup of the mesh and a method to go back to it
    #     set_grid(model, Grid('custom_grid', custom_grid=new_grid))
    warnings.warn('compute_model_at will be deprecated in GemPy 2.2.'
                  'Use argument `at` in compute_model instead', DeprecationWarning)
    model._grid.deactivate_all_grids()
    model.set_custom_grid(new_grid)

    # Now we are good to compute the model again only in the new point
    sol = compute_model(model, set_solutions=False, **kwargs)
    return sol
Ejemplo n.º 2
0
def read_csv(geo_model: Project, path_i=None, path_o=None, **kwargs):
    """
    Args:
        geo_model (Project):
        path_i:
        path_o:
        **kwargs:
    """
    if path_i is not None or path_o is not None:
        try:
            geo_model.read_data(path_i, path_o, **kwargs)
        except KeyError:
            raise KeyError('Loading of CSV file failed. Check if you use commas '
                           'to separate your data.')
    return True
Ejemplo n.º 3
0
def map_stack_to_surfaces(geo_model: Project, mapping_object: Union[dict, pn.Categorical] = None,
                          set_features=True, sort_geometric_data: bool = True, remove_unused_series=True):
    """Mapping which surfaces belongs to which geological feature

    Args:
        geo_model (:class:`gempy.core.model.Project`): [s0]
        mapping_object: [s_mapping_object]
        set_features (bool): If True set missing features from the mapping object
        sort_geometric_data (bool): If True sort the geometric_data according to the new
         order of the stack
        remove_unused_series(bool):

    Returns
        :class:`gempy_lite.core.data.Surfaces`
    """

    geo_model.map_stack_to_surfaces(mapping_object, set_features, sort_geometric_data, remove_unused_series)
    return geo_model._surfaces
Ejemplo n.º 4
0
def update_additional_data(model: Project, update_structure=True, update_kriging=True):
    """
    Args:
        model (Project):
        update_structure:
        update_kriging:
    """
    warnings.warn('This function is going to be deprecated. Use Project.update_additional_data instead',
                  DeprecationWarning)
    return model.update_additional_data(update_structure, update_kriging)
Ejemplo n.º 5
0
def map_series_to_surfaces(geo_model: Project, mapping_object: Union[dict, pn.Categorical] = None,
                           set_series=True, sort_geometric_data: bool = True, remove_unused_series=True):
    """Mapping which surfaces belongs to which geological feature

    Args:
        geo_model (:class:`gempy.core.model.Project`): [s0]
        mapping_object: [s_mapping_object]
        set_series (bool): If True set missing series from the mapping object
        sort_geometric_data (bool): If True sort the geometric_data according to the new
         order of the stack
        remove_unused_series(bool):

    Returns
        :class:`gempy_lite.core.data.Surfaces`
    """
    warnings.warn('Series is going to get renamed to Stack. Please use'
                  '`map_stack_to_surfaces` instead.', DeprecationWarning)

    geo_model.map_stack_to_surfaces(mapping_object, set_series, sort_geometric_data, remove_unused_series)
    return geo_model._surfaces
Ejemplo n.º 6
0
def create_model(project_name='default_project') -> Project:
    """Create a Project object.

    Args:
        project_name (str): Name of the project

    Returns:
        :class:`gempy_lite.core.model.Project`

    See Also:
        :class:`gempy_lite.core.model.Project`

    Notes:
        TODO: Adding saving address
    """
    return Project(project_name)
Ejemplo n.º 7
0
def activate_interactive_df(geo_model: Project, plot_object=None):
    """Experimental: Activate the use of the QgridProjectIntegration: TODO
    evaluate the use of this functionality

    Notes: Since this feature is for advance levels we will keep only object
    oriented functionality. Should we add in the future,

    TODO: copy docstrings to QgridModelIntegration :param geo_model: [s0]
    :param plot_object: GemPy plot object (so far only vtk is available)

    Args:
        geo_model (Project):
        plot_object:

    Returns:
        :class:`QgridModelIntegration`
    """
    try:
        from gempy_lite.core.qgrid_integration import QgridModelIntegration
    except ImportError:
        raise ImportError('qgrid package is not installed. No interactive dataframes available.')
    geo_model.qi = QgridModelIntegration(geo_model, plot_object)
    return geo_model.qi
Ejemplo n.º 8
0
def init_data(geo_model: Project, extent: Union[list, ndarray] = None,
              resolution: Union[list, ndarray] = None,
              **kwargs) -> Project:
    """Initialize some of the main functions such as:

     - Regular grid (:class:`gempy_lite.core.data.Grid`).
     - read_csv: :class:`gempy_lite.core.data_modules.geometric_data.SurfacePoints`
       and :class:`gempy_lite.core.data_modules.geometric_data.Orientations` From csv files
     - set_values to default

    Args:
        geo_model (Project): [s0]
        extent: [s_extent]
        resolution: [s_resolution]

    Keyword Args:
        path_i: [s_path_i]
        path_o: [s_path_o]
        surface_points_df: [s_surface_points_df]
        orientations_df: [s_orientations_df]
    Returns:
        :class:`gempy_lite.core.model.Project`
    """

    if extent is None or resolution is None:
        warnings.warn('Regular grid won\'t be initialize, you will have to create a gridafterwards. See gempy_lite.set_grid')
    else:
        geo_model.set_regular_grid(extent, resolution)

    if 'path_i' in kwargs or 'path_o' in kwargs:
        read_csv(geo_model, **kwargs)

    if 'surface_points_df' in kwargs:
        geo_model.set_surface_points(kwargs['surface_points_df'], **kwargs)
        # if we set the surfaces names with surfaces they cannot be set again on orientations or pandas will complain.
        kwargs['update_surfaces'] = False
    if 'orientations_df' in kwargs:
        geo_model.set_orientations(kwargs['orientations_df'], **kwargs)

    return geo_model
Ejemplo n.º 9
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_lite.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_lite.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