Skip to content

Commit

Permalink
Merge pull request #123 from mmaelicke/patch-use-nugget
Browse files Browse the repository at this point in the history
changed use_nugget settings
  • Loading branch information
mmaelicke authored Feb 14, 2022
2 parents da9459d + bcfa7d5 commit 2beb7c2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
30 changes: 27 additions & 3 deletions skgstat/Variogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,15 +962,31 @@ def harmonize(x):

@property
def use_nugget(self):
"""
Use a nugget effect on this Variogram instance.
If disabled, the automatic fitting procedures will omit the nugget and
not use it as a model parameter.
Note
----
If :func:`fit_method <skgstat.Variogram.fit_method>` is set to
``'manual'`` and a nugget parameter is pass to
:func:`fit <skgstat.Variogram.fit>`, use_nugget will be set to True.
Returns
-------
use_nugget : bool
"""
return self._use_nugget

@use_nugget.setter
def use_nugget(self, nugget):
if not isinstance(nugget, bool):
def use_nugget(self, enable_nugget):
if not isinstance(enable_nugget, bool):
raise ValueError('use_nugget has to be of type bool.')

# set new value
self._use_nugget = nugget
self._use_nugget = enable_nugget

@property
def dist_function(self):
Expand Down Expand Up @@ -1380,6 +1396,10 @@ def fit(self, force=False, method=None, sigma=None, **kwargs):
.. versionchanged:: 0.3.10
added 'ml' and 'custom' method.
.. versionchanged:: 1.0.1
use_nugget is now flagged implicitly, whenever a nugget > 0 is
passed in manual fitting.
Parameters
----------
force : bool
Expand Down Expand Up @@ -1449,6 +1469,10 @@ def fit(self, force=False, method=None, sigma=None, **kwargs):
_x = x[~np.isnan(y)]
_y = y[~np.isnan(y)]

# check if method is manual and a nugget was passed
if self.fit_method == 'manual' and kwargs.get('nugget', False):
self.use_nugget = True

# handle harmonized models
if self._harmonize:
_x = np.linspace(0, np.max(_x), 100)
Expand Down
13 changes: 12 additions & 1 deletion skgstat/tests/test_variogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,18 @@ def test_manual_preserve_params(self):
V.parameters,
params,
decimal=1
)
)

def test_implicit_nugget(self):
V = Variogram(self.c, self.v, use_nugget=False)

# no nugget used
self.assertTrue(V.parameters[-1] < 1e-10)

# switch to manual fitting
V.fit(method='manual', sill=5., nugget=2.)

self.assertTrue(abs(V.parameters[-1] - 2.) < 1e-10)


class TestVariogramQualityMeasures(unittest.TestCase):
Expand Down

0 comments on commit 2beb7c2

Please sign in to comment.