Visualization#

Raster#

pyinterpolate.interpolate_raster(known_locations: ArrayLike = None, known_values: ArrayLike = None, known_geometries: ArrayLike = None, dim=1000, buffer=0.0, number_of_neighbors=4, semivariogram_model=None, direction=None, tolerance=None, allow_approx_solutions=True) Dict[source]

Function interpolates raster from data points using ordinary kriging.

Parameters:
known_locationsnumpy array

Known locations: [x, y, value].

known_valuesArrayLike, optional

Observation in the i-th geometry (from known_geometries). Optional parameter, if not given then known_locations must be provided.

known_geometriesArrayLike, optional

Array or similar structure with geometries. It must have the same length as known_values. Optional parameter, if not given then known_locations must be provided. Point type geometry.

dimint

Number of pixels (points) of a larger dimension (it could be width or height). Ratio is preserved.

bufferfloat, default = 0

Buffer around interpolated area. Must be equal or greater than one, otherwise it is not created.

number_of_neighborsint, default=16

Number of points used to interpolate data.

semivariogram_modelTheoreticalVariogram, default=None

Variogram model, if not provided then it is estimated from a given dataset.

directionfloat (in range [0, 360]), optional

Direction of semivariogram, values from 0 to 360 degrees:

  • 0 or 180: is E-W,

  • 90 or 270 is N-S,

  • 45 or 225 is NE-SW,

  • 135 or 315 is NW-SE.

tolerancefloat (in range [0, 1]), optional

If tolerance is 0 then points must be placed at a single line with the beginning in the origin of the coordinate system and the direction given by y-axis and direction parameter. If tolerance is > 0 then the bin is selected as an elliptical area with major axis pointed in the same direction as the line for 0 tolerance:

  • the major axis size == step_size,

  • the minor axis size is tolerance * step_size,

  • the baseline point is at a center of the ellipse,

  • the tolerance == 1 creates an omnidirectional semivariogram.

allow_approx_solutionsbool, default=True

Allows the approximation of kriging weights based on the OLS algorithm. We don’t recommend set it to True if you don’t know what are you doing. This parameter can be useful when you have clusters in your dataset, that can lead to singular or near-singular matrix creation.

Returns:
raster_dictDict

A dictionary with keys:

  • ‘result’: numpy array of interpolated values,

  • ‘error’: numpy array of interpolation errors,

  • ‘params’:
    • ‘pixel size’,

    • ‘min x’,

    • ‘max x’,

    • ‘min y’,

    • ‘max y’

Examples

>>> import json  # printing purposes
>>> import numpy as np
>>> from pyinterpolate import interpolate_raster
>>>
>>>
>>> input_data = np.array([
...    [0, 0, 8],
...    [1, 0, 6],
...    [2, 0, 4],
...    [3, 0, 3],
...    [4, 0, 6],
...    [5, 0, 5],
...    [6, 0, 7],
...    [7, 0, 2],
...    [8, 0, 8],
...    [9, 0, 9],
...    [10, 0, 5],
...    [11, 0, 6],
...    [12, 0, 3]
...    ])
>>> raster_data = interpolate_raster(
...     known_values=input_data[:, -1],
...     known_geometries=input_data[:, :-1],
...     dim=20
... )
>>> print(json.dumps(raster_data, intend=2, default=str))
{
  "result": "[[7.96961847 6.47028231 5.60333362 ...]]",
  "error": "[[0.08611248 2.6949744  1.69602854 ...]]",
  "params": {
    "pixel size": 0.6,
    "min x": 0.0,
    "max x": 12.0,
    "min y": 0.0,
    "max y": 0.0
  }
}