Example #1
0
def set_dim(model, dim):
    """
    Set the dimension in the given model.

    Parameters
    ----------
    model : :any:`CovModel`
        The covariance model in use.
    dim : :class:`int`
        dimension of the model.

    Raises
    ------
    ValueError
        When dimension is < 1.
    """
    # check if a fixed dimension should be used
    if model.fix_dim() is not None and model.fix_dim() != dim:
        warnings.warn(
            model.name + ": using fixed dimension " + str(model.fix_dim()),
            AttributeWarning,
        )
        dim = model.fix_dim()
        if model.latlon and dim != 3:
            raise ValueError(
                f"{model.name}: using fixed dimension {model.fix_dim()}, "
                "which is not compatible with a latlon model."
            )
    # force dim=3 for latlon models
    dim = 3 if model.latlon else dim
    # set the dimension
    if dim < 1:
        raise ValueError("Only dimensions of d >= 1 are supported.")
    if not model.check_dim(dim):
        warnings.warn(
            f"Dimension {dim} is not appropriate for this model.",
            AttributeWarning,
        )
    model._dim = int(dim)
    # create fourier transform just once (recreate for dim change)
    model._sft = SFT(ndim=model.dim, **model.hankel_kw)
    # recalculate dimension related parameters
    if model._anis is not None:
        model._len_scale, model._anis = set_len_anis(
            model.dim, model._len_scale, model._anis
        )
    if model._angles is not None:
        model._angles = set_angles(model.dim, model._angles)
    model.check_arg_bounds()
Example #2
0
 def angles(self, angles):
     if self.latlon:
         self._angles = np.array(self.dim * [0], dtype=np.double)
     else:
         self._angles = set_angles(self.dim, angles)
     self.check_arg_bounds()
Example #3
0
    def __init__(
        self,
        dim=3,
        var=1.0,
        len_scale=1.0,
        nugget=0.0,
        anis=1.0,
        angles=0.0,
        integral_scale=None,
        rescale=None,
        latlon=False,
        var_raw=None,
        hankel_kw=None,
        **opt_arg,
    ):
        # assert, that we use a subclass
        # this is the case, if __init_subclass__ is called, which creates
        # the "variogram"... so we check for that
        if not hasattr(self, "variogram"):
            raise TypeError("Don't instantiate 'CovModel' directly!")

        # prepare dim setting
        self._dim = None
        self._hankel_kw = None
        self._sft = None
        # prepare parameters (they are checked in dim setting)
        self._rescale = None
        self._len_scale = None
        self._anis = None
        self._angles = None
        # prepare parameters boundaries
        self._var_bounds = None
        self._len_scale_bounds = None
        self._nugget_bounds = None
        self._anis_bounds = None
        self._opt_arg_bounds = {}
        # Set latlon first
        self._latlon = bool(latlon)
        # SFT class will be created within dim.setter but needs hankel_kw
        self.hankel_kw = hankel_kw
        self.dim = dim

        # optional arguments for the variogram-model
        set_opt_args(self, opt_arg)

        # set standard boundaries for variance, len_scale, nugget and opt_arg
        bounds = self.default_arg_bounds()
        bounds.update(self.default_opt_arg_bounds())
        self.set_arg_bounds(check_args=False, **bounds)

        # set parameters
        self.rescale = rescale
        self._nugget = float(nugget)
        # set anisotropy and len_scale, disable anisotropy for latlon models
        self._len_scale, anis = set_len_anis(self.dim, len_scale, anis)
        if self.latlon:
            self._anis = np.array((self.dim - 1) * [1], dtype=np.double)
            self._angles = np.array(self.dim * [0], dtype=np.double)
        else:
            self._anis = anis
            self._angles = set_angles(self.dim, angles)
        # set var at last, because of the var_factor (to be right initialized)
        if var_raw is None:
            self._var = None
            self.var = var
        else:
            self._var = float(var_raw)
        self._integral_scale = None
        self.integral_scale = integral_scale
        # set var again, if int_scale affects var_factor
        if var_raw is None:
            self._var = None
            self.var = var
        else:
            self._var = float(var_raw)
        # final check for parameter bounds
        self.check_arg_bounds()
        # additional checks for the optional arguments (provided by user)
        self.check_opt_arg()
        # precision for printing
        self._prec = 3
Example #4
0
 def angles(self, angles):
     self._angles = set_angles(self.dim, angles)
     self.check_arg_bounds()