Skip to content

Commit

Permalink
CovModel: remove mechanism for fixed args again
Browse files Browse the repository at this point in the history
  • Loading branch information
MuellerSeb committed Aug 11, 2024
1 parent 81e5421 commit 669e9a2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 36 deletions.
36 changes: 4 additions & 32 deletions src/gstools/covmodel/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ class CovModel:
used for the spectrum calculation. Use with caution (Better: Don't!).
``None`` is equivalent to ``{"a": -1, "b": 1, "N": 1000, "h": 0.001}``.
Default: :any:`None`
fixed: :class:`set` or :any:`None`, optional
Names of fixed arguments. Default: :any:`None`
**opt_arg
Optional arguments are covered by these keyword arguments.
If present, they are described in the section `Other Parameters`.
Expand All @@ -155,7 +153,6 @@ def __init__(
temporal=False,
spatial_dim=None,
hankel_kw=None,
fixed=None,
**opt_arg,
):
# assert, that we use a subclass
Expand All @@ -164,14 +161,13 @@ def __init__(
if not hasattr(self, "variogram"):
raise TypeError("Don't instantiate 'CovModel' directly!")

# indicate that arguments are fixed (True after __init__)
# indicator for initialization status (True after __init__)
self._init = False
# prepare dim setting
self._dim = None
self._hankel_kw = None
self._sft = None
# prepare parameters (they are checked in dim setting)
self._fixed = None
self._rescale = None
self._len_scale = None
self._anis = None
Expand All @@ -196,23 +192,14 @@ def __init__(
# optional arguments for the variogram-model
set_opt_args(self, opt_arg)

# check fixed
fixed = set(fixed) if fixed is not None else set()
fixed = fixed | self.always_fixed()
valid_fixed = set(self.iso_arg) # | set(["anis"])
if not fixed <= valid_fixed:
raise ValueError(
f"CovModel: unknown names in 'fixed': {fixed - valid_fixed}"
)
self._fixed = fixed

# set standard boundaries for variance, len_scale, nugget and opt_arg
bounds = self.default_arg_bounds()
bounds.update(self.default_opt_arg_bounds())
self.set_arg_bounds(check_args=False, **bounds)

# set parameters
self.rescale = rescale
self._var = float(var)
self._nugget = float(nugget)

# set anisotropy and len_scale, disable anisotropy for latlon models
Expand All @@ -225,23 +212,17 @@ def __init__(
self.dim, angles, self.latlon, self.temporal
)

self._var = None
self.var = var

if integral_scale is not None:
self.integral_scale = integral_scale

# final check for parameter bounds
self.check_arg_bounds()
# additional checks for the optional arguments (provided by user)
self.check_opt_arg()
# set fixed bounds after checking original bounds
for arg in self.fixed:
val = getattr(self, arg)
self.set_arg_bounds(check_args=False, **{arg: (val, val, "cc")})
self._init = True
# precision for printing
self._prec = 3
# initialized
self._init = True

# one of these functions needs to be overridden
def __init_subclass__(cls):
Expand Down Expand Up @@ -444,10 +425,6 @@ def pykrige_kwargs(self):

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

def always_fixed(self):
"""Provide set of fixed arguments."""
return set()

def default_opt_arg(self):
"""Provide default optional arguments by the user.
Expand Down Expand Up @@ -801,11 +778,6 @@ def check_arg_bounds(self):

# bounds properties

@property
def fixed(self):
""":class:`set`: Set with names of fixed arguments."""
return self._fixed

@property
def var_bounds(self):
""":class:`list`: Bounds for the variance.
Expand Down
2 changes: 0 additions & 2 deletions src/gstools/covmodel/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@ def fit_variogram(
The fitted parameters will be instantly set in the model.
"""
for para in model.fixed:
para_select[para] = False
# preprocess selected parameters
para, sill, constrain_sill, anis = _pre_para(
model, para_select, sill, anis
Expand Down
2 changes: 0 additions & 2 deletions src/gstools/covmodel/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,6 @@ def set_arg_bounds(model, check_args=True, **kwargs):
# if variance needs to be resetted, do this at last
var_bnds = []
for arg, bounds in kwargs.items():
if model._init and arg in model.fixed:
raise ValueError(f"Can't set bounds for fixed argument '{arg}'")
if not check_bounds(bounds):
raise ValueError(
f"Given bounds for '{arg}' are not valid, got: {bounds}"
Expand Down

0 comments on commit 669e9a2

Please sign in to comment.