Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __eq__(self, other):
"""Compare CovModels."""
if not isinstance(other, CovModel):
return False
# prevent attribute error in opt_arg if the are not equal
if set(self.opt_arg) != set(other.opt_arg):
return False
# prevent dim error in anis and angles
if self.dim != other.dim:
return False
equal = True
equal &= self.name == other.name
equal &= np.isclose(self.var, other.var)
equal &= np.isclose(self.var_raw, other.var_raw) # ?! needless?
equal &= np.isclose(self.nugget, other.nugget)
equal &= np.isclose(self.len_scale, other.len_scale)
equal &= np.all(np.isclose(self.anis, other.anis))
equal &= np.all(np.isclose(self.angles, other.angles))
for opt in self.opt_arg:
# modify the docstrings ###############################################
# class docstring gets attributes added
if cls.__doc__ is None:
cls.__doc__ = (
"User defined GSTools Covariance-Model "
+ CovModel.__doc__[44:-296]
)
else:
cls.__doc__ += CovModel.__doc__[44:-296]
# overridden functions get standard doc if no new doc was created
ignore = ["__", "variogram", "covariance", "correlation"]
for attr in cls.__dict__:
if any(
[attr.startswith(ign) for ign in ignore]
) or attr not in dir(CovModel):
continue
attr_doc = getattr(CovModel, attr).__doc__
attr_cls = cls.__dict__[attr]
if attr_cls.__doc__ is None:
attr_cls.__doc__ = attr_doc
self.reset_seed(self._seed)
# just update the seed, if its a new one
elif seed is None or not np.isnan(seed):
self.seed = seed
# or just update the seed, when no model is given
elif model is None and (seed is None or not np.isnan(seed)):
if isinstance(self._model, CovModel):
self.seed = seed
else:
raise ValueError(
"gstools.field.generator.RandMeth: no 'model' given"
)
# if the user tries to trick us, we beat him!
elif model is None and np.isnan(seed):
if (
isinstance(self._model, CovModel)
and self._z_1 is not None
and self._z_2 is not None
and self._cov_sample is not None
):
if self.verbose:
print("RandMeth.update: Nothing will be done...")
else:
raise ValueError(
"gstools.field.generator.RandMeth: "
+ "neither 'model' nor 'seed' given!"
)
# wrong model type
else:
raise ValueError(
"gstools.field.generator.RandMeth: 'model' is not an "
+ "instance of 'gstools.CovModel'"
+ cls.__name__
+ "', "
+ "without overriding at least on of the methods "
+ "'variogram', 'covariance' or 'correlation'."
)
# modify the docstrings ###############################################
# class docstring gets attributes added
if cls.__doc__ is None:
cls.__doc__ = (
"User defined GSTools Covariance-Model "
+ CovModel.__doc__[44:-296]
)
else:
cls.__doc__ += CovModel.__doc__[44:-296]
# overridden functions get standard doc if no new doc was created
ignore = ["__", "variogram", "covariance", "correlation"]
for attr in cls.__dict__:
if any(
[attr.startswith(ign) for ign in ignore]
) or attr not in dir(CovModel):
continue
attr_doc = getattr(CovModel, attr).__doc__
attr_cls = cls.__dict__[attr]
if attr_cls.__doc__ is None:
attr_cls.__doc__ = attr_doc
def update(self, model=None, seed=np.nan):
"""Update the model and the seed.
If model and seed are not different, nothing will be done.
Parameters
----------
model : :any:`CovModel` or :any:`None`, optional
covariance model. Default: :any:`None`
seed : :class:`int` or :any:`None` or :any:`numpy.nan`, optional
the seed of the random number generator.
If :any:`None`, a random seed is used. If :any:`numpy.nan`,
the actual seed will be kept. Default: :any:`numpy.nan`
"""
# check if a new model is given
if isinstance(model, CovModel):
if self.model != model:
self._model = dcp(model)
if seed is None or not np.isnan(seed):
self.reset_seed(seed)
else:
self.reset_seed(self._seed)
# just update the seed, if its a new one
elif seed is None or not np.isnan(seed):
self.seed = seed
# or just update the seed, when no model is given
elif model is None and (seed is None or not np.isnan(seed)):
if isinstance(self._model, CovModel):
self.seed = seed
else:
raise ValueError(
"gstools.field.generator.RandMeth: no 'model' given"
def model(self, model):
if isinstance(model, CovModel):
self._model = model
else:
raise ValueError(
"Field: 'model' is not an instance of 'gstools.CovModel'"
)
# class docstring gets attributes added
if cls.__doc__ is None:
cls.__doc__ = (
"User defined GSTools Covariance-Model "
+ CovModel.__doc__[44:-296]
)
else:
cls.__doc__ += CovModel.__doc__[44:-296]
# overridden functions get standard doc if no new doc was created
ignore = ["__", "variogram", "covariance", "correlation"]
for attr in cls.__dict__:
if any(
[attr.startswith(ign) for ign in ignore]
) or attr not in dir(CovModel):
continue
attr_doc = getattr(CovModel, attr).__doc__
attr_cls = cls.__dict__[attr]
if attr_cls.__doc__ is None:
attr_cls.__doc__ = attr_doc