gstools.field.CondSRF

class gstools.field.CondSRF(krige, generator='RandMeth', **generator_kwargs)[source]

Bases: gstools.field.base.Field

A class to generate conditioned spatial random fields (SRF).

Parameters
  • krige (Krige) – Kriging setup to condition the spatial random field.

  • generator (str, optional) –

    Name of the field generator to be used. At the moment, only the following generator is provided:

    • ”RandMeth” : The Randomization Method. See: RandMeth

    Default: “RandMeth”

  • **generator_kwargs – Keyword arguments that are forwarded to the generator in use. Have a look at the provided generators for further information.

Attributes
dim

int: Dimension of the field.

generator

callable: The generator of the field.

krige

Krige: The underlying kriging class.

latlon

bool: Whether the field depends on geographical coords.

mean

float or callable: The mean of the field.

model

CovModel: The covariance model of the field.

name

str: The name of the class.

normalizer

Normalizer: Normalizer of the field.

trend

float or callable: The trend of the field.

value_type

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

Methods

__call__(pos[, seed, mesh_type])

Generate the conditioned spatial random field.

get_scaling(krige_var, shape)

Get scaling coefficients for the random field.

mesh(mesh[, points, direction, name])

Generate a field on a given meshio, ogs5py or PyVista mesh.

plot([field, fig, ax])

Plot the spatial random field.

post_field(field[, name, process, save])

Postprocessing field values.

pre_pos(pos[, mesh_type])

Preprocessing positions and mesh_type.

set_generator(generator, **generator_kwargs)

Set the generator for the field.

structured(*args, **kwargs)

Generate a field on a structured mesh.

to_pyvista([field_select, fieldname])

Create a VTK/PyVista grid of the stored field.

unstructured(*args, **kwargs)

Generate a field on an unstructured mesh.

vtk_export(filename[, field_select, fieldname])

Export the stored field to vtk.

__call__(pos, seed=nan, mesh_type='unstructured', **kwargs)[source]

Generate the conditioned spatial random field.

The field is saved as self.field and is also returned.

Parameters
  • pos (list) – the position tuple, containing main direction and transversal directions

  • seed (int, optional) – seed for RNG for reseting. Default: keep seed from generator

  • mesh_type (str) – ‘structured’ / ‘unstructured’

  • **kwargs – keyword arguments that are forwarded to the kriging routine in use.

Returns

field – the conditioned SRF

Return type

numpy.ndarray

get_scaling(krige_var, shape)[source]

Get scaling coefficients for the random field.

Parameters
Returns

mesh(mesh, points='centroids', direction='all', name='field', **kwargs)

Generate a field on a given meshio, ogs5py or PyVista mesh.

Parameters
  • mesh (meshio.Mesh or ogs5py.MSH or PyVista mesh) – The given mesh

  • points (str, optional) – The points to evaluate the field at. Either the “centroids” of the mesh cells (calculated as mean of the cell vertices) or the “points” of the given mesh. Default: “centroids”

  • direction (str or list, optional) – Here you can state which direction should be choosen for lower dimension. For example, if you got a 2D mesh in xz direction, you have to pass “xz”. By default, all directions are used. One can also pass a list of indices. Default: “all”

  • name (str or list of str, optional) – Name(s) to store the field(s) in the given mesh as point_data or cell_data. If to few names are given, digits will be appended. Default: “field”

  • **kwargs – Keyword arguments forwarded to __call__.

Notes

This will store the field in the given mesh under the given name, if a meshio or PyVista mesh was given.

See:
plot(field='field', fig=None, ax=None, **kwargs)

Plot the spatial random field.

Parameters
  • field (str, optional) – Field that should be plotted. Default: “field”

  • fig (Figure or None) – Figure to plot the axes on. If None, a new one will be created. Default: None

  • ax (Axes or None) – Axes to plot on. If None, a new one will be added to the figure. Default: None

  • **kwargs – Forwarded to the plotting routine.

post_field(field, name='field', process=True, save=True)

Postprocessing field values.

Parameters
  • field (numpy.ndarray) – Field values.

  • name (str, optional) – Name. to store the field. The default is “field”.

  • process (bool, optional) – Whether to process field to apply mean, normalizer and trend. The default is True.

  • save (bool, optional) – Whether to store the field under the given name. The default is True.

Returns

field – Processed field values.

Return type

numpy.ndarray

pre_pos(pos, mesh_type='unstructured')

Preprocessing positions and mesh_type.

Parameters
  • pos (iterable) – the position tuple, containing main direction and transversal directions

  • mesh_type (str, optional) – ‘structured’ / ‘unstructured’ Default: “unstructured”

Returns

  • iso_pos ((d, n), numpy.ndarray) – the isometrized position tuple

  • shape (tuple) – Shape of the resulting field.

set_generator(generator, **generator_kwargs)[source]

Set the generator for the field.

Parameters
  • generator (str, optional) – Name of the generator to use for field generation. Default: “RandMeth”

  • **generator_kwargs – keyword arguments that are forwarded to the generator in use.

structured(*args, **kwargs)

Generate a field on a structured mesh.

See __call__

to_pyvista(field_select='field', fieldname='field')

Create a VTK/PyVista grid of the stored field.

Parameters
  • field_select (str, optional) – Field that should be stored. Can be: “field”, “raw_field”, “krige_field”, “err_field” or “krige_var”. Default: “field”

  • fieldname (str, optional) – Name of the field in the VTK file. Default: “field”

unstructured(*args, **kwargs)

Generate a field on an unstructured mesh.

See __call__

vtk_export(filename, field_select='field', fieldname='field')

Export the stored field to vtk.

Parameters
  • filename (str) – Filename of the file to be saved, including the path. Note that an ending (.vtr or .vtu) will be added to the name.

  • field_select (str, optional) – Field that should be stored. Can be: “field”, “raw_field”, “krige_field”, “err_field” or “krige_var”. Default: “field”

  • fieldname (str, optional) – Name of the field in the VTK file. Default: “field”

property dim

Dimension of the field.

Type

int

property generator

The generator of the field.

Type

callable

property krige

The underlying kriging class.

Type

Krige

property latlon

Whether the field depends on geographical coords.

Type

bool

property mean

The mean of the field.

Type

float or callable

property model

The covariance model of the field.

Type

CovModel

property name

The name of the class.

Type

str

property normalizer

Normalizer of the field.

Type

Normalizer

property trend

The trend of the field.

Type

float or callable

property value_type

Type of the field values (scalar, vector).

Type

str