gstools.tools

GStools subpackage providing miscellaneous tools.

Export

vtk_export(filename, pos, fields[, mesh_type]) Export a field to vtk.
vtk_export_structured(filename, pos, fields) Export a field to vtk structured rectilinear grid file.
vtk_export_unstructured(filename, pos, fields) Export a field to vtk unstructured grid file.
to_vtk(pos, fields[, mesh_type]) Create a VTK/PyVista grid.
to_vtk_structured(pos, fields) Create a vtk structured rectilinear grid from a field.
to_vtk_unstructured(pos, fields) Export a field to vtk structured rectilinear grid file.

Special functions

inc_gamma(s, x) The (upper) incomplete gamma function.
exp_int(s, x) The exponential integral E_s(x).
inc_beta(a, b, x) The incomplete Beta function.
tplstable_cor(r, len_scale, hurst, alpha) The correlation function of the TPLStable model.
tpl_exp_spec_dens(k, dim, len_scale, hurst) Spectal density of the TPLExponential covariance model.
tpl_gau_spec_dens(k, dim, len_scale, hurst) Spectal density of the TPLGaussian covariance model.

Geometric

xyz2pos(x[, y, z, dtype, max_dim]) Convert x, y, z to postional arguments.
pos2xyz(pos[, dtype, calc_dim, max_dim]) Convert postional arguments to x, y, z.
r3d_x(theta) Rotation matrix about x axis.
r3d_y(theta) Rotation matrix about y axis.
r3d_z(theta) Rotation matrix about z axis.

gstools.tools.vtk_export(filename, pos, fields, mesh_type='unstructured')[source]

Export a 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.
  • pos (list) – the position tuple, containing main direction and transversal directions
  • fields (dict or numpy.ndarray) – [Un]structured fields to be saved. Either a single numpy array as returned by SRF, or a dictionary of fields with theirs names as keys.
  • mesh_type (str, optional) – ‘structured’ / ‘unstructured’. Default: structured
gstools.tools.vtk_export_structured(filename, pos, fields)[source]

Export a field to vtk structured rectilinear grid file.

Parameters:
  • filename (str) – Filename of the file to be saved, including the path. Note that an ending (.vtr) will be added to the name.
  • pos (list) – the position tuple, containing main direction and transversal directions
  • fields (dict or numpy.ndarray) – Structured fields to be saved. Either a single numpy array as returned by SRF, or a dictionary of fields with theirs names as keys.
gstools.tools.vtk_export_unstructured(filename, pos, fields)[source]

Export a field to vtk unstructured grid file.

Parameters:
  • filename (str) – Filename of the file to be saved, including the path. Note that an ending (.vtu) will be added to the name.
  • pos (list) – the position tuple, containing main direction and transversal directions
  • fields (dict or numpy.ndarray) – Unstructured fields to be saved. Either a single numpy array as returned by SRF, or a dictionary of fields with theirs names as keys.
gstools.tools.to_vtk(pos, fields, mesh_type='unstructured')[source]

Create a VTK/PyVista grid.

Parameters:
  • pos (list) – the position tuple, containing main direction and transversal directions
  • fields (dict or numpy.ndarray) – [Un]structured fields to be saved. Either a single numpy array as returned by SRF, or a dictionary of fields with theirs names as keys.
  • mesh_type (str, optional) – ‘structured’ / ‘unstructured’. Default: structured
Returns:

This will return a PyVista object for the given field data in its appropriate type. Structured meshes will return a pyvista.RectilinearGrid and unstructured meshes will return an pyvista.UnstructuredGrid object.

Return type:

pyvista.RectilinearGrid or pyvista.UnstructuredGrid

gstools.tools.to_vtk_structured(pos, fields)[source]

Create a vtk structured rectilinear grid from a field.

Parameters:
  • pos (list) – the position tuple, containing main direction and transversal directions
  • fields (dict or numpy.ndarray) – Structured fields to be saved. Either a single numpy array as returned by SRF, or a dictionary of fields with theirs names as keys.
Returns:

A PyVista rectilinear grid of the structured field data. Data arrays live on the point data of this PyVista dataset.

Return type:

pyvista.RectilinearGrid

gstools.tools.to_vtk_unstructured(pos, fields)[source]

Export a field to vtk structured rectilinear grid file.

Parameters:
  • pos (list) – the position tuple, containing main direction and transversal directions
  • fields (dict or numpy.ndarray) – Unstructured fields to be saved. Either a single numpy array as returned by SRF, or a dictionary of fields with theirs names as keys.
Returns:

