Skip to content

Kriging interpolation

kriging(data, target_column, resolution, extent=None, variogram_model='linear', coordinates_type='geographic', method='ordinary')

Perform Kriging interpolation on the input data.

Parameters:

Name Type Description Default
data GeoDataFrame

GeoDataFrame containing the input data.

required
target_column str

The column name with values for each geometry.

required
resolution Tuple[Number, Number]

The resolution i.e. cell size of the output raster as (pixel_size_x, pixel_size_y).

required
extent Optional[Tuple[Number, Number, Number, Number]]

The extent of the output raster as (x_min, x_max, y_min, y_max). If None, calculate extent from the input vector data.

None
variogram_model Literal[linear, power, gaussian, spherical, exponential]

Variogram model to be used. Either 'linear', 'power', 'gaussian', 'spherical' or 'exponential'. Defaults to 'linear'.

'linear'
coordinates_type Literal[euclidean, geographic]

Determines are coordinates on a plane ('euclidean') or a sphere ('geographic'). Used only in ordinary kriging. Defaults to 'geographic'.

'geographic'
method Literal[ordinary, universal]

Ordinary or universal kriging. Defaults to 'ordinary'.

'ordinary'

Returns:

Type Description
Tuple[ndarray, dict]

Grid containing the interpolated values and metadata.

Raises:

Type Description
EmptyDataFrameException

The input GeoDataFrame is empty.

InvalidParameterValueException

Target column name is invalid or resolution is not greater than zero.

Source code in eis_toolkit/vector_processing/kriging_interpolation.py
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
@beartype
def kriging(
    data: gpd.GeoDataFrame,
    target_column: str,
    resolution: Tuple[Number, Number],
    extent: Optional[Tuple[Number, Number, Number, Number]] = None,
    variogram_model: Literal["linear", "power", "gaussian", "spherical", "exponential"] = "linear",
    coordinates_type: Literal["euclidean", "geographic"] = "geographic",
    method: Literal["ordinary", "universal"] = "ordinary",
) -> Tuple[np.ndarray, dict]:
    """
    Perform Kriging interpolation on the input data.

    Args:
        data: GeoDataFrame containing the input data.
        target_column: The column name with values for each geometry.
        resolution: The resolution i.e. cell size of the output raster as (pixel_size_x, pixel_size_y).
        extent: The extent of the output raster as (x_min, x_max, y_min, y_max).
            If None, calculate extent from the input vector data.
        variogram_model: Variogram model to be used.
            Either 'linear', 'power', 'gaussian', 'spherical' or 'exponential'. Defaults to 'linear'.
        coordinates_type: Determines are coordinates on a plane ('euclidean') or a sphere ('geographic').
            Used only in ordinary kriging. Defaults to 'geographic'.
        method: Ordinary or universal kriging. Defaults to 'ordinary'.

    Returns:
        Grid containing the interpolated values and metadata.

    Raises:
        EmptyDataFrameException: The input GeoDataFrame is empty.
        InvalidParameterValueException: Target column name is invalid or resolution is not greater than zero.
    """

    if data.empty:
        raise EmptyDataFrameException("The input GeoDataFrame is empty.")

    if target_column not in data.columns:
        raise InvalidParameterValueException(
            f"Expected target_column ({target_column}) to be contained in geodataframe columns."
        )

    if resolution[0] <= 0 or resolution[1] <= 0:
        raise InvalidParameterValueException("The resolution must be greater than zero.")

    data_interpolated, out_meta = _kriging(
        data, target_column, resolution, extent, variogram_model, coordinates_type, method
    )

    return data_interpolated, out_meta