Source code for gstools.krige.methods

"""
GStools subpackage providing a class for simple kriging.

.. currentmodule:: gstools.krige.methods

The following classes are provided

.. autosummary::
   Simple
   Ordinary
   Universal
   ExtDrift
   Detrended
"""
# pylint: disable=C0103
from gstools.krige.base import Krige

__all__ = ["Simple", "Ordinary", "Universal", "ExtDrift", "Detrended"]


[docs]class Simple(Krige): """ Simple kriging. Simple kriging is used to interpolate data with a given mean. Parameters ---------- model : :any:`CovModel` Covariance Model used for kriging. cond_pos : :class:`list` tuple, containing the given condition positions (x, [y, z]) cond_val : :class:`numpy.ndarray` the values of the conditions (nan values will be ignored) mean : :class:`float`, optional mean value used to shift normalized conditioning data. Could also be a callable. The default is None. normalizer : :any:`None` or :any:`Normalizer`, optional Normalizer to be applied to the input data to gain normality. The default is None. trend : :any:`None` or :class:`float` or :any:`callable`, optional A callable trend function. Should have the signature: f(x, [y, z, ...]) This is used for detrended kriging, where the trended is subtracted from the conditions before kriging is applied. This can be used for regression kriging, where the trend function is determined by an external regression algorithm. If no normalizer is applied, this behaves equal to 'mean'. The default is None. exact : :class:`bool`, optional Whether the interpolator should reproduce the exact input values. If `False`, `cond_err` is interpreted as measurement error at the conditioning points and the result will be more smooth. Default: False cond_err : :class:`str`, :class :class:`float` or :class:`list`, optional The measurement error at the conditioning points. Either "nugget" to apply the model-nugget, a single value applied to all points or an array with individual values for each point. The measurement error has to be <= nugget. The "exact=True" variant only works with "cond_err='nugget'". Default: "nugget" pseudo_inv : :class:`bool`, optional Whether the kriging system is solved with the pseudo inverted kriging matrix. If `True`, this leads to more numerical stability and redundant points are averaged. But it can take more time. Default: True pseudo_inv_type : :class:`str` or :any:`callable`, optional Here you can select the algorithm to compute the pseudo-inverse matrix: * `"pinv"`: use `pinv` from `scipy` which uses `SVD` * `"pinvh"`: use `pinvh` from `scipy` which uses eigen-values If you want to use another routine to invert the kriging matrix, you can pass a callable which takes a matrix and returns the inverse. Default: `"pinv"` fit_normalizer : :class:`bool`, optional Whether to fit the data-normalizer to the given conditioning data. Default: False fit_variogram : :class:`bool`, optional Whether to fit the given variogram model to the data. Directional variogram fitting is triggered by setting any anisotropy factor of the model to anything unequal 1 but the main axes of correlation are taken from the model rotation angles. If the model is a spatio-temporal latlon model, this will raise an error. This assumes the sill to be the data variance and with standard bins provided by the :any:`standard_bins` routine. Default: False """ def __init__( self, model, cond_pos, cond_val, mean=0.0, normalizer=None, trend=None, exact=False, cond_err="nugget", pseudo_inv=True, pseudo_inv_type="pinv", fit_normalizer=False, fit_variogram=False, ): super().__init__( model, cond_pos, cond_val, mean=mean, normalizer=normalizer, trend=trend, unbiased=False, exact=exact, cond_err=cond_err, pseudo_inv=pseudo_inv, pseudo_inv_type=pseudo_inv_type, fit_normalizer=fit_normalizer, fit_variogram=fit_variogram, )
[docs]class Ordinary(Krige): """ Ordinary kriging. Ordinary kriging is used to interpolate data and estimate a proper mean. Parameters ---------- model : :any:`CovModel` Covariance Model used for kriging. cond_pos : :class:`list` tuple, containing the given condition positions (x, [y, z]) cond_val : :class:`numpy.ndarray` the values of the conditions (nan values will be ignored) normalizer : :any:`None` or :any:`Normalizer`, optional Normalizer to be applied to the input data to gain normality. The default is None. trend : :any:`None` or :class:`float` or :any:`callable`, optional A callable trend function. Should have the signature: f(x, [y, z, ...]) This is used for detrended kriging, where the trended is subtracted from the conditions before kriging is applied. This can be used for regression kriging, where the trend function is determined by an external regression algorithm. If no normalizer is applied, this behaves equal to 'mean'. The default is None. exact : :class:`bool`, optional Whether the interpolator should reproduce the exact input values. If `False`, `cond_err` is interpreted as measurement error at the conditioning points and the result will be more smooth. Default: False cond_err : :class:`str`, :class :class:`float` or :class:`list`, optional The measurement error at the conditioning points. Either "nugget" to apply the model-nugget, a single value applied to all points or an array with individual values for each point. The measurement error has to be <= nugget. The "exact=True" variant only works with "cond_err='nugget'". Default: "nugget" pseudo_inv : :class:`bool`, optional Whether the kriging system is solved with the pseudo inverted kriging matrix. If `True`, this leads to more numerical stability and redundant points are averaged. But it can take more time. Default: True pseudo_inv_type : :class:`str` or :any:`callable`, optional Here you can select the algorithm to compute the pseudo-inverse matrix: * `"pinv"`: use `pinv` from `scipy` which uses `SVD` * `"pinvh"`: use `pinvh` from `scipy` which uses eigen-values If you want to use another routine to invert the kriging matrix, you can pass a callable which takes a matrix and returns the inverse. Default: `"pinv"` fit_normalizer : :class:`bool`, optional Whether to fit the data-normalizer to the given conditioning data. Default: False fit_variogram : :class:`bool`, optional Whether to fit the given variogram model to the data. Directional variogram fitting is triggered by setting any anisotropy factor of the model to anything unequal 1 but the main axes of correlation are taken from the model rotation angles. If the model is a spatio-temporal latlon model, this will raise an error. This assumes the sill to be the data variance and with standard bins provided by the :any:`standard_bins` routine. Default: False """ def __init__( self, model, cond_pos, cond_val, normalizer=None, trend=None, exact=False, cond_err="nugget", pseudo_inv=True, pseudo_inv_type="pinv", fit_normalizer=False, fit_variogram=False, ): super().__init__( model, cond_pos, cond_val, trend=trend, normalizer=normalizer, exact=exact, cond_err=cond_err, pseudo_inv=pseudo_inv, pseudo_inv_type=pseudo_inv_type, fit_normalizer=fit_normalizer, fit_variogram=fit_variogram, )
[docs]class Universal(Krige): """ Universal kriging. Universal kriging is used to interpolate given data with a variable mean, that is determined by a functional drift. This estimator is set to be unbiased by default. This means, that the weights in the kriging equation sum up to 1. Consequently no constant function needs to be given for a constant drift, since the unbiased condition is applied to all given drift functions. Parameters ---------- model : :any:`CovModel` Covariance Model used for kriging. cond_pos : :class:`list` tuple, containing the given condition positions (x, [y, z]) cond_val : :class:`numpy.ndarray` the values of the conditions (nan values will be ignored) drift_functions : :class:`list` of :any:`callable`, :class:`str` or :class:`int` Either a list of callable functions, an integer representing the polynomial order of the drift or one of the following strings: * "linear" : regional linear drift (equals order=1) * "quadratic" : regional quadratic drift (equals order=2) normalizer : :any:`None` or :any:`Normalizer`, optional Normalizer to be applied to the input data to gain normality. The default is None. trend : :any:`None` or :class:`float` or :any:`callable`, optional A callable trend function. Should have the signature: f(x, [y, z, ...]) This is used for detrended kriging, where the trended is subtracted from the conditions before kriging is applied. This can be used for regression kriging, where the trend function is determined by an external regression algorithm. If no normalizer is applied, this behaves equal to 'mean'. The default is None. exact : :class:`bool`, optional Whether the interpolator should reproduce the exact input values. If `False`, `cond_err` is interpreted as measurement error at the conditioning points and the result will be more smooth. Default: False cond_err : :class:`str`, :class :class:`float` or :class:`list`, optional The measurement error at the conditioning points. Either "nugget" to apply the model-nugget, a single value applied to all points or an array with individual values for each point. The measurement error has to be <= nugget. The "exact=True" variant only works with "cond_err='nugget'". Default: "nugget" pseudo_inv : :class:`bool`, optional Whether the kriging system is solved with the pseudo inverted kriging matrix. If `True`, this leads to more numerical stability and redundant points are averaged. But it can take more time. Default: True pseudo_inv_type : :class:`str` or :any:`callable`, optional Here you can select the algorithm to compute the pseudo-inverse matrix: * `"pinv"`: use `pinv` from `scipy` which uses `SVD` * `"pinvh"`: use `pinvh` from `scipy` which uses eigen-values If you want to use another routine to invert the kriging matrix, you can pass a callable which takes a matrix and returns the inverse. Default: `"pinv"` fit_normalizer : :class:`bool`, optional Whether to fit the data-normalizer to the given conditioning data. Default: False fit_variogram : :class:`bool`, optional Whether to fit the given variogram model to the data. Directional variogram fitting is triggered by setting any anisotropy factor of the model to anything unequal 1 but the main axes of correlation are taken from the model rotation angles. If the model is a spatio-temporal latlon model, this will raise an error. This assumes the sill to be the data variance and with standard bins provided by the :any:`standard_bins` routine. Default: False """ def __init__( self, model, cond_pos, cond_val, drift_functions, normalizer=None, trend=None, exact=False, cond_err="nugget", pseudo_inv=True, pseudo_inv_type="pinv", fit_normalizer=False, fit_variogram=False, ): super().__init__( model, cond_pos, cond_val, drift_functions=drift_functions, normalizer=normalizer, trend=trend, exact=exact, cond_err=cond_err, pseudo_inv=pseudo_inv, pseudo_inv_type=pseudo_inv_type, fit_normalizer=fit_normalizer, fit_variogram=fit_variogram, )
[docs]class ExtDrift(Krige): """ External drift kriging (EDK). External drift kriging is used to interpolate given data with a variable mean, that is determined by an external drift. This estimator is set to be unbiased by default. This means, that the weights in the kriging equation sum up to 1. Consequently no constant external drift needs to be given to estimate a proper mean. Parameters ---------- model : :any:`CovModel` Covariance Model used for kriging. cond_pos : :class:`list` tuple, containing the given condition positions (x, [y, z]) cond_val : :class:`numpy.ndarray` the values of the conditions (nan values will be ignored) ext_drift : :class:`numpy.ndarray` the external drift values at the given condition positions. normalizer : :any:`None` or :any:`Normalizer`, optional Normalizer to be applied to the input data to gain normality. The default is None. trend : :any:`None` or :class:`float` or :any:`callable`, optional A callable trend function. Should have the signature: f(x, [y, z, ...]) This is used for detrended kriging, where the trended is subtracted from the conditions before kriging is applied. This can be used for regression kriging, where the trend function is determined by an external regression algorithm. If no normalizer is applied, this behaves equal to 'mean'. The default is None. exact : :class:`bool`, optional Whether the interpolator should reproduce the exact input values. If `False`, `cond_err` is interpreted as measurement error at the conditioning points and the result will be more smooth. Default: False cond_err : :class:`str`, :class :class:`float` or :class:`list`, optional The measurement error at the conditioning points. Either "nugget" to apply the model-nugget, a single value applied to all points or an array with individual values for each point. The measurement error has to be <= nugget. The "exact=True" variant only works with "cond_err='nugget'". Default: "nugget" pseudo_inv : :class:`bool`, optional Whether the kriging system is solved with the pseudo inverted kriging matrix. If `True`, this leads to more numerical stability and redundant points are averaged. But it can take more time. Default: True pseudo_inv_type : :class:`str` or :any:`callable`, optional Here you can select the algorithm to compute the pseudo-inverse matrix: * `"pinv"`: use `pinv` from `scipy` which uses `SVD` * `"pinvh"`: use `pinvh` from `scipy` which uses eigen-values If you want to use another routine to invert the kriging matrix, you can pass a callable which takes a matrix and returns the inverse. Default: `"pinv"` fit_normalizer : :class:`bool`, optional Whether to fit the data-normalizer to the given conditioning data. Default: False fit_variogram : :class:`bool`, optional Whether to fit the given variogram model to the data. Directional variogram fitting is triggered by setting any anisotropy factor of the model to anything unequal 1 but the main axes of correlation are taken from the model rotation angles. If the model is a spatio-temporal latlon model, this will raise an error. This assumes the sill to be the data variance and with standard bins provided by the :any:`standard_bins` routine. Default: False """ def __init__( self, model, cond_pos, cond_val, ext_drift, normalizer=None, trend=None, exact=False, cond_err="nugget", pseudo_inv=True, pseudo_inv_type="pinv", fit_normalizer=False, fit_variogram=False, ): super().__init__( model, cond_pos, cond_val, ext_drift=ext_drift, normalizer=normalizer, trend=trend, exact=exact, cond_err=cond_err, pseudo_inv=pseudo_inv, pseudo_inv_type=pseudo_inv_type, fit_normalizer=fit_normalizer, fit_variogram=fit_variogram, )
[docs]class Detrended(Krige): """ Detrended simple kriging. In detrended kriging, the data is detrended before interpolation by simple kriging with zero mean. The trend needs to be a callable function the user has to provide. This can be used for regression kriging, where the trend function is determined by an external regression algorithm. This is just a shortcut for simple kriging with a given trend function, zero mean and no normalizer. A trend can be given with EVERY provided kriging routine. Parameters ---------- model : :any:`CovModel` Covariance Model used for kriging. cond_pos : :class:`list` tuple, containing the given condition positions (x, [y, z]) cond_val : :class:`numpy.ndarray` the values of the conditions (nan values will be ignored) trend_function : :any:`callable` The callable trend function. Should have the signature: f(x, [y, z]) exact : :class:`bool`, optional Whether the interpolator should reproduce the exact input values. If `False`, `cond_err` is interpreted as measurement error at the conditioning points and the result will be more smooth. Default: False cond_err : :class:`str`, :class :class:`float` or :class:`list`, optional The measurement error at the conditioning points. Either "nugget" to apply the model-nugget, a single value applied to all points or an array with individual values for each point. The measurement error has to be <= nugget. The "exact=True" variant only works with "cond_err='nugget'". Default: "nugget" pseudo_inv : :class:`bool`, optional Whether the kriging system is solved with the pseudo inverted kriging matrix. If `True`, this leads to more numerical stability and redundant points are averaged. But it can take more time. Default: True pseudo_inv_type : :class:`str` or :any:`callable`, optional Here you can select the algorithm to compute the pseudo-inverse matrix: * `"pinv"`: use `pinv` from `scipy` which uses `SVD` * `"pinvh"`: use `pinvh` from `scipy` which uses eigen-values If you want to use another routine to invert the kriging matrix, you can pass a callable which takes a matrix and returns the inverse. Default: `"pinv"` fit_variogram : :class:`bool`, optional Whether to fit the given variogram model to the data. Directional variogram fitting is triggered by setting any anisotropy factor of the model to anything unequal 1 but the main axes of correlation are taken from the model rotation angles. If the model is a spatio-temporal latlon model, this will raise an error. This assumes the sill to be the data variance and with standard bins provided by the :any:`standard_bins` routine. Default: False """ def __init__( self, model, cond_pos, cond_val, trend, exact=False, cond_err="nugget", pseudo_inv=True, pseudo_inv_type="pinv", fit_variogram=False, ): super().__init__( model, cond_pos, cond_val, trend=trend, unbiased=False, exact=exact, cond_err=cond_err, pseudo_inv=pseudo_inv, pseudo_inv_type=pseudo_inv_type, fit_variogram=fit_variogram, )