Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry picks minor fixes for v1.4 #255

Merged
merged 4 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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)
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