def compute_model(model: Model, output='geology', compute_mesh=True, reset_weights=False, reset_scalar=False, reset_block=False, sort_surfaces=True, debug=False, set_solutions=True) -> Solution: """ Computes the geological model and any extra output given in the additional data option. Args: model (:obj:`gempy.core.data.Model`) compute_mesh (bool): If true compute polydata Returns: gempy.core.data.Solution """ # TODO: Assert frame by frame that all data is like is supposed. Otherwise, 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' if output == 'geology': assert model.interpolator.theano_function is not None, 'You need to compile the theano function first' 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) elif output == 'gravity': assert isinstance(model.interpolator_gravity, InterpolatorGravity), 'You need to set the gravity interpolator' \ 'first. See `Model.set_gravity_interpolator' i = model.interpolator_gravity.get_python_input_block( append_control=True, fault_drift=None) # TODO So far I reset all shared parameters to be sure. In the future this should be optimize as interpolator model.interpolator_gravity.set_theano_shared_tz_kernel() model.interpolator_gravity.set_all_shared_parameters(reset=True) sol = model.interpolator_gravity.theano_function(*i) set_solutions = False else: raise NotImplementedError( 'Only geology and gravity are implemented so far') if debug is True or set_solutions is False: return sol elif set_solutions is True: if model.grid.active_grids[0] is np.True_: model.solutions.set_solution_to_regular_grid( sol, compute_mesh=compute_mesh) # TODO @elisa elaborate this if model.grid.active_grids[2] is np.True_: l0, l1 = model.grid.get_grid_args('topography') model.solutions.geological_map = sol[0][:, l0:l1] if sort_surfaces: model.set_surface_order_from_solution() return model.solutions
def compute_model(model: Model, output=None, compute_mesh=True, reset_weights=False, reset_scalar=False, reset_block=False, sort_surfaces=True, debug=False, set_solutions=True) -> Solution: """ Computes the geological model and any extra output given in the additional data option. Args: model (:class:`Model`): [s0] output (str {'geology', 'gravity'}): Compute the lithologies or gravity 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 Model.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. Returns: :class:`Solutions` """ # TODO: Assert frame by frame that all data is like is supposed. Otherwise, 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 None: # If output is not passed we check for the type of interpolator. If that also fail # we try simply geology try: output = model.interpolator._type except AttributeError: output = 'geology' if output == 'geology': assert model.interpolator.theano_function is not None, 'You need to compile the theano function first' 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) elif output == 'gravity': model.set_active_grid('centered', reset=False) try: i = model.interpolator.get_python_input_grav(append_control=True, fault_drift=None) sol = model.interpolator.theano_function(*i) except AttributeError: i = model.interpolator_gravity.get_python_input_grav() sol = model.interpolator_gravity.theano_function(*i) # assert isinstance(model.interpolator_gravity, InterpolatorGravity), 'You need to set the gravity interpolator' \ # 'first. See `Model.set_gravity_interpolator' # # model.set_active_grid('centered') # model.interpolator_gravity.modify_results_matrices_pro() # model.interpolator_gravity.set_theano_shared_structure() # # # TODO So far I reset all shared parameters to be sure. In the future this should be optimize as interpolator # model.interpolator_gravity.set_theano_shared_tz_kernel() # # model.interpolator_gravity.set_all_shared_parameters(reset_ctrl=True) # sol = model.interpolator_gravity.theano_function(*i) #set_solutions = False else: raise NotImplementedError( 'Only geology and gravity are implemented so far') if debug is True or set_solutions is False: return sol elif set_solutions is True: if model.grid.active_grids[0] is np.True_: model.solutions.set_solution_to_regular_grid( sol, compute_mesh=compute_mesh) 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) if output == 'gravity': model.solutions.fw_gravity = sol[6] if sort_surfaces: model.set_surface_order_from_solution() return model.solutions
def compute_model(model: Model, output='geology', compute_mesh=True, reset_weights=False, reset_scalar=False, reset_block=False, sort_surfaces=True, debug=False, set_solutions=True) -> Solution: """ Computes the geological model and any extra output given in the additional data option. Args: model (:class:`Model`): [s0] output (str {'geology', 'gravity'}): Compute the lithologies or gravity 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 Model.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. Returns: :class:`Solutions` """ # TODO: Assert frame by frame that all data is like is supposed. Otherwise, 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' if output == 'geology': assert model.interpolator.theano_function is not None, 'You need to compile the theano function first' 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) elif output == 'gravity': assert isinstance(model.interpolator_gravity, InterpolatorGravity), 'You need to set the gravity interpolator' \ 'first. See `Model.set_gravity_interpolator' model.set_active_grid('centered') model.interpolator_gravity.modify_results_matrices_pro() model.interpolator_gravity.set_theano_shared_structure() i = model.interpolator_gravity.get_python_input_block( append_control=True, fault_drift=None) # TODO So far I reset all shared parameters to be sure. In the future this should be optimize as interpolator model.interpolator_gravity.set_theano_shared_tz_kernel() # model.interpolator_gravity.set_all_shared_parameters(reset_ctrl=True) sol = model.interpolator_gravity.theano_function(*i) set_solutions = False else: raise NotImplementedError( 'Only geology and gravity are implemented so far') if debug is True or set_solutions is False: return sol elif set_solutions is True: if model.grid.active_grids[0] is np.True_: model.solutions.set_solution_to_regular_grid( sol, compute_mesh=compute_mesh) if model.grid.active_grids[1] is np.True_: l0, l1 = model.grid.get_grid_args('custom') model.solutions.custom = sol[0][:, l0:l1] # TODO @elisa elaborate this if model.grid.active_grids[2] is np.True_: l0, l1 = model.grid.get_grid_args('topography') model.solutions.geological_map = sol[0][:, l0:l1] model.solutions.geological_map_scalfield = sol[3][:, l0:l1].astype( float) if model.grid.active_grids[3] is np.True_: l0, l1 = model.grid.get_grid_args('sections') model.solutions.sections = sol[0][:, l0:l1] model.solutions.sections_scalfield = sol[3][:, l0:l1].astype(float) if sort_surfaces: model.set_surface_order_from_solution() return model.solutions
def compute_model(model: Model, output=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 (:class:`Model`): [s0] output (str {'geology', 'gravity'}): Compute the lithologies or gravity 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 Model.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. Keyword Args: compute_mesh_options (dict): options for the marching cube function. 1) rescale: True Returns: :class:`Solutions` """ # TODO: Assert frame by frame that all data is like is supposed. Otherwise, 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, ) 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: 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: Set magnetcs and set topology if sort_surfaces: model.set_surface_order_from_solution() return model.solutions