A PyVista unstructured grid of the unstructured field data. Data arrays live on the point data of this PyVista dataset. This is essentially a point cloud with no topology.

Return type:

pyvista.UnstructuredGrid

gstools.tools.inc_gamma(s, x)[source]

The (upper) incomplete gamma function.

Given by: \Gamma(s,x) = \int_x^{\infty} t^{s-1}\,e^{-t}\,{\rm d}t

Parameters:
gstools.tools.exp_int(s, x)[source]

The exponential integral E_s(x).

Given by: E_s(x) = \int_1^\infty \frac{e^{-xt}}{t^s}\,\mathrm dt

Parameters:
  • s (float) – exponent in the integral (should be > -100)
  • x (numpy.ndarray) – input values
gstools.tools.inc_beta(a, b, x)[source]

The incomplete Beta function.

Given by: B(a,b;\,x) = \int_0^x t^{a-1}\,(1-t)^{b-1}\,dt

Parameters:
  • a (float) – first exponent in the integral
  • b (float) – second exponent in the integral
  • x (numpy.ndarray) – input values
gstools.tools.tplstable_cor(r, len_scale, hurst, alpha)[source]

The correlation function of the TPLStable model.

Given by the following correlation function:

\rho(r) =
\frac{2H}{\alpha} \cdot
E_{1+\frac{2H}{\alpha}}
\left(\left(\frac{r}{\ell}\right)^{\alpha} \right)

Parameters:
  • r (numpy.ndarray) – input values
  • len_scale (float) – length-scale of the model.
  • hurst (float) – Hurst coefficient of the power law.
  • alpha (float, optional) – Shape parameter of the stable model.
gstools.tools.tpl_exp_spec_dens(k, dim, len_scale, hurst, len_low=0.0)[source]

Spectal density of the TPLExponential covariance model.

Parameters:
  • k (float) – Radius of the phase: k=\left\Vert\mathbf{k}\right\Vert
  • dim (int) – Dimension of the model.
  • len_scale (float) – Length scale of the model.
  • hurst (float) – Hurst coefficient of the power law.
  • len_low (float, optional) – The lower length scale truncation of the model. Default: 0.0
Returns:

spectal density of the TPLExponential model

Return type:

float

gstools.tools.tpl_gau_spec_dens(k, dim, len_scale, hurst, len_low=0.0)[source]

Spectal density of the TPLGaussian covariance model.

Parameters:
  • k (float) – Radius of the phase: k=\left\Vert\mathbf{k}\right\Vert
  • dim (int) – Dimension of the model.
  • len_scale (float) – Length scale of the model.
  • hurst (float) – Hurst coefficient of the power law.
  • len_low (float, optional) – The lower length scale truncation of the model. Default: 0.0
Returns:

spectal density of the TPLExponential model

Return type:

float

gstools.tools.xyz2pos(x, y=None, z=None, dtype=None, max_dim=3)[source]

Convert x, y, z to postional arguments.

Parameters:
  • x (numpy.ndarray) – grid axis in x-direction if structured, or first components of position vectors if unstructured
  • y (numpy.ndarray, optional) – analog to x
  • z (numpy.ndarray, optional) – analog to x
  • dtype (data-type, optional) – The desired data-type for the array. If not given, then the type will be determined as the minimum type required to hold the objects in the sequence. Default: None
  • max_dim (int, optional) – Cut of information above the given dimension. Default: 3
Returns:

pos – the position tuple

Return type:

tuple of numpy.ndarray

gstools.tools.pos2xyz(pos, dtype=None, calc_dim=False, max_dim=3)[source]

Convert postional arguments to x, y, z.

Parameters:
  • pos (iterable) – the position tuple, containing main direction and transversal directions
  • dtype (data-type, optional) – The desired data-type for the array. If not given, then the type will be determined as the minimum type required to hold the objects in the sequence. Default: None
  • calc_dim (bool, optional) – State if the dimension should be returned. Default: False
  • max_dim (int, optional) – Cut of information above the given dimension. Default: 3
Returns:

Notes

If len(pos) > 3, everything after pos[2] will be ignored.

gstools.tools.r3d_x(theta)[source]

Rotation matrix about x axis.

Parameters:theta (float) – Rotation angle
Returns:Rotation matrix.
Return type:numpy.ndarray
gstools.tools.r3d_y(theta)[source]

Rotation matrix about y axis.

Parameters:theta (float) – Rotation angle
Returns:Rotation matrix.
Return type:numpy.ndarray
gstools.tools.r3d_z(theta)[source]

Rotation matrix about z axis.

Parameters:theta (float) – Rotation angle
Returns:Rotation matrix.
Return type:numpy.ndarray