def fidw(xs, ds, beta=2): '''Interpolate using using U{Inverse Distance Weighting <https://WikiPedia.org/wiki/Inverse_distance_weighting>} (IDW). @arg xs: Known values (C{scalar}[]). @arg ds: Non-negative distances (C{scalar}[]). @kwarg beta: Inverse distance power (C{int}, 0, 1, 2, or 3). @return: Interpolated value C{x} (C{float}). @raise ValueError: Invalid B{C{beta}}, negative B{C{ds}} value, weighted B{C{ds}} below L{EPS} or unequal C{len}C{(}B{C{ds}}C{)} and C{len}C{(}B{C{xs}}C{)}. @note: Using B{C{beta}}C{=0} returns the mean of B{C{xs}}. ''' n, xs = len2(xs) d, ds = len2(ds) if n != d or n < 1: raise LenError(fidw, xs=n, ds=d) d, x = min(zip(ds, xs)) if d > EPS and n > 1: b = -Int_(beta, name=_beta_, low=0, high=3) if b < 0: ds = tuple(d**b for d in ds) d = fsum(ds) if d < EPS: raise _ValueError(ds=d) x = fdot(xs, *ds) / d else: x = fmean(xs) elif d < 0: raise _ValueError(_item_sq('ds', ds.index(d)), d) return x
def __init__(self, knots, s=4, name=NN): '''New L{HeightSmoothBiSpline} interpolator. @arg knots: The points with known height (C{LatLon}s). @kwarg s: The spline smoothing factor (C{4}). @kwarg name: Optional name for this height interpolator (C{str}). @raise HeightError: Insufficient number of B{C{knots}} or an invalid B{C{knot}} or B{C{s}}. @raise ImportError: Package C{numpy} or C{scipy} not found or not installed. @raise SciPyError: A C{SmoothSphereBivariateSpline} issue. @raise SciPyWarning: A C{SmoothSphereBivariateSpline} warning as exception. ''' _, spi = self._NumSciPy() s = Int_(s, name='smoothing', Error=HeightError, low=4) xs, ys, hs = self._xyhs3(knots) try: self._ev = spi.SmoothSphereBivariateSpline(ys, xs, hs, eps=EPS, s=s).ev except Exception as x: raise _SciPyIssue(x) if name: self.name = name
def beta(self, beta): '''Set the inverse distance power. @arg beta: New inverse distance power (C{int} 1, 2, or 3). @raise HeightError: Invalid B{C{beta}}. ''' self._beta = Int_(beta, name=_beta_, Error=HeightError, low=1, high=3)
def resolution(prec): '''Determine the (geographic) resolution of a given L{Garef} precision. @arg prec: The given precision (C{int}). @return: The (geographic) resolution (C{degrees}). @raise GARSError: Invalid B{C{prec}}. @see: Function L{gars.encode} for more C{precision} details. ''' p = Int_(prec=prec, Error=GARSError, low=-1, high=_MaxPrec + 1) return _Resolutions[max(0, min(p, _MaxPrec))]