gstools.field.generator.RandMeth

class gstools.field.generator.RandMeth(model, *, mode_no=1000, seed=None, sampling='auto', **kwargs)[source]

Bases: Generator

Randomization method for calculating isotropic random fields.

Parameters:
  • model (CovModel) – Covariance model

  • mode_no (int, optional) – Number of Fourier modes. Default: 1000

  • seed (int or None, optional) – The seed of the random number generator. If “None”, a random seed is used. Default: None

  • sampling (str, optional) –

    Sampling strategy. Either

    • “auto”: select best strategy depending on given model

    • “inversion”: use inversion method

    • “mcmc”: use mcmc sampling

  • **kwargs – Placeholder for keyword-args

Notes

The Randomization method is used to generate isotropic spatial random fields characterized by a given covariance model. The calculation looks like [Hesse2014]:

\[u\left(x\right)= \sqrt{\frac{\sigma^{2}}{N}}\cdot \sum_{i=1}^{N}\left( Z_{1,i}\cdot\cos\left(\left\langle k_{i},x\right\rangle \right)+ Z_{2,i}\cdot\sin\left(\left\langle k_{i},x\right\rangle \right) \right)\]

where:

  • \(N\) : fourier mode number

  • \(Z_{j,i}\) : random samples from a normal distribution

  • \(k_i\) : samples from the spectral density distribution of the covariance model

References

[Hesse2014]

Heße, F., Prykhodko, V., Schlüter, S., and Attinger, S., “Generating random fields with a truncated power-law variogram: A comparison of several numerical methods”, Environmental Modelling & Software, 55, 32-48., (2014)

Attributes:
mode_no

int: Number of modes in the randomization method.

model

CovModel: Covariance model of the spatial random field.

name

str: Name of the generator.

sampling

str: Sampling strategy.

seed

int: Seed of the master RNG.

value_type

str: Type of the field values (scalar, vector).

Methods

__call__(pos[, add_nugget])

Calculate the random modes for the randomization method.

get_nugget(shape)

Generate normal distributed values for the nugget simulation.

reset_seed([seed])

Recalculate the random amplitudes and wave numbers with the given seed.

update([model, seed])

Update the model and the seed.

__call__(pos, add_nugget=True)[source]

Calculate the random modes for the randomization method.

This method calls the summate_* Cython methods, which are the heart of the randomization method.

Parameters:
  • pos ((d, n), numpy.ndarray) – the position tuple with d dimensions and n points.

  • add_nugget (bool) – Whether to add nugget noise to the field.

Returns:

the random modes

Return type:

numpy.ndarray

get_nugget(shape)[source]

Generate normal distributed values for the nugget simulation.

Parameters:

shape (tuple) – the shape of the summed modes

Returns:

nugget – the nugget in the same shape as the summed modes

Return type:

numpy.ndarray

reset_seed(seed=nan)[source]

Recalculate the random amplitudes and wave numbers with the given seed.

Parameters:

seed (int or None or numpy.nan, optional) – the seed of the random number generator. If None, a random seed is used. If numpy.nan, the actual seed will be kept. Default: numpy.nan

Notes

Even if the given seed is the present one, modes will be recalculated.

update(model=None, seed=nan)[source]

Update the model and the seed.

If model and seed are not different, nothing will be done.

Parameters:
property mode_no

Number of modes in the randomization method.

Type:

int

property model

Covariance model of the spatial random field.

Type:

CovModel

property name

Name of the generator.

Type:

str

property sampling

Sampling strategy.

Type:

str

property seed

Seed of the master RNG.

Notes

If a new seed is given, the setter property not only saves the new seed, but also creates new random modes with the new seed.

Type:

int

property value_type

Type of the field values (scalar, vector).

Type:

str