def __call__(self, pos, mesh_type="unstructured"): """ Generate the ordinary kriging field. The field is saved as `self.field` and is also returned. Parameters ---------- pos : :class:`list` the position tuple, containing main direction and transversal directions (x, [y, z]) mesh_type : :class:`str` 'structured' / 'unstructured' Returns ------- field : :class:`numpy.ndarray` the kriged field krige_var : :class:`numpy.ndarray` the kriging error variance """ # internal conversation x, y, z = pos2xyz(pos, dtype=np.double, max_dim=self.model.dim) c_x, c_y, c_z = pos2xyz(self.cond_pos, dtype=np.double, max_dim=self.model.dim) self.pos = xyz2pos(x, y, z) self.mesh_type = mesh_type # format the positional arguments of the mesh check_mesh(self.model.dim, x, y, z, mesh_type) mesh_type_changed = False if mesh_type == "structured": mesh_type_changed = True mesh_type_old = mesh_type mesh_type = "unstructured" x, y, z, axis_lens = reshape_axis_from_struct_to_unstruct( self.model.dim, x, y, z) if self.model.do_rotation: x, y, z = unrotate_mesh(self.model.dim, self.model.angles, x, y, z) c_x, c_y, c_z = unrotate_mesh(self.model.dim, self.model.angles, c_x, c_y, c_z) y, z = make_isotropic(self.model.dim, self.model.anis, y, z) c_y, c_z = make_isotropic(self.model.dim, self.model.anis, c_y, c_z) # set condtions cond = np.concatenate((self.cond_val, [0])) krig_mat = inv(self._get_krig_mat((c_x, c_y, c_z), (c_x, c_y, c_z))) krig_vecs = self._get_vario_mat((c_x, c_y, c_z), (x, y, z), add=True) # generate the kriged field field, krige_var = krigesum(krig_mat, krig_vecs, cond) # calculate the estimated mean (kriging field at infinity) mean_est = np.concatenate((np.full_like(self.cond_val, self.model.sill), [1])) self.mean = np.einsum("i,ij,j", cond, krig_mat, mean_est) # reshape field if we got an unstructured mesh if mesh_type_changed: mesh_type = mesh_type_old field = reshape_field_from_unstruct_to_struct( self.model.dim, field, axis_lens) krige_var = reshape_field_from_unstruct_to_struct( self.model.dim, krige_var, axis_lens) # save the field self.krige_var = krige_var self.field = field return self.field, self.krige_var
def __call__(self, pos, mesh_type="unstructured"): """ Generate the simple kriging field. The field is saved as `self.field` and is also returned. Parameters ---------- pos : :class:`list` the position tuple, containing main direction and transversal directions (x, [y, z]) mesh_type : :class:`str` 'structured' / 'unstructured' Returns ------- field : :class:`numpy.ndarray` the kriged field krige_var : :class:`numpy.ndarray` the kriging error variance """ # internal conversation x, y, z = pos2xyz(pos, dtype=np.double, max_dim=self.model.dim) c_x, c_y, c_z = pos2xyz(self.cond_pos, dtype=np.double, max_dim=self.model.dim) self.pos = xyz2pos(x, y, z) self.mesh_type = mesh_type # format the positional arguments of the mesh check_mesh(self.model.dim, x, y, z, mesh_type) mesh_type_changed = False if mesh_type == "structured": mesh_type_changed = True mesh_type_old = mesh_type mesh_type = "unstructured" x, y, z, axis_lens = reshape_axis_from_struct_to_unstruct( self.model.dim, x, y, z) if self.model.do_rotation: x, y, z = unrotate_mesh(self.model.dim, self.model.angles, x, y, z) c_x, c_y, c_z = unrotate_mesh(self.model.dim, self.model.angles, c_x, c_y, c_z) y, z = make_isotropic(self.model.dim, self.model.anis, y, z) c_y, c_z = make_isotropic(self.model.dim, self.model.anis, c_y, c_z) # set condtions to zero mean cond = self.cond_val - self.mean krig_mat = inv(self._get_cov_mat((c_x, c_y, c_z), (c_x, c_y, c_z))) krig_vecs = self._get_cov_mat((c_x, c_y, c_z), (x, y, z)) # generate the kriged field field, krige_var = krigesum(krig_mat, krig_vecs, cond) # reshape field if we got an unstructured mesh if mesh_type_changed: mesh_type = mesh_type_old field = reshape_field_from_unstruct_to_struct( self.model.dim, field, axis_lens) krige_var = reshape_field_from_unstruct_to_struct( self.model.dim, krige_var, axis_lens) # calculate the kriging error self.krige_var = self.model.sill - krige_var # add the given mean self.field = field + self.mean return self.field, self.krige_var
def __call__( self, pos, mesh_type="unstructured", ext_drift=None, chunk_size=None, only_mean=False, ): """ Generate the kriging field. The field is saved as `self.field` and is also returned. The error variance is saved as `self.krige_var` and is also returned. Parameters ---------- pos : :class:`list` the position tuple, containing main direction and transversal directions (x, [y, z]) mesh_type : :class:`str`, optional 'structured' / 'unstructured' ext_drift : :class:`numpy.ndarray` or :any:`None`, optional the external drift values at the given positions (only for EDK) chunk_size : :class:`int`, optional Chunk size to cut down the size of the kriging system to prevent memory errors. Default: None only_mean : :class:`bool`, optional Whether to only calculate the mean of the kriging field. Default: `False` Returns ------- field : :class:`numpy.ndarray` the kriged field krige_var : :class:`numpy.ndarray` the kriging error variance """ iso_pos, shape = self.pre_pos(pos, mesh_type) pnt_cnt = len(iso_pos[0]) field = np.empty(pnt_cnt, dtype=np.double) krige_var = np.empty(pnt_cnt, dtype=np.double) # set constant mean if present and wanted if only_mean and self.has_const_mean: field[...] = self.get_mean() - self.mean # mean is added later krige_var[...] = self.model.sill # will result in 0 var. later # execute the kriging routine else: # set chunk size chunk_size = pnt_cnt if chunk_size is None else int(chunk_size) chunk_no = int(np.ceil(pnt_cnt / chunk_size)) ext_drift = self._pre_ext_drift(pnt_cnt, ext_drift) # iterate of chunks for i in range(chunk_no): # get chunk slice for actual chunk chunk_slice = ( i * chunk_size, min(pnt_cnt, (i + 1) * chunk_size), ) c_slice = slice(*chunk_slice) # get RHS of the kriging system k_vec = self._get_krige_vecs( iso_pos, chunk_slice, ext_drift, only_mean ) # generate the raw kriging field and error variance field[c_slice], krige_var[c_slice] = krigesum( self._krige_mat, k_vec, self._krige_cond ) # reshape field if we got a structured mesh field = np.reshape(field, shape) krige_var = np.reshape(krige_var, shape) self._post_field(field, krige_var) return self.field, self.krige_var
def __call__( self, pos, mesh_type="unstructured", ext_drift=None, chunk_size=None ): """ Generate the kriging field. The field is saved as `self.field` and is also returned. The error variance is saved as `self.krige_var` and is also returned. Parameters ---------- pos : :class:`list` the position tuple, containing main direction and transversal directions (x, [y, z]) mesh_type : :class:`str`, optional 'structured' / 'unstructured' ext_drift : :class:`numpy.ndarray` or :any:`None`, optional the external drift values at the given positions (only for EDK) chunk_size : :class:`int`, optional Chunk size to cut down the size of the kriging system to prevent memory errors. Default: None Returns ------- field : :class:`numpy.ndarray` the kriged field krige_var : :class:`numpy.ndarray` the kriging error variance """ self.mesh_type = mesh_type # internal conversation x, y, z, self.pos, __, mt_changed, axis_lens = self._pre_pos( pos, mesh_type, make_unstruct=True ) point_no = len(x) # set chunk size chunk_size = point_no if chunk_size is None else int(chunk_size) chunk_no = int(np.ceil(point_no / chunk_size)) field = np.empty_like(x) krige_var = np.empty_like(x) ext_drift = self._pre_ext_drift(point_no, ext_drift) # iterate of chunks for i in range(chunk_no): # get chunk slice for actual chunk chunk_slice = (i * chunk_size, min(point_no, (i + 1) * chunk_size)) c_slice = slice(*chunk_slice) # get RHS of the kriging system k_vec = self._get_krige_vecs((x, y, z), chunk_slice, ext_drift) # generate the raw kriging field and error variance field[c_slice], krige_var[c_slice] = krigesum( self._krige_mat, k_vec, self._krige_cond ) # reshape field if we got a structured mesh if mt_changed: field = reshape_field_from_unstruct_to_struct( self.model.dim, field, axis_lens ) krige_var = reshape_field_from_unstruct_to_struct( self.model.dim, krige_var, axis_lens ) self._post_field(field, krige_var) return self.field, self.krige_var