pyinterp.RTree.window_function#

RTree.window_function(coordinates: numpy.ndarray, radius: float, k: Optional[int] = 9, wf: Optional[str] = None, arg: Optional[float] = None, within: Optional[bool] = True, num_threads: Optional[int] = 0) Tuple[numpy.ndarray, numpy.ndarray][source]#

Interpolation of the value at the requested position by window function.

The interpolated value will be equal to the expression:

\[\frac{\sum_{i=1}^{k} \omega(d_i,r)x_i} {\sum_{i=1}^{k} \omega(d_i,r)}\]

where \(d_i\) is the distance between the point of interest and the \(i\)-th neighbor, \(r\) is the radius of the search, \(x_i\) is the value of the \(i\)-th neighbor, and \(\omega(d_i,r)\) is weight calculated by the window function describe above.

Parameters
  • coordinates – a matrix (n, ndims) where n is the number of observations and ndims is the number of coordinates in order: longitude and latitude in degrees, altitude in meters and then the other coordinates defined in Euclidean space if dims > 3. If the shape of the matrix is (n, ndims) then the method considers the altitude constant and equal to zero.

  • radius – The maximum radius of the search (m).

  • k – The number of nearest neighbors to be used for calculating the interpolated value. Defaults to 9.

  • wf

    The window function, based on the distance the distance between points (\(d\)) and the radius (\(r\)). This parameter can take one of the following values:

    • blackman: \(w(d) = 0.42659 - 0.49656 \cos( \frac{\pi (d + r)}{r}) + 0.076849 \cos( \frac{2 \pi (d + r)}{r})\)

    • blackman_harris: \(w(d) = 0.35875 - 0.48829 \cos(\frac{\pi (d + r)}{r}) + 0.14128 \cos(\frac{2 \pi (d + r)}{r}) - 0.01168 \cos(\frac{3 \pi (d + r)}{r})\)

    • boxcar: \(w(d) = 1\)

    • flat_top: \(w(d) = 0.21557895 - 0.41663158 \cos(\frac{\pi (d + r)}{r}) + 0.277263158 \cos(\frac{2 \pi (d + r)}{r}) - 0.083578947 \cos(\frac{3 \pi (d + r)}{r}) + 0.006947368 \cos(\frac{4 \pi (d + r)}{r})\)

    • lanczos: \(w(d) = \left\{\begin{array}{ll} sinc(\frac{d}{r}) \times sinc(\frac{d}{arg \times r}), & d \le arg \times r \\ 0, & d \gt arg \times r \end{array} \right\}\)

    • gaussian: \(w(d) = e^{ -\frac{1}{2}\left( \frac{d}{\sigma}\right)^2 }\)

    • hamming: \(w(d) = 0.53836 - 0.46164 \cos(\frac{\pi (d + r)}{r})\)

    • nuttall: \(w(d) = 0.3635819 - 0.4891775 \cos(\frac{\pi (d + r)}{r}) + 0.1365995 \cos(\frac{2 \pi (d + r)}{r})\)

    • parzen: \(w(d) = \left\{ \begin{array}{ll} 1 - 6 \left(\frac{2*d}{2*r}\right)^2 \left(1 - \frac{2*d}{2*r}\right), & d \le \frac{2r + arg}{4} \\ 2\left(1 - \frac{2*d}{2*r}\right)^3 & \frac{2r + arg}{2} \le d \lt \frac{2r +arg}{4} \end{array} \right\}\)

    • parzen_swot: \(w(d) = \left\{\begin{array}{ll} 1 - 6\left(\frac{2 * d}{2 * r}\right)^2 + 6\left(1 - \frac{2 * d}{2 * r}\right), & d \le \frac{2r}{4} \\ 2\left(1 - \frac{2 * d}{2 * r}\right)^3 & \frac{2r}{2} \ge d \gt \frac{2r}{4} \end{array} \right\}\)

  • arg – The optional argument of the window function. Defaults to 1 for lanczos, to 0 for parzen and for all other functions is None.

  • within – If true, the method ensures that the neighbors found are located around the point of interest. In other words, this parameter ensures that the calculated values will not be extrapolated. Defaults to true.

  • num_threads – The number of threads to use for the computation. If 0 all CPUs are used. If 1 is given, no parallel computing code is used at all, which is useful for debugging. Defaults to 0.

Returns

The interpolated value and the number of neighbors used in the calculation.