Skip to content

Commit

Permalink
generator: fix/unify call signature
Browse files Browse the repository at this point in the history
  • Loading branch information
MuellerSeb committed Aug 16, 2022
1 parent 01d3ae8 commit 212d282
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/gstools/field/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
RandMeth
IncomprRandMeth
"""
# pylint: disable=C0103, W0222, C0412, W0221
# pylint: disable=C0103, W0222, C0412
import warnings
from abc import ABC, abstractmethod
from copy import deepcopy as dcp
Expand Down Expand Up @@ -70,8 +70,22 @@ def get_nugget(self, shape):
"""

@abstractmethod
def __call__(self, pos, **kwargs):
"""Generate the field."""
def __call__(self, pos, add_nugget=True):
"""
Generate the field.
Parameters
----------
pos : (d, n), :class:`numpy.ndarray`
the position tuple with d dimensions and n points.
add_nugget : :class:`bool`
Whether to add nugget noise to the field.
Returns
-------
:class:`numpy.ndarray`
the random modes
"""

@property
@abstractmethod
Expand Down Expand Up @@ -452,7 +466,7 @@ def __init__(
self.mean_u = mean_velocity
self._value_type = "vector"

def __call__(self, pos):
def __call__(self, pos, add_nugget=True):
"""Calculate the random modes for the randomization method.
This method calls the `summate_incompr_*` Cython methods,
Expand All @@ -464,6 +478,8 @@ def __call__(self, pos):
----------
pos : (d, n), :class:`numpy.ndarray`
the position tuple with d dimensions and n points.
add_nugget : :class:`bool`
Whether to add nugget noise to the field.
Returns
-------
Expand All @@ -474,10 +490,8 @@ def __call__(self, pos):
summed_modes = summate_incompr(
self._cov_sample, self._z_1, self._z_2, pos
)
nugget = self.get_nugget(summed_modes.shape)

nugget = self.get_nugget(summed_modes.shape) if add_nugget else 0.0
e1 = self._create_unit_vector(summed_modes.shape)

return (
self.mean_u * e1
+ self.mean_u
Expand Down

0 comments on commit 212d282

Please sign in to comment.