Skip to content

Commit

Permalink
Merge pull request #255 from GeoStat-Framework/cherry_picks_minor_fixes
Browse files Browse the repository at this point in the history
Cherry picks minor fixes for v1.4
  • Loading branch information
MuellerSeb authored Aug 16, 2022
2 parents 58cc52b + 62a90fa commit ebefaa6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/gstools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
7 changes: 7 additions & 0 deletions src/gstools/covmodel/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,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)
6 changes: 3 additions & 3 deletions src/gstools/variogram/estimator.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -156,23 +156,23 @@ 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

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

cdef _normalization_func_vec choose_estimator_normalization_vec(str estimator_type):
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

Expand Down
9 changes: 9 additions & 0 deletions tests/test_covmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ebefaa6

Please sign in to comment.