Mesh Tools

This provides a class for discretizing data in a convienant way that makes sense for our spatially referenced data/models.

Grid

class wtools.mesh.Grid(h=None, x0=(0.0, 0.0, 0.0), models=None, **kwargs)[source]

Bases: discretize.TensorMesh.TensorMesh, wtools.fileio.GridFileIO

A data structure to store a model space discretization and different attributes of that model space.

Example:
>>> import wtools
>>> import numpy as np
>>> models = {
    'rand': np.random.random(1000).reshape((10,10,10)),
    'spatial': np.arange(1000).reshape((10,10,10)),
    }
>>> grid = wtools.Grid(models=models)
>>> grid.validate() # Make sure the data object was created successfully
True
Note:
See Jupyter notebooks under the examples directory

Required Properties:

  • h (a list of Array): h is a list containing the cell widths of the tensor mesh in each dimension., a list (each item is a list or numpy array of <class ‘float’> with shape (*)) with length between 0 and 3
  • x0 (Array): origin of the mesh (dim, ), a list or numpy array of <class ‘float’> with shape (*)

Optional Properties:

  • models (Dictionary): The volumetric data as a 3D NumPy arrays in <X,Y,Z> or <i,j,k> coordinates. Each key value pair represents a different model for the gridded model space. Keys will be treated as the string name of the model., a dictionary (keys: a unicode string; values: a list or numpy array of <class ‘float’>, <class ‘int’> with shape (*, *, *))
bounds

The bounds of the grid

equal(other)[source]

Compare this Grid to another Grid

get_data_range(key)[source]

Get the data range for a given model

keys

List of the string names for each of the models

models

a unicode string; values: a list or numpy array of <class ‘float’>, <class ‘int’> with shape (*, *, *))

Type:models (Dictionary)
Type:The volumetric data as a 3D NumPy arrays in <X,Y,Z> or <i,j,k> coordinates. Each key value pair represents a different model for the gridded model space. Keys will be treated as the string name of the model., a dictionary (keys
models_flat

Returns flattened model dictionary in Fortran ordering

plotSlice(key, **kwargs)[source]

Plots a 2D slice of the mesh

Parameters:key (str) – the model name to plot

Note

See the discretize code docs for more details.

plot_3d_slicer(key, **kwargs)[source]

Plot slices of a 3D volume, interactively (scroll wheel).

If called from a notebook, make sure to set

%matplotlib notebook

See the class discretize.View.Slicer for more information.

It returns nothing. However, if you need the different figure handles you can get it via

fig = plt.gcf()

and subsequently its children via

fig.get_children()

and recursively deeper, e.g.,

fig.get_children()[0].get_children().
shape

3D shape of the grid (number of cells in all three directions)

toVTK()[source]
to_data_frame(order='C')[source]

Returns the models in this Grid to a Pandas DataFrame with all arrays flattened in the specified order. A header attribute is added to the DataFrame to specified the grid extents. Much metadata is lost in this conversion.

writeVTK()[source]

Makes and saves a VTK rectilinear file (vtr) for a Tensor mesh and model.

Input: :param str fileName: path to the output vtk file or just its name if directory is specified :param str directory: directory where the UBC GIF file lives :param dict models: dictionary of numpy.array - Name(‘s) and array(‘s). Match number of cells