diff --git a/src/gstools/__init__.py b/src/gstools/__init__.py index a82839cc..2d0e7232 100644 --- a/src/gstools/__init__.py +++ b/src/gstools/__init__.py @@ -180,7 +180,7 @@ try: from gstools._version import __version__ -except ModuleNotFoundError: # pragma: nocover +except ModuleNotFoundError: # pragma: no cover # package is not installed __version__ = "0.0.0.dev0" diff --git a/src/gstools/covmodel/base.py b/src/gstools/covmodel/base.py index f87aee80..2dab3e7c 100644 --- a/src/gstools/covmodel/base.py +++ b/src/gstools/covmodel/base.py @@ -1138,6 +1138,13 @@ def __eq__(self, other): return False return compare(self, other) + def __setattr__(self, name, value): + """Set an attribute.""" + super().__setattr__(name, value) + # if an optional variogram argument was given, check bounds + if hasattr(self, "_opt_arg") and name in self._opt_arg: + self.check_arg_bounds() + def __repr__(self): """Return String representation.""" return model_repr(self) diff --git a/src/gstools/variogram/estimator.pyx b/src/gstools/variogram/estimator.pyx index 6c5a67df..a3f40b5e 100644 --- a/src/gstools/variogram/estimator.pyx +++ b/src/gstools/variogram/estimator.pyx @@ -156,7 +156,7 @@ cdef _estimator_func choose_estimator_func(str estimator_type): cdef _estimator_func estimator_func if estimator_type == 'm': estimator_func = estimator_matheron - elif estimator_type == 'c': + else: # estimator_type == 'c' estimator_func = estimator_cressie return estimator_func @@ -164,7 +164,7 @@ cdef _normalization_func choose_estimator_normalization(str estimator_type): cdef _normalization_func normalization_func if estimator_type == 'm': normalization_func = normalization_matheron - elif estimator_type == 'c': + else: # estimator_type == 'c' normalization_func = normalization_cressie return normalization_func @@ -172,7 +172,7 @@ cdef _normalization_func_vec choose_estimator_normalization_vec(str estimator_ty cdef _normalization_func_vec normalization_func_vec if estimator_type == 'm': normalization_func_vec = normalization_matheron_vec - elif estimator_type == 'c': + else: # estimator_type == 'c' normalization_func_vec = normalization_cressie_vec return normalization_func_vec diff --git a/tests/test_covmodel.py b/tests/test_covmodel.py index 741129d6..415bc691 100644 --- a/tests/test_covmodel.py +++ b/tests/test_covmodel.py @@ -279,11 +279,20 @@ def test_fitting(self): # init guess with self.assertRaises(ValueError): model.fit_variogram(self.gamma_x, self.gamma_y, init_guess="wrong") + with self.assertRaises(ValueError): + model.fit_variogram( + self.gamma_x, self.gamma_y, init_guess={"wrong": 1} + ) + # sill fixing model.var_bounds = [0, np.inf] model.fit_variogram( self.gamma_x, np.array(self.gamma_y) + 1, sill=2, alpha=False ) self.assertAlmostEqual(model.var + model.nugget, 2) + # check isotropicity for latlon models + model = Stable(latlon=True) + with self.assertRaises(ValueError): + model.fit_variogram(self.gamma_x, 3 * [self.gamma_y]) def test_covmodel_class(self): model_std = Gaussian(rescale=3, var=1.1, nugget=1.2, len_scale=1.3)