wradlib.ipol.interpolate(src, trg, vals, ipclass, *args, **kwargs)

Convenience function to use the interpolation classes in an efficient way

The interpolation classes in wradlib.ipol are computationally very efficient if they are applied on large multi-dimensional arrays of which the first dimension must be the locations’ dimension (1d or 2d coordinates) and the following dimensions can be anything (e.g. time or ensembles). This way, the weights need to be computed only once. However, this can only be done with success if all source values for the interpolation are valid numbers. If the source values contain let’s say np.nan types, the result of the interpolation will be np.nan in the vicinity of the corresponding points, too. Imagine that you have a time series of observations at points and in each time step one observation is missing. You would still like to efficiently apply the interpolation classes, but you will need to account for the resulting np.nan values in the interpolation output.

In order to still allow for the efficient application, you have to take care of the remaining np.nan in your interpolation result. This is done by this convenience function.

Alternatively, you have to make sure that your vals argument does not contain any np.nan values OR you have to post-process missing values in your interpolation result in another way.


Works only for one- and two-dimensional vals arrays, yet.

  • src (ndarray of floats, shape (npoints, ndims)) – Data point coordinates of the source points.
  • trg (ndarray of floats, shape (npoints, ndims)) – Data point coordinates of the target points.
  • vals (ndarray of float, shape (numsourcepoints, ..)) – Values at the source points which to interpolate
  • ipclass (a class which inherits from IpolBase) –
Other Parameters:

*args (arguments of ipclass (see class documentation))

Keyword Arguments:

**kwargs (keyword arguments of ipclass (see class documentation)) –


>>> # test for 1 dimension in space and two value dimensions
>>> src = np.arange(10)[:,None]
>>> trg = np.linspace(0,20,40)[:,None]
>>> vals = np.hstack((np.sin(src), 10.+np.sin(src)))
>>> # here we introduce missing values only in the second dimension
>>> vals[3:5,1] = np.nan
>>> ipol_result = interpolate(src, trg, vals, Idw, nnearest=2)
>>> import matplotlib.pyplot as plt
>>> plt.interactive(True)
>>> line1 = plt.plot(trg, ipol_result, 'b+')
>>> line2 = plt.plot(src, vals, 'ro')