diff --git a/.gitignore b/.gitignore index 872d3f40b..1be5ae0c4 100644 --- a/.gitignore +++ b/.gitignore @@ -45,6 +45,7 @@ nosetests.xml coverage.xml *.cover .hypothesis/ +cov.xml # Translations *.mo diff --git a/src/gstools/field/cond_srf.py b/src/gstools/field/cond_srf.py index 385216ba1..406c3e01a 100644 --- a/src/gstools/field/cond_srf.py +++ b/src/gstools/field/cond_srf.py @@ -64,7 +64,7 @@ def __init__(self, krige, generator="RandMeth", **generator_kwargs): def __call__( self, pos=None, - seed=np.nan, + seed=..., mesh_type="unstructured", post_process=True, store=True, @@ -80,8 +80,10 @@ def __call__( pos : :class:`list`, optional the position tuple, containing main direction and transversal directions - seed : :class:`int`, optional - seed for RNG for resetting. Default: keep seed from generator + seed : :class:`int` or :any:`None` or :any:`Ellipsis`, optional + the seed of the random number generator. + If :any:`None`, a random seed is used. If :any:`Ellipsis`, + the current seed will be kept. Default: :any:`Ellipsis` mesh_type : :class:`str` 'structured' / 'unstructured' post_process : :class:`bool`, optional diff --git a/src/gstools/field/generator.py b/src/gstools/field/generator.py index 7780ec726..b25b8d8ad 100644 --- a/src/gstools/field/generator.py +++ b/src/gstools/field/generator.py @@ -52,7 +52,7 @@ def __init__(self, model, **kwargs): pass @abstractmethod - def update(self, model=None, seed=np.nan): + def update(self, model=None, seed=...): """Update the model and the seed. If model and seed are not different, nothing will be done. @@ -61,10 +61,10 @@ def update(self, model=None, seed=np.nan): ---------- model : :any:`CovModel` or :any:`None`, optional covariance model. Default: :any:`None` - seed : :class:`int` or :any:`None` or :any:`numpy.nan`, optional + seed : :class:`int` or :any:`None` or :any:`Ellipsis`, 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` + If :any:`None`, a random seed is used. If :any:`Ellipsis`, + the current seed will be kept. Default: :any:`Ellipsis` """ @abstractmethod @@ -235,7 +235,7 @@ def get_nugget(self, shape): nugget = 0.0 return nugget - def update(self, model=None, seed=np.nan): + def update(self, model=None, seed=...): """Update the model and the seed. If model and seed are not different, nothing will be done. @@ -244,24 +244,21 @@ def update(self, model=None, seed=np.nan): ---------- model : :any:`CovModel` or :any:`None`, optional covariance model. Default: :any:`None` - seed : :class:`int` or :any:`None` or :any:`numpy.nan`, optional + seed : :class:`int` or :any:`None` or :any:`Ellipsis`, 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` + If :any:`None`, a random seed is used. If :any:`Ellipsis`, + the current seed will be kept. Default: :any:`Ellipsis` """ # 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) + self.reset_seed(self._seed if seed is Ellipsis else seed) # just update the seed, if its a new one - elif seed is None or not np.isnan(seed): + elif seed is not Ellipsis: 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)): + elif model is None and seed is not Ellipsis: if isinstance(self._model, CovModel): self.seed = seed else: @@ -269,8 +266,8 @@ def update(self, model=None, seed=np.nan): "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 not ( + elif model is None and seed is Ellipsis: + if ( isinstance(self._model, CovModel) and self._z_1 is not None and self._z_2 is not None @@ -287,22 +284,22 @@ def update(self, model=None, seed=np.nan): "instance of 'gstools.CovModel'" ) - def reset_seed(self, seed=np.nan): + def reset_seed(self, seed=...): """ Recalculate the random amplitudes and wave numbers with the given seed. Parameters ---------- - seed : :class:`int` or :any:`None` or :any:`numpy.nan`, optional + seed : :class:`int` or :any:`None` or :any:`Ellipsis`, 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` + If :any:`None`, a random seed is used. If :any:`Ellipsis`, + the current seed will be kept. Default: :any:`Ellipsis` Notes ----- Even if the given seed is the present one, modes will be recalculated. """ - if seed is None or not np.isnan(seed): + if seed is not Ellipsis: self._seed = seed self._rng = RNG(self._seed) # normal distributed samples for randmeth @@ -351,7 +348,7 @@ def seed(self): @seed.setter def seed(self, new_seed): - if new_seed is not self._seed: + if new_seed != self._seed: self.reset_seed(new_seed) @property diff --git a/src/gstools/field/srf.py b/src/gstools/field/srf.py index a8a1e575f..15d95f267 100644 --- a/src/gstools/field/srf.py +++ b/src/gstools/field/srf.py @@ -103,7 +103,7 @@ def __init__( def __call__( self, pos=None, - seed=np.nan, + seed=..., point_volumes=0.0, mesh_type="unstructured", post_process=True, @@ -118,8 +118,10 @@ def __call__( pos : :class:`list`, optional the position tuple, containing main direction and transversal directions - seed : :class:`int`, optional - seed for RNG for resetting. Default: keep seed from generator + seed : :class:`int` or :any:`None` or :any:`Ellipsis`, optional + the seed of the random number generator. + If :any:`None`, a random seed is used. If :any:`Ellipsis`, + the current seed will be kept. Default: :any:`Ellipsis` point_volumes : :class:`float` or :class:`numpy.ndarray` If your evaluation points for the field are coming from a mesh, they are probably representing a certain element volume. diff --git a/src/gstools/krige/base.py b/src/gstools/krige/base.py index 336f4cc0e..e4c225e92 100755 --- a/src/gstools/krige/base.py +++ b/src/gstools/krige/base.py @@ -257,7 +257,7 @@ def __call__( ext_drift = self._pre_ext_drift(pnt_cnt, ext_drift) # iterate chunks for i in range(chunk_no): - # get chunk slice for actual chunk + # get chunk slice for current chunk chunk_slice = ( i * chunk_size, min(pnt_cnt, (i + 1) * chunk_size),