Exemplo n.º 1
0
    def set_condition(
        self, cond_pos=None, cond_val=None, krige_type="ordinary"
    ):
        """Condition a given spatial random field with measurements.

        Parameters
        ----------
        cond_pos : :class:`list`
            the position tuple of the conditions
        cond_val : :class:`numpy.ndarray`
            the values of the conditions
        krige_type : :class:`str`, optional
            Used kriging type for conditioning.
            Either 'ordinary' or 'simple'.
            Default: 'ordinary'

        Notes
        -----
        When using "ordinary" as ``krige_type``, the ``mean`` attribute of the
        spatial random field will be overwritten with the estimated mean.
        """
        if cond_pos is not None:
            self._cond_pos, self._cond_val = set_condition(
                cond_pos, cond_val, self.model.dim
            )
        else:
            self._cond_pos = self._cond_val = None
        self._krige_type = krige_type
        if krige_type not in CONDITION:
            raise ValueError(
                "gstools.SRF: Unknown kriging method: " + krige_type
            )
Exemplo n.º 2
0
    def set_condition(
        self, cond_pos, cond_val, ext_drift=None, cond_err="nugget"
    ):
        """Set the conditions for kriging.

        Parameters
        ----------
        cond_pos : :class:`list`
            the position tuple of the conditions (x, [y, z])
        cond_val : :class:`numpy.ndarray`
            the values of the conditions
        ext_drift : :class:`numpy.ndarray` or :any:`None`, optional
            the external drift values at the given conditions (only for EDK)
            For multiple external drifts, the first dimension
            should be the index of the drift term.
        cond_err : :class:`str`, :class :class:`float`, :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"
        """
        # correctly format cond_pos and cond_val
        self._cond_pos, self._cond_val = set_condition(
            cond_pos, cond_val, self.model.dim
        )
        # set the measurement errors
        self.cond_err = cond_err
        # set the external drift values and the conditioning points
        self._cond_ext_drift = self._pre_ext_drift(
            self.cond_no, ext_drift, set_cond=True
        )
        # upate the internal kriging settings
        self.update()
Exemplo n.º 3
0
    def set_condition(self, cond_pos, cond_val):
        """Set the conditions for kriging.

        Parameters
        ----------
        cond_pos : :class:`list`
            the position tuple of the conditions (x, [y, z])
        cond_val : :class:`numpy.ndarray`
            the values of the conditions
        """
        self._cond_pos, self._cond_val = set_condition(cond_pos, cond_val,
                                                       self.model.dim)
Exemplo n.º 4
0
    def set_condition(self, cond_pos, cond_val, ext_drift=None):
        """Set the conditions for kriging.

        Parameters
        ----------
        cond_pos : :class:`list`
            the position tuple of the conditions (x, [y, z])
        cond_val : :class:`numpy.ndarray`
            the values of the conditions
        ext_drift : :class:`numpy.ndarray` or :any:`None`, optional
            the external drift values at the given conditions (only for EDK)
            For multiple external drifts, the first dimension
            should be the index of the drift term.
        """
        self._cond_pos, self._cond_val = set_condition(
            cond_pos, cond_val, self.model.dim
        )
        self._cond_ext_drift = self._pre_ext_drift(
            self.cond_no, ext_drift, set_cond=True
        )
        self.update()
Exemplo n.º 5
0
    def set_condition(
        self,
        cond_pos=None,
        cond_val=None,
        ext_drift=None,
        cond_err=None,
        fit_normalizer=False,
        fit_variogram=False,
    ):
        """Set the conditions for kriging.

        This method could also be used to update the kriging setup, when
        properties were changed. Then you can call it without arguments.

        Parameters
        ----------
        cond_pos : :class:`list`, optional
            the position tuple of the conditions (x, [y, z]). Default: current.
        cond_val : :class:`numpy.ndarray`, optional
            the values of the conditions. Default: current.
        ext_drift : :class:`numpy.ndarray` or :any:`None`, optional
            the external drift values at the given conditions (only for EDK)
            For multiple external drifts, the first dimension
            should be the index of the drift term. When passing `None`, the
            extisting external drift will be used.
        cond_err : :class:`str`, :class :class:`float`, :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"
        fit_normalizer : :class:`bool`, optional
            Wheater to fit the data-normalizer to the given conditioning data.
            Default: False
        fit_variogram : :class:`bool`, optional
            Wheater to fit the given variogram model to the data.
            This is done by using isotropy settings of the given model,
            assuming the sill to be the data variance and with the
            standard bins provided by the :any:`standard_bins` routine.
            Default: False
        """
        # only use existing external drift, if no new positions are given
        ext_drift = (self._cond_ext_drift if
                     (ext_drift is None and cond_pos is None) else ext_drift)
        # use existing values or set default
        cond_pos = self._cond_pos if cond_pos is None else cond_pos
        cond_val = self._cond_val if cond_val is None else cond_val
        cond_err = self._cond_err if cond_err is None else cond_err
        cond_err = "nugget" if cond_err is None else cond_err  # default
        if cond_pos is None or cond_val is None:
            raise ValueError("Krige.set_condition: missing cond_pos/cond_val.")
        # correctly format cond_pos and cond_val
        self._cond_pos, self._cond_val = set_condition(cond_pos, cond_val,
                                                       self.dim)
        if fit_normalizer:  # fit normalizer to detrended data
            self.normalizer.fit(self.cond_val - self.cond_trend)
        if fit_variogram:  # fitting model to empirical variogram of data
            # normalize field
            field = self.normalizer.normalize(self.cond_val - self.cond_trend)
            field -= self.cond_mean
            sill = np.var(field)
            if self.model.is_isotropic:
                emp_vario = vario_estimate(self.cond_pos,
                                           field,
                                           latlon=self.model.latlon)
            else:
                axes = rotated_main_axes(self.model.dim, self.model.angles)
                emp_vario = vario_estimate(self.cond_pos,
                                           field,
                                           direction=axes)
            # set the sill to the field variance
            self.model.fit_variogram(*emp_vario, sill=sill)
        # set the measurement errors
        self.cond_err = cond_err
        # set the external drift values and the conditioning points
        self._cond_ext_drift = self._pre_ext_drift(self.cond_no,
                                                   ext_drift,
                                                   set_cond=True)
        # upate the internal kriging settings
        self._krige_pos = self.model.isometrize(self.cond_pos)
        # krige pos are the unrotated and isotropic condition positions
        self._krige_mat = self._get_krige_mat()