Exemple #1
0
 def len_scale(self, len_scale):
     self._len_scale, anis = set_len_anis(self.dim, len_scale, self.anis)
     if self.latlon:
         self._anis = np.array((self.dim - 1) * [1], dtype=np.double)
     else:
         self._anis = anis
     self.check_arg_bounds()
Exemple #2
0
 def anis(self, anis):
     if self.latlon:
         self._anis = np.array((self.dim - 1) * [1], dtype=np.double)
     else:
         self._len_scale, self._anis = set_len_anis(self.dim,
                                                    self.len_scale, anis)
     self.check_arg_bounds()
Exemple #3
0
 def dim(self, dim):
     # check if a fixed dimension should be used
     if self.fix_dim() is not None:
         print(self.name + ": using fixed dimension " + str(self.fix_dim()))
         dim = self.fix_dim()
     # set the dimension
     if dim < 1 or dim > 3:
         raise ValueError("Only dimensions of 1 <= d <= 3 are supported.")
     self._dim = int(dim)
     # create fourier transform just once (recreate for dim change)
     self._sft = SFT(ndim=self.dim, **self.hankel_kw)
     # recalculate dimension related parameters
     if self._anis is not None:
         self._len_scale, self._anis = set_len_anis(self.dim,
                                                    self._len_scale,
                                                    self._anis)
     if self._angles is not None:
         self._angles = set_angles(self.dim, self._angles)
Exemple #4
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
Exemple #5
0
 def len_scale(self, len_scale):
     self._len_scale, self._anis = set_len_anis(self.dim, len_scale,
                                                self.anis)
     self.check_arg_bounds()
Exemple #6
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,
                 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!")

        # optional arguments for the variogram-model
        # look up the defaults for the optional arguments (defined by the user)
        default = self.default_opt_arg()
        # add the default vaules if not specified
        for def_arg in default:
            if def_arg not in opt_arg:
                opt_arg[def_arg] = default[def_arg]
        # save names of the optional arguments
        self._opt_arg = list(opt_arg.keys())
        # add the optional arguments as attributes to the class
        for opt_name in opt_arg:
            if opt_name in dir(self):  # "dir" also respects properties
                raise ValueError(
                    "parameter '" + opt_name +
                    "' has a 'bad' name, since it is already present in " +
                    "the class. It could not be added to the model")
            if opt_name not in self.default_opt_arg().keys():
                warnings.warn(
                    "The given optional argument '{}' ".format(opt_name) +
                    "is unknown or has at least no defined standard value. " +
                    "Or you made a Typo... hehe.",
                    AttributeWarning,
                )
            # Magic happens here
            setattr(self, opt_name, opt_arg[opt_name])

        # set standard boundaries for variance, len_scale, nugget and opt_arg
        self._var_bounds = None
        self._len_scale_bounds = None
        self._nugget_bounds = None
        self._opt_arg_bounds = {}
        bounds = self.default_arg_bounds()
        bounds.update(self.default_opt_arg_bounds())
        self.set_arg_bounds(**bounds)

        # prepare dim setting
        self._dim = None
        self._len_scale = None
        self._anis = None
        self._angles = None
        # SFT class will be created within dim.setter but needs hankel_kw
        self._hankel_kw = None
        self._sft = None
        self.hankel_kw = hankel_kw
        self.dim = dim
        # set parameters
        self._nugget = nugget
        self._angles = set_angles(self.dim, angles)
        self._len_scale, self._anis = set_len_anis(self.dim, len_scale, anis)
        # 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 = 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 = var_raw
        # final check for parameter bounds
        self.check_arg_bounds()
        # additional checks for the optional arguments (provided by user)
        self.check_opt_arg()
Exemple #7
0
 def anis(self, anis):
     self._len_scale, self._anis = set_len_anis(self.dim, self.len_scale,
                                                anis)
     self.check_arg_bounds()