def kriging3d_block(kriging_type,grid,points,data,vm,discritization=None,mean=None,mindata=1,maxdata=1,azimuth=0.0,dip=0.0,plunge=0.0,search_range=np.inf,anisotropy=[1.0,1.0],full=False,debug=1): if mean is None: mean = np.mean(data) #create kd3 kdtree = KDTree3D(points,azimuth,dip,plunge,anisotropy) if discritization is not None: dblock = grid.discretize(discritization) npd = len(dblock) max_covariance = 0 for dp in dblock: max_covariance += np.sum(vm.covariance(dp,dblock)) max_covariance -= vm.nugget*npd max_covariance /= npd**2 else: dblock = None npd = 1 max_covariance = vm.max_covariance() print("block covariance",max_covariance) n = len(grid) ret = np.empty((n,2)) non_estimated = 0 if full: ret_indices = [] for i,point in enumerate(grid): #print i,point d,indices = kdtree.search(point,maxdata,search_range) if debug >=1: print('est at:',point,'neigborhs len:',len(indices)) if full: ret_indices += [indices] if len(indices) < mindata: estimation = np.nan variance = np.nan non_estimated +=1 else: estimation,variance,A,b,x = kriging_system(kriging_type,vm,max_covariance,point,points[indices,:],data[indices],dblock) if debug >=3: print("ponits:",points[indices]) print("A=",A) print("b=",b) print("x=",x) if debug >=1: print("estimation,variance:",estimation,variance) ret[i,0] = estimation ret[i,1] = variance if full: return ret,non_estimated,ret_indices else: return ret,non_estimated
def kriging3d_cross_validation(kriging_type,points,data,vm,mean=None,mindata=1,maxdata=10,azimuth=0.0,dip=0.0,plunge=0.0,search_range=np.inf,anisotropy=[1.0,1.0],full=False): if mean is None: mean = np.mean(data) #create kd3 kdtree = KDTree3D(points,azimuth,dip,plunge,anisotropy) ret = kriging_cross_validation(kriging_type,points,data,vm,mean,mindata,maxdata,search_range,kdtree,full) return ret
def kriging3d_block_iterator(kriging_type, grid, points, data, vm, discretization=None, mean=None, mindata=1, maxdata=1, azimuth=0.0, dip=0.0, plunge=0.0, search_range=np.inf, anisotropy=[1.0, 1.0], full=False, debug=1): if mean is None: mean = np.mean(data) #create kd3 kdtree = KDTree3D(points, azimuth, dip, plunge, anisotropy) if discretization is not None: dblock = grid.discretize(discretization) npd = len(dblock) max_covariance = 0 for dp in dblock: max_covariance += np.sum(vm.covariance(dp, dblock)) max_covariance -= vm.nugget * npd max_covariance /= npd**2 else: dblock = None npd = 1 max_covariance = vm.max_covariance() print("block covariance", max_covariance) for i, point in enumerate(grid): d, indices = kdtree.search(point, maxdata, search_range) if len(indices) < mindata: estimation = np.nan variance = np.nan else: estimation, variance, A, b, x = kriging_system( kriging_type, vm, max_covariance, point, points[indices, :], data[indices], dblock) if full: yield point, estimation, variance, indices else: yield point, estimation, variance
def kriging3d_puntual(kriging_type, output_points, points, data, vm, mean=None, mindata=1, maxdata=1, azimuth=0.0, dip=0.0, plunge=0.0, search_range=np.inf, anisotropy=[1.0, 1.0], full=False): if mean is None: mean = np.mean(data) #create kd3 kdtree = KDTree3D(points, azimuth, dip, plunge, anisotropy) max_covariance = vm.max_covariance() n = len(points) ret = np.empty((n, 2)) non_estimated = 0 if full: ret_indices = [] for i, point in enumerate(output_points): d, indices = kdtree.search(point, maxdata, search_range) if full: ret_indices += [indices] if len(indices) < mindata: estimation = np.nan variance = np.nan non_estimated += 1 else: estimation, variance, A, b, x = kriging_system( kriging_type, vm, max_covariance, point, points[indices, :], data[indices]) #print A,b,x,estimation,variance,points[indices] ret[i, 0] = estimation ret[i, 1] = variance if full: return ret, non_estimated, ret_indices else: return ret, non_estimated
def kriging3d_block_multipasses(kriging_type,grid,points,tag_in,data,tag_out,vm,discritization=None,mean=None,search_angles=None,search_anisotropy=None,search_passes=None,search_soft=None,full=False,debug=1): if mean is None: mean = np.mean(data) if discritization is not None: dblock = grid.discretize(discritization) npd = len(dblock) max_covariance = 0 for dp in dblock: max_covariance += np.sum(vm.covariance(dp,dblock)) max_covariance -= vm.nugget*npd max_covariance /= npd**2 print("block covariance",max_covariance) else: dblock = None npd = 1 max_covariance = vm.max_covariance() print("covariance",max_covariance) tag_values = list(set(tag_in)) tag_values.sort() n = len(grid) ret = np.empty((n,3)) ret_pass = np.zeros(n,dtype=np.int8) for tag in tag_values: #create kd3 kdtree = [] for search_params in search_passes[tag]: kdtree += [KDTree3D(points,search_params.azimuth,search_params.dip,search_params.plunge,search_params.anisotropy)] kdtree_soft = KDTree3D(points,search_soft.azimuth,search_soft.dip,search_soft.plunge,search_soft.anisotropy) non_estimated = 0 if full: ret_indices = [] for i,point in enumerate(grid): if tag_in[i] == tag: ''' Search is performed by multiple passes ''' data_found = False for j,search_params in enumerate(search_passes): d,indices = kdtree[j].search(point,search_params.maxdata,search_params.range) #filter by this tag #include any softdata for soft_tag in search_params.softdata.keys(): d_soft,indices_soft = kdtree_soft.search(point,soft_params.maxdata_soft,soft_params.range) if len(d) >= search_params.mindata: data_found = True ret_pass[i] = j+1 break if full: ret_indices += [indices] n_data = len(d) + len(d_soft) if debug >=1: print('est at:',point,'neigborhs len:',len(indices)) print('est at:',point,'soft len:',len(indices_soft)) locations_data = np.empty((n_data,3)) locations_data[:len(d),:] = points[indices,:] locations_data[len(d):,:] = points[indices_soft,:] value_data = np.empty(n_data) value_data[:len(d),:] = data[indices] value_data[len(d):,:] = data[indices_soft] estimation,variance,A,b,x = kriging_system(kriging_type,vm,max_covariance,point,locations_data,value_data,dblock) else: estimation = np.nan variance = np.nan non_estimated +=1 if debug >=3: print("ponits:",points[indices]) print("A=",A) print("b=",b) print("x=",x) if debug >=1: print("estimation,variance:",estimation,variance) ret[i,0] = estimation ret[i,1] = variance if full: return ret,non_estimated,ret_indices else: return ret,non_estimated