Skip to content

Commit

Permalink
Merge pull request #108 from GeoStat-Framework/cov_optarg_sort
Browse files Browse the repository at this point in the history
CovModel: sort opt_arg
  • Loading branch information
MuellerSeb authored Nov 10, 2020
2 parents 9549734 + 4706919 commit f62af73
Showing 1 changed file with 15 additions and 27 deletions.
42 changes: 15 additions & 27 deletions gstools/covmodel/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@


class AttributeWarning(UserWarning):
pass

"""Attribute warning for CovModel class."""

# The CovModel Base-Class #####################################################
pass


class CovModel(metaclass=InitSubclassMeta):
Expand Down Expand Up @@ -162,8 +161,9 @@ def __init__(
for def_arg in default:
if def_arg not in opt_arg:
opt_arg[def_arg] = default[def_arg]
# save names of the optional arguments
# save names of the optional arguments (sort them by name)
self._opt_arg = list(opt_arg.keys())
self._opt_arg.sort()
# add the optional arguments as attributes to the class
for opt_name in opt_arg:
if opt_name in dir(self): # "dir" also respects properties
Expand Down Expand Up @@ -204,10 +204,7 @@ def __init__(
# additional checks for the optional arguments (provided by user)
self.check_opt_arg()

###########################################################################
### one of these functions needs to be overridden #########################
###########################################################################

# one of these functions needs to be overridden
def __init_subclass__(cls):
r"""Initialize gstools covariance model.
Expand All @@ -228,7 +225,6 @@ def __init_subclass__(cls):
Best practice is to use the ``correlation`` function, or the ``cor``
function. The latter one takes the dimensionles distance h=r/l.
"""
# override one of these ###############################################

def variogram(self, r):
r"""Isotropic variogram of the model.
Expand Down Expand Up @@ -279,8 +275,6 @@ def cor_from_correlation(self, h):
h = np.array(np.abs(h), dtype=np.double)
return self.correlation(h * self.len_scale)

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

abstract = True
if hasattr(cls, "cor"):
cls.correlation = correlation_from_cor
Expand Down Expand Up @@ -308,7 +302,7 @@ def cor_from_correlation(self, h):
+ "'variogram', 'covariance' or 'correlation'."
)

# modify the docstrings ###############################################
# modify the docstrings

# class docstring gets attributes added
if cls.__doc__ is None:
Expand All @@ -330,7 +324,7 @@ def cor_from_correlation(self, h):
if attr_cls.__doc__ is None:
attr_cls.__doc__ = attr_doc

### special variogram functions ###########################################
# special variogram functions

def _get_iso_rad(self, pos):
x, y, z = pos2xyz(pos, max_dim=self.dim)
Expand Down Expand Up @@ -412,9 +406,7 @@ def plot(self, func="variogram", **kwargs): # pragma: no cover
routine = getattr(plot, "plot_" + func)
return routine(self, **kwargs)

###########################################################################
### pykrige functions #####################################################
###########################################################################
# pykrige functions

def pykrige_vario(self, args=None, r=0):
r"""Isotropic variogram of the model for pykrige.
Expand Down Expand Up @@ -501,9 +493,7 @@ def pykrige_kwargs(self):
kwargs.update(add_kwargs)
return kwargs

###########################################################################
### methods for optional arguments (can be overridden) ####################
###########################################################################
# methods for optional arguments (can be overridden)

def default_opt_arg(self):
"""Provide default optional arguments by the user.
Expand Down Expand Up @@ -543,7 +533,7 @@ def var_factor(self):
"""Factor for the variance."""
return 1.0

### calculation of different scales #######################################
# calculation of different scales

def calc_integral_scale(self):
"""Calculate the integral scale of the isotrope model."""
Expand All @@ -569,9 +559,7 @@ def curve(x):
# take 'per * len_scale' as initial guess
return root(curve, per * self.len_scale)["x"][0]

###########################################################################
### spectrum methods (can be overridden for speedup) ######################
###########################################################################
# spectrum methods (can be overridden for speedup)

def spectrum(self, k):
r"""
Expand Down Expand Up @@ -646,7 +634,7 @@ def _has_ppf(self):
"""State if a ppf is defined with 'spectral_rad_ppf'."""
return hasattr(self, "spectral_rad_ppf")

### fitting routine #######################################################
# fitting routine

def fit_variogram(
self,
Expand Down Expand Up @@ -787,7 +775,7 @@ def fit_variogram(
**para_select
)

### bounds setting and checks #############################################
# bounds setting and checks

def default_arg_bounds(self):
"""Provide default boundaries for arguments.
Expand Down Expand Up @@ -875,7 +863,7 @@ def check_arg_bounds(self):
"{0} needs to be < {1}, got: {2}".format(arg, bnd[1], val)
)

### bounds properties #####################################################
# bounds properties

@property
def var_bounds(self):
Expand Down Expand Up @@ -993,7 +981,7 @@ def arg_bounds(self):
res.update(self.opt_arg_bounds)
return res

### standard parameters ###################################################
# standard parameters

@property
def dim(self):
Expand Down

0 comments on commit f62af73

Please sign in to comment.