Skip to content

kriging

py3dinterpolations.modelling.models.kriging

Ordinary Kriging 3D model via pykrige.

KrigingModel(**kriging_params)

Bases: BaseModel

Ordinary Kriging 3D wrapper around pykrige.

pykrige fits at construction time, so fit() constructs the OrdinaryKriging3D instance.

Parameters:

Name Type Description Default
**kriging_params object

Parameters passed to OrdinaryKriging3D constructor.

{}
Source code in py3dinterpolations/modelling/models/kriging.py
20
21
22
def __init__(self, **kriging_params: object):
    self._params = kriging_params
    self._model: OrdinaryKriging3D | None = None

fit(x, y, z, v)

Fit by constructing the OrdinaryKriging3D model.

Source code in py3dinterpolations/modelling/models/kriging.py
24
25
26
def fit(self, x: np.ndarray, y: np.ndarray, z: np.ndarray, v: np.ndarray) -> None:
    """Fit by constructing the OrdinaryKriging3D model."""
    self._model = OrdinaryKriging3D(x, y, z, v, **self._params)

predict(grid_x, grid_y, grid_z, **kwargs)

Execute kriging on the given grid arrays.

Returns:

Type Description
InterpolationResult

InterpolationResult with interpolated and variance arrays.

InterpolationResult

Shape is (len(grid_z), len(grid_y), len(grid_x)) per pykrige convention.

Source code in py3dinterpolations/modelling/models/kriging.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def predict(
    self,
    grid_x: np.ndarray,
    grid_y: np.ndarray,
    grid_z: np.ndarray,
    **kwargs: object,
) -> InterpolationResult:
    """Execute kriging on the given grid arrays.

    Returns:
        InterpolationResult with interpolated and variance arrays.
        Shape is (len(grid_z), len(grid_y), len(grid_x)) per pykrige convention.
    """
    if self._model is None:
        msg = "Model must be fit before predicting"
        raise RuntimeError(msg)
    interpolated, variance = self._model.execute(
        style="grid",
        xpoints=grid_x,
        ypoints=grid_y,
        zpoints=grid_z,
        **kwargs,
    )
    return InterpolationResult(
        interpolated=interpolated,
        variance=variance,
    )