Inverse Distance Weighting (IDW)#
- pyinterpolate.inverse_distance_weighting(unknown_location: ArrayLike, known_locations: ArrayLike = None, known_values: ArrayLike = None, known_geometries: ArrayLike = None, no_neighbors=-1, power=2.0) float[source]
Inverse Distance Weighting with a given set of points and the unknown location.
- Parameters:
- unknown_locationIterable
Array or list with coordinates of the unknown point. Its length is N-1 (number of dimensions). The unknown location shape should be the same as the
known_pointsparameter shape, if not, then new dimension is added once - vector of points[x, y]becomes[[x, y]]for 2-dimensional data.- known_locationsnumpy array, optional
The known locations:
[x, y, value].- known_valuesArrayLike, optional
Observation in the i-th geometry (from
known_geometries). Optional parameter, if not given thenknown_locationsmust 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 thenknown_locationsmust be provided. Point type geometry.- no_neighborsint, default = -1
If default value (-1) then all known points will be used to estimate value at the unknown location. Can be any number within the limits
[2, len(known_points)],- powerfloat, default = 2.
Power value must be larger or equal to 0. It controls weight assigned to each known point. Larger power means stronger influence of the closest neighbors, but it decreases faster.
- Returns:
- resultfloat
The estimated value.
- Raises:
- ValueError
Power parameter set to be smaller than 0.
- ValueError
Less than 2 neighbours or more than the number of
known_pointsneighbours are given in thenumber_of_neighboursparameter.
Examples
>>> unknown_pos = (10, 10) >>> locs = np.array([ ... [11, 1, 1], ... [23, 2, 2], ... [33, 3, 3], ... [14, 44, 4], ... [13, 10, 9], ... [12, 55, 35], ... [11, 9, 7] ... ]) >>> pred = inverse_distance_weighting( ... unknown_locations=unknown_pos, ... known_values=locs[:, -1], ... known_geometries=locs[:, :-1], ... no_neighbors=2 ... ) >>> print(pred) 7.286311587314138