def set_interpolator(geo_model: Model, output: list = None, compile_theano: bool = True, theano_optimizer=None, verbose: list = None, grid=None, type_=None, update_structure=True, update_kriging=True, **kwargs): """ Method to create a graph and compile the theano code to compute the interpolation. Args: geo_model (:class:`Model`): [s0] output (list[str:{geo, grav}]): type of interpolation. compile_theano (bool): [s1] theano_optimizer (str {'fast_run', 'fast_compile'}): [s2] verbose: kwargs: - pos_density (Optional[int]): Only necessary when type='grav'. Location on the Surfaces().df where density is located (starting on id being 0). - Vs - pos_magnetics - Returns: """ # output = list(output) if output is None: output = ['geology'] if type(output) is not list: raise TypeError('Output must be a list.') # TODO Geology is necessary for everthing? if 'gravity' in output and 'geology' not in output: output.append('geology') if 'magnetics' in output and 'geology' not in output: output.append('geology') if type_ is not None: warnings.warn('type warn is going to be deprecated. Use output insted', FutureWarning) output = type_ if theano_optimizer is not None: geo_model.additional_data.options.df.at[ 'values', 'theano_optimizer'] = theano_optimizer if verbose is not None: geo_model.additional_data.options.df.at['values', 'verbosity'] = verbose geo_model.interpolator.create_theano_graph(geo_model.additional_data, inplace=True, output=output, **kwargs) # TODO add kwargs geo_model.rescaling.rescale_data() update_additional_data(geo_model, update_structure=update_structure, update_kriging=update_kriging) geo_model.surface_points.sort_table() geo_model.orientations.sort_table() if 'gravity' in output: pos_density = kwargs.get('pos_density', 1) tz = kwargs.get('tz', 'auto') geo_model.interpolator.set_theano_shared_gravity(tz, pos_density) # if tz is 'auto' and geo_model.grid.centered_grid is not None: # print('Calculating the tz components for the centered grid...') # #tz = geo_model.interpolator.calculate_tz() # from gempy.assets.geophysics import GravityPreprocessing # g = GravityPreprocessing(geo_model.grid.centered_grid) # tz = g.set_tz_kernel() # print('Done') # # # Set the shared parameters for this piece of tree # # TODO: gravity_interpolator methods should be inherited by interpolator # # geo_model.interpolator.theano_graph.tz.set_value(tz.astype(geo_model.interpolator.dtype)) # geo_model.interpolator.theano_graph.pos_density.set_value(pos_density) # geo_model.interpolator.theano_graph.lg0.set_value(geo_model.grid.get_grid_args('centered')[0]) # geo_model.interpolator.theano_graph.lg1.set_value(geo_model.grid.get_grid_args('centered')[1]) if 'magnetics' in output: pos_magnetics = kwargs.get('pos_magnetics', 1) Vs = kwargs.get('Vs', 'auto') incl = kwargs.get('incl') decl = kwargs.get('decl') B_ext = kwargs.get('B_ext', 52819.8506939139e-9) geo_model.interpolator.set_theano_shared_magnetics( Vs, pos_magnetics, incl, decl, B_ext) if 'topology' in output: # This id is necessary for topology id_list = geo_model.surfaces.df.groupby('isFault').cumcount() + 1 geo_model.add_surface_values(id_list, 'topology_id') geo_model.interpolator.set_theano_shared_topology() # TODO it is missing to pass to theano the position of topology_id if compile_theano is True: geo_model.interpolator.set_all_shared_parameters(reset_ctrl=True) geo_model.interpolator.compile_th_fn_geo(inplace=True, grid=grid) else: if grid == 'shared': geo_model.interpolator.set_theano_shared_grid(grid) return geo_model.interpolator
def set_interpolator(geo_model: Model, output: list = None, compile_theano: bool = True, theano_optimizer=None, verbose: list = None, grid=None, type_=None, update_structure=True, update_kriging=True, **kwargs): """ Method to create a graph and compile the theano code to compute the interpolation. Args: geo_model (:class:`gempy.core.model.Project`): [s0] output (list[str:{geo, grav}]): type of interpolation. compile_theano (bool): [s1] theano_optimizer (str {'fast_run', 'fast_compile'}): [s2] verbose: update_kriging (bool): reset kriging values to its default. update_structure (bool): sync Structure instance before setting theano graph. Keyword Args: - pos_density (Optional[int]): Only necessary when type='grav'. Location on the Surfaces().df where density is located (starting on id being 0). - Vs - pos_magnetics Returns: """ # output = list(output) if output is None: output = ['geology'] if type(output) is not list: raise TypeError('Output must be a list.') # TODO Geology is necessary for everthing? if 'gravity' in output and 'geology' not in output: output.append('geology') if 'magnetics' in output and 'geology' not in output: output.append('geology') if type_ is not None: warnings.warn('type warn is going to be deprecated. Use output insted', FutureWarning) output = type_ if theano_optimizer is not None: geo_model._additional_data.options.df.at['values', 'theano_optimizer'] = theano_optimizer if verbose is not None: geo_model._additional_data.options.df.at['values', 'verbosity'] = verbose if 'dtype' in kwargs: geo_model._additional_data.options.df.at['values', 'dtype'] = kwargs['dtype'] if 'device' in kwargs: geo_model._additional_data.options.df.at['values', 'device'] = kwargs['device'] # TODO add kwargs geo_model._rescaling.rescale_data() geo_model.update_additional_data(update_structure=update_structure, update_kriging=update_kriging) geo_model.update_to_interpolator() geo_model._surface_points.sort_table() geo_model._orientations.sort_table() geo_model._interpolator.create_theano_graph(geo_model._additional_data, inplace=True, output=output, **kwargs) if 'gravity' in output: pos_density = kwargs.get('pos_density', 1) tz = kwargs.get('tz', 'auto') if geo_model._grid.centered_grid is not None: geo_model._interpolator.set_theano_shared_gravity(tz, pos_density) if 'magnetics' in output: pos_magnetics = kwargs.get('pos_magnetics', 1) Vs = kwargs.get('Vs', 'auto') incl = kwargs.get('incl') decl = kwargs.get('decl') B_ext = kwargs.get('B_ext', 52819.8506939139e-9) if geo_model._grid.centered_grid is not None: geo_model._interpolator.set_theano_shared_magnetics(Vs, pos_magnetics, incl, decl, B_ext) if 'topology' in output: # This id is necessary for topology id_list = geo_model._surfaces.df.groupby('isFault').cumcount() + 1 geo_model.add_surface_values(id_list, 'topology_id') geo_model._interpolator.set_theano_shared_topology() # TODO it is missing to pass to theano the position of topology_id if compile_theano is True: geo_model._interpolator.set_all_shared_parameters(reset_ctrl=True) geo_model._interpolator.compile_th_fn_geo(inplace=True, grid=grid) else: if grid == 'shared': geo_model._interpolator.set_theano_shared_grid(grid) print('Kriging values: \n', geo_model._additional_data.kriging_data) return geo_model._interpolator