Skip to content

Commit

Permalink
remove variogram_normed from cov-model
Browse files Browse the repository at this point in the history
  • Loading branch information
MuellerSeb committed Jul 12, 2019
1 parent f9fc944 commit 25b1647
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 43 deletions.
27 changes: 5 additions & 22 deletions gstools/covmodel/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,14 @@ def __init_subclass__(cls):
* ``model.variogram(r)``
:math:`\gamma\left(r\right)=
\sigma^2\cdot\left(1-\mathrm{cor}\left(r\right)\right)+n`
* ``model.variogram_normed(r)``
:math:`\tilde{\gamma}\left(r\right)=
1-\mathrm{cor}\left(r\right)`
* ``model.covariance(r)``
:math:`C\left(r\right)=
\sigma^2\cdot\mathrm{cor}\left(r\right)`
* ``model.correlation(r)``
:math:`\mathrm{cor}\left(r\right)`
Best practice is to use the ``correlation`` function!
Best practice is to use the ``correlation`` function, or the ``cor``
function. The latter one takes the dimensionles distance h=r/l.
"""
# overrid one of these ################################################

Expand Down Expand Up @@ -237,7 +235,7 @@ def correlation(self, r):
It has to be a monotonic decreasing function with
:math:`\mathrm{cor}(0)=1` and :math:`\mathrm{cor}(\infty)=0`.
"""
return 1.0 - self.variogram_normed(r)
return 1.0 - (self.variogram(r) - self.nugget) / self.var

def cor_from_cor(self, r):
r"""Correlation function (or normalized covariance) of the model.
Expand All @@ -250,16 +248,6 @@ def cor_from_cor(self, r):
r = np.array(np.abs(r), dtype=np.double)
return self.cor(r / self.len_scale)

def variogram_normed(self, r):
r"""Normalized-variogram of the model.
Given by: :math:`\tilde{\gamma}\left(r\right)=
1-\mathrm{cor}\left(r\right)`
Where :math:`\mathrm{cor}(r)` is the correlation function.
"""
return (self.variogram(r) - self.nugget) / self.var

#######################################################################

abstract = True
Expand All @@ -278,18 +266,13 @@ def variogram_normed(self, r):
cls.correlation = correlation
else:
abstract = False
if not hasattr(cls, "variogram_normed"):
cls.variogram_normed = variogram_normed
else:
abstract = False
if abstract:
raise TypeError(
"Can't instantiate class '"
+ cls.__name__
+ "', "
+ "without overriding at least on of the methods "
+ "'variogram', 'covariance', "
+ "'correlation', or 'variogram_normed'."
+ "'variogram', 'covariance' or 'correlation'."
)

# modify the docstrings ###############################################
Expand Down Expand Up @@ -514,7 +497,7 @@ def percentile_scale(self, per=0.9):

# define a curve, that has its root at the wanted point
def curve(x):
return self.variogram_normed(x) - per
return 1.0 - self.correlation(x) - per

# take 'per * len_scale' as initial guess
return root(curve, per * self.len_scale)["x"][0]
Expand Down
23 changes: 2 additions & 21 deletions gstools/covmodel/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
.. autosummary::
plot_variogram
plot_variogram_normed
plot_covariance
plot_correlation
plot_spectrum
Expand All @@ -18,11 +17,9 @@
# pylint: disable=C0103
from __future__ import print_function, division, absolute_import
import numpy as np
from matplotlib import pyplot as plt

__all__ = [
"plot_variogram",
"plot_variogram_normed",
"plot_covariance",
"plot_correlation",
"plot_spectrum",
Expand All @@ -35,6 +32,8 @@


def _get_fig_ax(fig, ax, ax_name="rectilinear"): # pragma: no cover
from matplotlib import pyplot as plt

if fig is None and ax is None:
fig = plt.figure()
ax = fig.add_subplot(111, projection=ax_name)
Expand Down Expand Up @@ -91,24 +90,6 @@ def plot_correlation(
return ax


def plot_variogram_normed(
model, x_min=0.0, x_max=None, fig=None, ax=None
): # pragma: no cover
"""Plot normalized variogram of a given CovModel."""
fig, ax = _get_fig_ax(fig, ax)
if x_max is None:
x_max = 3 * model.integral_scale
x_s = np.linspace(x_min, x_max)
ax.plot(
x_s,
model.variogram_normed(x_s),
label=model.name + " normed variogram",
)
ax.legend()
fig.show()
return ax


def plot_spectrum(
model, x_min=0.0, x_max=None, fig=None, ax=None
): # pragma: no cover
Expand Down

0 comments on commit 25b1647

Please sign in to comment.