def execute(self): #aqui vai o codigo #getting variables pts_grid = self.params['gridselectorbasic']['value'] pts_props = self.params['orderedpropertyselector']['value'].split(';') grids_grid = self.params['gridselectorbasic_2']['value'] grids_props = self.params['orderedpropertyselector_2']['value'].split( ';') flname_pts = self.params['filechooser']['value'] flname_grid = self.params['filechooser_2']['value'] if len(pts_props) != 0: x, y, z = np.array(sgems.get_X(pts_grid)), np.array( sgems.get_Y(pts_grid)), np.array(sgems.get_Z(pts_grid)) vardict = {} for v in pts_props: values = np.array(sgems.get_property(pts_grid, v)) vardict[v] = values pointsToVTK(flname_pts, x, y, z, data=vardict) print('Point set saved to {}'.format(flname_pts)) if len(grids_props) != 0: X, Y, Z = grid_vertices(grids_grid) vardict = {} for v in grids_props: values = np.array(sgems.get_property(grids_grid, v)) vardict[v] = values gridToVTK(flname_grid, X, Y, Z, cellData=vardict) print('Grid saved to {}'.format(flname_grid)) return True
def execute(self): #aqui vai o codigo #getting variables grid_name = self.params['rt_prop']['grid'] prop_name = self.params['rt_prop']['property'] prop_values = sgems.get_property(grid_name, prop_name) prop_values = np.array(prop_values) point_transform_type = self.params['comboBox']['value'] if point_transform_type == 'Indicators': #calculating indicators nan_filter = np.isfinite(prop_values) unique_rts = np.unique(prop_values[nan_filter]) for rt in unique_rts: print('calculating indicators for rock type {}'.format(int(rt))) ind_prop = prop_values == rt ind_prop = np.where(ind_prop == True, 1., 0.) ind_prop[~nan_filter] = float('nan') indprop_name = 'indicators_rt_{}'.format(int(rt)) sgems.set_property(grid_name, indprop_name, ind_prop.tolist()) else: x, y, z = np.array(sgems.get_X(grid_name)), np.array(sgems.get_Y(grid_name)), np.array(sgems.get_Z(grid_name)) coords_matrix = np.vstack((x,y,z)).T #calculating signed distances nan_filter = np.isfinite(prop_values) unique_rts = np.unique(prop_values[nan_filter]) for rt in unique_rts: print('calculating signed distances for rock type {}'.format(int(rt))) filter_0 = prop_values != rt filter_1 = prop_values == rt points_0 = coords_matrix[filter_0] points_1 = coords_matrix[filter_1] sd_prop = [] for idx, pt in enumerate(prop_values): if np.isnan(pt): sd_prop.append(float('nan')) else: point = coords_matrix[idx] if pt == rt: sd_prop.append(-min_dist(point, points_0)) else: sd_prop.append(min_dist(point, points_1)) sgems.set_property(grid_name, 'signed_distances_rt_{}'.format(int(rt)), sd_prop) return True
def execute(self): #aqui vai o codigo #getting variables tg_grid_name = self.params['gridselector']['value'] tg_region_name = self.params['gridselector']['region'] tg_prop_name = self.params['lineEdit']['value'] keep_variables = self.params['checkBox_2']['value'] props_grid_name = self.params['gridselectorbasic']['value'] var_names = self.params['orderedpropertyselector']['value'].split(';') codes = [v.split('_')[-1] for v in var_names] dcf_param = self.params['comboBox_2']['value'] f_min_o = float(self.params['doubleSpinBox']['value']) f_min_p = float(self.params['doubleSpinBox_2']['value']) acceptance = [ float(i) for i in self.params['lineEdit_9']['value'].split(',') ] if len(acceptance) == 1 and len(codes) > 1: acceptance = acceptance * len(codes) acceptance = np.array(acceptance) #kernels variables function = self.params['comboBox']['value'] supports = [ float(i) for i in self.params['lineEdit_5']['value'].split(',') ] azms = [ float(i) for i in self.params['lineEdit_2']['value'].split(',') ] dips = [ float(i) for i in self.params['lineEdit_3']['value'].split(',') ] rakes = [ float(i) for i in self.params['lineEdit_4']['value'].split(',') ] nuggets = [ float(i) for i in self.params['lineEdit_6']['value'].split(',') ] major_med = [ float(i) for i in self.params['lineEdit_7']['value'].split(',') ] major_min = [ float(i) for i in self.params['lineEdit_8']['value'].split(',') ] kernels_par = { 'supports': supports, 'azms': azms, 'dips': dips, 'rakes': rakes, 'nuggets': nuggets, 'major_meds': major_med, 'major_mins': major_min } for key in kernels_par: if len(kernels_par[key]) == 1 and len(codes) > 1: kernels_par[key] = kernels_par[key] * len(codes) kernels_par['function'] = [function] * len(codes) print(kernels_par) #getting coordinates variables = [] nan_filters = [] for v in var_names: values = np.array(sgems.get_property(props_grid_name, v)) nan_filter = np.isfinite(values) filtered_values = values[nan_filter] nan_filters.append(nan_filter) variables.append(filtered_values) nan_filter = np.product(nan_filters, axis=0) nan_filter = nan_filter == 1 x, y, z = np.array(sgems.get_X(props_grid_name))[nan_filter], np.array( sgems.get_Y(props_grid_name))[nan_filter], np.array( sgems.get_Z(props_grid_name))[nan_filter] #Interpolating variables a2g_grid = helpers.ar2gemsgrid_to_ar2gasgrid(tg_grid_name, tg_region_name) print('Computing results by RBF using a {} kernel...'.format(function)) interpolated_variables = {} for idx, v in enumerate(variables): rt = int(codes[idx]) interpolated_variables[rt] = {} print('Interpolating RT {}'.format(rt)) if kernels_par['supports'][idx] == 0: mask = v < 0 kernels_par['supports'][idx] = helpers.max_dist( x, y, z, mask, a2g_grid) print('Estimated support is {}'.format( kernels_par['supports'][idx])) rbf = RBF(x, y, z, v, function=kernels_par['function'][idx], nugget=kernels_par['nuggets'][idx], support=kernels_par['supports'][idx], major_med=kernels_par['major_meds'][idx], major_min=kernels_par['major_mins'][idx], azimuth=kernels_par['azms'][idx], dip=kernels_par['dips'][idx], rake=kernels_par['rakes'][idx]) dc_param = dc_parametrization(v, dcf_param, f_min_o, f_min_p) for t in dc_param: print('Working on {}...'.format(t)) rbf.train(dc_param[t]) results = rbf.predict(a2g_grid) interpolated_variables[rt][t] = results if keep_variables == '1': prop_name = 'interpolated_' + tg_prop_name + '_' + dcf_param + '_' + t + '_' + str( rt) sgems.set_property(tg_grid_name, prop_name, results.tolist()) print('Done!') #Generating geological models print('Building geomodel...') #getting closest node to each sample ids = [ sgems.get_closest_nodeid(tg_grid_name, xi, yi, zi) for xi, yi, zi in zip(x, y, z) ] rt_prop = sd_to_cat(variables, codes) build_geomodels(interpolated_variables, codes, tg_grid_name, tg_prop_name, ids, acceptance, rt_prop) print('Done!') return True
def execute(self): #aqui vai o codigo #getting variables point_set_name = self.params['gridselectorbasic']['value'] new_grid_name = self.params['lineEdit']['value'] buffer = float(self.params['doubleSpinBox_4']['value']) sx, sy, sz = float(self.params['doubleSpinBox']['value']), float(self.params['doubleSpinBox_2']['value']), float(self.params['doubleSpinBox_3']['value']) x, y, z = np.array(sgems.get_X(point_set_name)), np.array(sgems.get_Y(point_set_name)), np.array(sgems.get_Z(point_set_name)) grid_dic = autogrid(x, y, z, sx, sy, sz, buffer) sgems.execute('NewCartesianGrid {}::{}::{}::{}::{}::{}::{}::{}::{}::{}::0,00'.format(new_grid_name, grid_dic['nx'], grid_dic['ny'], grid_dic['nz'], grid_dic['sx'], grid_dic['sy'], grid_dic['sz'], grid_dic['ox'], grid_dic['oy'], grid_dic['oz'])) return True
def execute(self): #aqui vai o codigo #getting variables tg_grid_name = self.params['gridselector']['value'] tg_region_name = self.params['gridselector']['region'] tg_prop_name = self.params['lineEdit']['value'] keep_variables = self.params['checkBox_2']['value'] props_grid_name = self.params['gridselectorbasic']['value'] var_names = self.params['orderedpropertyselector']['value'].split(';') codes = [v.split('_')[-1] for v in var_names] var_type = 'Signed Distances' variables = [] nan_filters = [] for v in var_names: values = np.array(sgems.get_property(props_grid_name, v)) nan_filter = np.isfinite(values) filtered_values = values[nan_filter] nan_filters.append(nan_filter) variables.append(filtered_values) nan_filter = np.product(nan_filters, axis=0) nan_filter = nan_filter == 1 x, y, z = np.array(sgems.get_X(props_grid_name))[nan_filter], np.array( sgems.get_Y(props_grid_name))[nan_filter], np.array( sgems.get_Z(props_grid_name))[nan_filter] #sim variables n_reals = int(self.params['spinBox']['value']) n_lines = int(self.params['spinBox_2']['value']) p_factor = float(self.params['doubleSpinBox']['value']) seed = int(self.params['spinBox_3']['value']) acceptance = [ float(i) for i in self.params['lineEdit_2']['value'].split(',') ] if len(acceptance) == 1 and len(codes) > 1: acceptance = acceptance * len(codes) acceptance = np.array(acceptance) #getting variograms for interpolation print('Getting variogram models') use_model_file = self.params['checkBox']['value'] if use_model_file == '1': path = self.params['filechooser']['value'] variograms = helpers.modelfile_to_ar2gasmodel(path) if len(variograms) == 1: values_covs = list(variograms.values()) varg_lst = values_covs * len(codes) variograms = {} variograms[0] = varg_lst[0] else: p = self.params varg_lst = helpers.ar2gemsvarwidget_to_ar2gascovariance(p) if len(varg_lst) == 0: variograms = {} if len(varg_lst) == 1: varg_lst = varg_lst * len(codes) variograms = {} variograms[0] = varg_lst[0] else: variograms = dict(zip(codes, varg_lst)) #getting variograms for simulation use_model_file = self.params['checkBox_3']['value'] if use_model_file == '1': path = self.params['filechooser_2']['value'] sim_variograms = helpers.modelfile_to_ar2gasmodel(path) if len(variograms) == 1: values_covs = list(sim_variograms.values()) varg_lst = values_covs * len(codes) sim_variograms = {} sim_variograms[0] = varg_lst[0] else: p = self.params varg_lst = helpers.ar2gemsvarwidget_to_ar2gascovariance_sim(p) if len(varg_lst) == 0: sim_variograms = {} if len(varg_lst) == 1: varg_lst = varg_lst * len(codes) sim_variograms = {} sim_variograms[0] = varg_lst[0] else: sim_variograms = dict(zip(codes, varg_lst)) ids = [ sgems.get_closest_nodeid(tg_grid_name, xi, yi, zi) for xi, yi, zi in zip(x, y, z) ] rt_prop = sd_to_cat(variables, codes) #interpolating variables num_models = [] for idx in range(n_reals): print('Working on realization {}...'.format(idx + 1)) tg_prop_name_temp = tg_prop_name + '_real_{}'.format(idx) perturbed_variables = perturb_sd(x, y, z, variables, codes, sim_variograms, seed, n_lines, p_factor) seed = seed + 1 a2g_grid = helpers.ar2gemsgrid_to_ar2gasgrid( tg_grid_name, tg_region_name) interpolated_variables = interpolate_variables( x, y, z, perturbed_variables, codes, a2g_grid, variograms, keep_variables, var_type, tg_prop_name_temp, tg_grid_name) #creating a geologic model build_geomodel(var_type, interpolated_variables, codes, a2g_grid, tg_grid_name, tg_prop_name_temp, ids, acceptance, rt_prop, num_models) print('{} geologic models accepted!'.format(len(num_models))) print('Finished!') return True
def execute(self): #aqui vai o codigo #getting variables tg_grid_name = self.params['gridselector']['value'] tg_region_name = self.params['gridselector']['region'] tg_prop_name = self.params['lineEdit']['value'] prop_grid_name = self.params['propertyselectornoregion']['grid'] prop_name = self.params['propertyselectornoregion']['property'] cmin = str_to_float(self.params['lineEdit_3']['value']) cmax = str_to_float(self.params['lineEdit_2']['value']) gamma_min = str_to_float(self.params['lineEdit_5']['value']) gamma_max = str_to_float(self.params['lineEdit_4']['value']) n = int(self.params['spinBox']['value']) n_folds = int(self.params['spinBox_2']['value']) values = np.array(sgems.get_property(prop_grid_name, prop_name)) nan_filter = np.isfinite(values) y_val = values[nan_filter] x, y, z = np.array(sgems.get_X(prop_grid_name))[nan_filter], np.array( sgems.get_Y(prop_grid_name))[nan_filter], np.array( sgems.get_Z(prop_grid_name))[nan_filter] X = np.array([x, y, z]).T grid = helpers.ar2gemsgrid_to_ar2gasgrid(tg_grid_name, tg_region_name) X_new = grid.locations() #scaling scaler = MinMaxScaler(feature_range=(0, 1)) X = scaler.fit_transform(X) X_new = scaler.fit_transform(X_new) #grid search parameters C = np.linspace(cmin, cmax, n) gamma = np.linspace(gamma_min, gamma_max, n) param_grid = [ { 'estimator__C': C, 'estimator__gamma': gamma, 'estimator__kernel': ["rbf"] * n }, ] #clf print("Tunning parameters...") clf = OneVsOneClassifier(SVC()) model_tunning = GridSearchCV(clf, param_grid=param_grid, cv=n_folds) model_tunning.fit(X, y_val) print('accuracy ', model_tunning.best_score_) print('parameters', model_tunning.best_params_) clf = model_tunning.best_estimator_ print("Predicting...") clf.fit(X, y_val) results = clf.predict(X_new) tp = np.ones(grid.size_of_mask()) * float('nan') if hasattr( grid, 'mask') else np.ones(grid.size()) * float('nan') if hasattr(grid, 'mask'): mask = grid.mask() r_idx = 0 for idx, val in enumerate(mask): if val == True: tp[idx] = results[r_idx] r_idx = r_idx + 1 else: tp = results sgems.set_property(tg_grid_name, tg_prop_name, tp.tolist()) print('Done!') return True
def execute(self): #aqui vai o codigo #getting variables var_type = self.params['comboBox']['value'] tg_grid_name = self.params['gridselector']['value'] tg_region_name = self.params['gridselector']['region'] tg_prop_name = self.params['lineEdit']['value'] keep_variables = self.params['checkBox_2']['value'] props_grid_name = self.params['gridselectorbasic']['value'] var_names = self.params['orderedpropertyselector']['value'].split(';') codes = [v.split('_')[-1] for v in var_names] #getting variograms print('Getting variogram models') variables = [] nan_filters = [] for v in var_names: values = np.array(sgems.get_property(props_grid_name, v)) nan_filter = np.isfinite(values) filtered_values = values[nan_filter] nan_filters.append(nan_filter) variables.append(filtered_values) nan_filter = np.product(nan_filters, axis=0) nan_filter = nan_filter == 1 x, y, z = np.array(sgems.get_X(props_grid_name))[nan_filter], np.array( sgems.get_Y(props_grid_name))[nan_filter], np.array( sgems.get_Z(props_grid_name))[nan_filter] use_model_file = self.params['checkBox']['value'] if use_model_file == '1': path = self.params['filechooser']['value'] variograms = helpers.modelfile_to_ar2gasmodel(path) if len(variograms) == 1: values_covs = list(variograms.values()) varg_lst = values_covs * len(codes) variograms = {} variograms[0] = varg_lst[0] else: p = self.params varg_lst = helpers.ar2gemsvarwidget_to_ar2gascovariance(p) if len(varg_lst) == 0: variograms = {} if len(varg_lst) == 1: varg_lst = varg_lst * len(codes) variograms = {} variograms[0] = varg_lst[0] else: variograms = dict(zip(codes, varg_lst)) #interpolating variables a2g_grid = helpers.ar2gemsgrid_to_ar2gasgrid(tg_grid_name, tg_region_name) interpolated_variables = interpolate_variables( x, y, z, variables, codes, a2g_grid, variograms, keep_variables, var_type, tg_prop_name, tg_grid_name) #creating a geologic model geomodel = build_geomodel(var_type, interpolated_variables, codes, a2g_grid, tg_grid_name, tg_prop_name) #Refining model iterations = int(self.params['iterations']['value']) fx, fy, fz = int(self.params['fx']['value']), int( self.params['fy']['value']), int(self.params['fz']['value']) if iterations > 0: if len(variables) == 1: print( 'Sorry! Refinemnt works only for multicategorical models.') return False grid = a2g_grid geomodel = geomodel if tg_region_name != '': region = sgems.get_region(tg_grid_name, tg_region_name) for i in range(iterations): print('Refinemnt iteration {}'.format(i + 1)) print('Defining refinment zone...') ref_zone, indices = refinement_zone(grid, geomodel) if tg_region_name != '': downscaled_grid, downscaled_props = helpers.downscale_properties( grid, [ref_zone, geomodel, np.array(region)], fx, fy, fz) region = downscaled_props[2] m1 = np.array(downscaled_props[0] == -999) m2 = np.array(downscaled_props[2] == 1) mask = m1 * m2 mask = np.where(mask == 1, True, False).tolist() nx, ny, nz = downscaled_grid.dim()[0], downscaled_grid.dim( )[1], downscaled_grid.dim()[2] sx, sy, sz = downscaled_grid.cell_size( )[0], downscaled_grid.cell_size( )[1], downscaled_grid.cell_size()[2] ox, oy, oz = downscaled_grid.origin( )[0], downscaled_grid.origin()[1], downscaled_grid.origin( )[2] downscaled_grid = ar2gas.data.CartesianGrid( nx, ny, nz, sx, sy, sz, ox, oy, oz) else: downscaled_grid, downscaled_props = helpers.downscale_properties( grid, [ref_zone, geomodel], fx, fy, fz) mask = downscaled_props[0] == -999 grid = downscaled_grid grid_name = tg_grid_name + '_' + tg_prop_name + '_iteration_{}'.format( i + 1) helpers.ar2gasgrid_to_ar2gems(grid_name, grid) masked_grid = ar2gas.data.MaskedGrid(downscaled_grid, mask) interpolated_variables = interpolate_variables( x, y, z, variables, codes, masked_grid, variograms, keep_variables, var_type, tg_prop_name, grid_name) geomodel = build_refined_geomodel(interpolated_variables, downscaled_props, codes, var_type) sgems.set_property(grid_name, tg_prop_name, geomodel) print('Finished!') return True