Skip to content

Kriging interpolation

kriging(geodataframe, target_column, raster_profile, variogram_model='linear', coordinates_type='geographic', method='ordinary')

Perform Kriging interpolation on the input data.

Parameters:

Name Type Description Default
geodataframe GeoDataFrame

GeoDataFrame containing the input data.

required
target_column str

The column name with values for each geometry.

required
raster_profile Union[Profile, dict]

The raster profile used for output grid properties. Needs to include at least crs, transform, width and height.

required
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
ndarray

Numpy array containing the interpolated values.

Raises:

Type Description
EmptyDataFrameException

The input GeoDataFrame is empty.

InvalidParameterValueException

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

NonMatchingCrsException

The input GeoDataFrame and raster profile have mismatching CRS.

Source code in eis_toolkit/vector_processing/kriging_interpolation.py
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 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
@beartype
def kriging(
    geodataframe: gpd.GeoDataFrame,
    target_column: str,
    raster_profile: Union[profiles.Profile, dict],
    variogram_model: Literal["linear", "power", "gaussian", "spherical", "exponential"] = "linear",
    coordinates_type: Literal["euclidean", "geographic"] = "geographic",
    method: Literal["ordinary", "universal"] = "ordinary",
) -> np.ndarray:
    """
    Perform Kriging interpolation on the input data.

    Args:
        geodataframe: GeoDataFrame containing the input data.
        target_column: The column name with values for each geometry.
        raster_profile: The raster profile used for output grid properties. Needs to include at least
            crs, transform, width and height.
        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:
        Numpy array containing the interpolated values.

    Raises:
        EmptyDataFrameException: The input GeoDataFrame is empty.
        InvalidParameterValueException: Target column name is invalid or resolution is not greater than zero.
        NonMatchingCrsException: The input GeoDataFrame and raster profile have mismatching CRS.
    """

    if geodataframe.empty:
        raise EmptyDataFrameException("Expected GeoDataFrame to not be empty.")
    if raster_profile.get("crs") != geodataframe.crs:
        raise NonMatchingCrsException("Expected coordinate systems to match between raster and GeoDataFrame.")
    if target_column not in geodataframe.columns:
        raise InvalidParameterValueException(
            f"Expected target_column ({target_column}) to be contained in GeoDataFrame columns."
        )

    check_raster_profile(raster_profile)

    raster_width = raster_profile.get("width")
    raster_height = raster_profile.get("height")
    raster_transform = raster_profile.get("transform")

    data_interpolated = _kriging(
        geodataframe,
        target_column,
        raster_width,
        raster_height,
        raster_transform,
        variogram_model,
        coordinates_type,
        method,
    )

    return data_interpolated