Gridded Data

Gridded datasets in pyvista capture vtkRectilinearGrid and vtkImageData data objects on the VTK backend. These data types have common features which are encompassed int their shared inheritance of pyvista.Grid

Attributes

dimensions

Returns a length 3 tuple of the grid’s dimensions - these are effectively the number of nodes along each of the three dataset axes

Methods

class pyvista.Grid(*args, **kwargs)

Bases: pyvista.core.common.Common

A class full of common methods for non-pointset grids

property dimensions

Returns a length 3 tuple of the grid’s dimensions - these are effectively the number of nodes along each of the three dataset axes

Rectilinear Grid

Attributes

points

returns a pointer to the points as a numpy object

x

Get the coordinates along the X-direction

y

Get the coordinates along the Y-direction

z

Get the coordinates along the Z-direction

Methods

save(filename[, binary])

Writes a rectilinear grid to disk.

class pyvista.RectilinearGrid(*args, **kwargs)

Bases: vtkCommonDataModelPython.vtkRectilinearGrid, pyvista.core.grid.Grid

Extends the functionality of a vtk.vtkRectilinearGrid object Can be initialized in several ways:

  • Create empty grid

  • Initialize from a vtk.vtkRectilinearGrid object

  • Initialize directly from the point arrays

See _from_arrays in the documentation for more details on initializing from point arrays

Examples

>>> import pyvista
>>> import vtk
>>> import numpy as np
>>> # Create empty grid
>>> grid = pyvista.RectilinearGrid()
>>> # Initialize from a vtk.vtkRectilinearGrid object
>>> vtkgrid = vtk.vtkRectilinearGrid()
>>> grid = pyvista.RectilinearGrid(vtkgrid)
>>> # Create from NumPy arrays
>>> xrng = np.arange(-10, 10, 2)
>>> yrng = np.arange(-10, 10, 5)
>>> zrng = np.arange(-10, 10, 1)
>>> grid = pyvista.RectilinearGrid(xrng, yrng, zrng)
property points

returns a pointer to the points as a numpy object

save(filename, binary=True)

Writes a rectilinear grid to disk.

Parameters
  • filename (str) – Filename of grid to be written. The file extension will select the type of writer to use. “.vtk” will use the legacy writer, while “.vtr” will select the VTK XML writer.

  • binary (bool, optional) – Writes as a binary file by default. Set to False to write ASCII.

Notes

Binary files write much faster than ASCII, but binary files written on one system may not be readable on other systems. Binary can be used only with the legacy writer.

property x

Get the coordinates along the X-direction

property y

Get the coordinates along the Y-direction

property z

Get the coordinates along the Z-direction

Uniform Grid

PyVista’s definition of a uniform grid is an extension of VTK’s vtkImageData

Attributes

origin

Origin of the grid (bottom southwest corner)

points

returns a pointer to the points as a numpy object

spacing

Get the spacing for each axial direction.

x

all the X points

y

all the Y points

z

all the Z points

Methods

cast_to_rectilinear_grid()

Cast this unifrom grid to a pyvista.RectilinearGrid

cast_to_structured_grid()

Cast this unifrom grid to a pyvista.StructuredGrid

save(filename[, binary])

Writes image data grid to disk.

class pyvista.UniformGrid(*args, **kwargs)

Bases: vtkCommonDataModelPython.vtkImageData, pyvista.core.grid.Grid

Extends the functionality of a vtk.vtkImageData object Can be initialized in several ways:

  • Create empty grid

  • Initialize from a vtk.vtkImageData object

  • Initialize directly from the point arrays

See _from_specs in the documentation for more details on initializing from point arrays

Examples

>>> import pyvista
>>> import vtk
>>> import numpy as np
>>> # Create empty grid
>>> grid = pyvista.UniformGrid()
>>> # Initialize from a vtk.vtkImageData object
>>> vtkgrid = vtk.vtkImageData()
>>> grid = pyvista.UniformGrid(vtkgrid)
>>> # Using just the grid dimensions
>>> dims = (10, 10, 10)
>>> grid = pyvista.UniformGrid(dims)
>>> # Using dimensions and spacing
>>> spacing = (2, 1, 5)
>>> grid = pyvista.UniformGrid(dims, spacing)
>>> # Using dimensions, spacing, and an origin
>>> origin = (10, 35, 50)
>>> grid = pyvista.UniformGrid(dims, spacing, origin)
cast_to_rectilinear_grid()

Cast this unifrom grid to a pyvista.RectilinearGrid

cast_to_structured_grid()

Cast this unifrom grid to a pyvista.StructuredGrid

property origin

Origin of the grid (bottom southwest corner)

property points

returns a pointer to the points as a numpy object

save(filename, binary=True)

Writes image data grid to disk.

Parameters
  • filename (str) – Filename of grid to be written. The file extension will select the type of writer to use. “.vtk” will use the legacy writer, while “.vti” will select the VTK XML writer.

  • binary (bool, optional) – Writes as a binary file by default. Set to False to write ASCII.

Notes

Binary files write much faster than ASCII, but binary files written on one system may not be readable on other systems. Binary can be used only with the legacy writer.

property spacing

Get the spacing for each axial direction.

property x

all the X points

property y

all the Y points

property z

all the Z points