Skip to content

Proposal: allow arbitrary dimensions #77

@MuellerSeb

Description

@MuellerSeb

Since we are planing to allow arbitrary dimensions in PyKrige, we need to prepare GSTools for that as well.

There are just a few modifications needed. The foundation for rotation and anisotropy in N-D, as discussed in issue GeoStat-Framework/PyKrige#138, could be implemented in GSTools.

The covariance model needs some updates:

  1. it could simply provide the respective transformation matrices rot_mat, derot_mat, iso_mat and aniso_mat depending on the given angles and anisotropy-ratios (as described in the PyKrige issue)
  2. we have to update the workflow for checking dimensionality. The fix_dim could be a check_dim routine, that takes the wanted dimension and state if it is valid.
  3. anis and angles need to be treated based on the dimension. for anis this already works and for angles we need to consider, that there are (dim * (dim - 1)) // 2 rotation angles in N-D (15e2d80)
  4. The associated rotation planes are [(i, j) for i in range(angles_no) for j in range(i + 1, angles_no)] (15e2d80)
  5. everything else should be already working (SFT and so on).

The SRF would need some special treatment:

  1. We need samples of the unit-sphere in N-D. Following this, we could modify RNG.sample_sphere for dim>3 with: (a856ea2)
    coord = self.random.normal(size=coord.shape)
    while True:  # loop until all norms are non-zero
        norm = np.linalg.norm(coord, axis=0)
        # check for zero norms
        zero_norms = np.isclose(norm, 0)
        # exit the loop if all norms are non-zero
        if not np.any(zero_norms):
            break
        # transpose, since the next transpose reverses axis order
        zero_samples = zero_norms.T.nonzero()
        # need to transpose to have dim-axis last
        new_shape = coord.T[zero_samples].shape
        # resample the zero norm samples
        coord.T[zero_samples] = self.random.normal(size=new_shape)
    # project onto sphere
    coord = coord / norm
  2. The generators for unstructured meshes are already prepared for arbitrary dimensions.
  3. For structured meshes, we could simply drop handling structured meshes separately and convert them always to unstructured (which is done already, if anisotropy is present) or we could keep this procedures for 1,2 and 3 dimensions.
  4. we need to get rid of this cumbersome pos=(x,y,z) handling. We could simply handle it as an array and the spatial dimension is first array dimension.

Metadata

Metadata

Assignees

Labels

RefactoringCode-Refactoring needed hereenhancementNew feature or request

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions