vtk.numpy_interface.algorithms Module

This module provides a number of algorithms that can be used with the dataset classes defined in the dataset_adapter module. See the documentation of the dataset_adapter for some examples. These algorithms work in serial and in parallel as long as the data is partitioned according to VTK data parallel execution guidelines. For details, see the documentation of individual algorithms.

paraview.vtk.numpy_interface.algorithms.abs(array)

Returns the absolute values of an array of scalars/vectors/tensors.

paraview.vtk.numpy_interface.algorithms.add(array1, val2)

Element by element addition. Both elements can be single values or arrays. Same as +.

paraview.vtk.numpy_interface.algorithms.all(array, axis=None, controller=None)[source]

Returns True if all values of an array evaluate to True, returns False otherwise. This is useful to check if all values of an array match a certain condition such as:

algorithms.all(array > 5)

paraview.vtk.numpy_interface.algorithms.apply_dfunc(dfunc, array1, val2)[source]

Apply a two argument function to each member of a VTKCompositeDataArray and another argument The second argument can be a VTKCompositeDataArray, in which case a one-to-one match between arrays is assumed. Otherwise, the function is applied to the composite array with the second argument repeated. VTKArray and numpy arrays are also supported.

paraview.vtk.numpy_interface.algorithms.apply_ufunc(func, array, args=())[source]

Apply a function to each member of a VTKCompositeDataArray. VTKArray and numpy arrays are also supported.

paraview.vtk.numpy_interface.algorithms.arccos(array)

Computes inverse cosine.

paraview.vtk.numpy_interface.algorithms.arccosh(array)

Computes inverse hyperbolic cosine.

paraview.vtk.numpy_interface.algorithms.arcsin(array)

Computes inverse sine.

paraview.vtk.numpy_interface.algorithms.arcsinh(array)

Computes inverse hyperbolic sine.

paraview.vtk.numpy_interface.algorithms.arctan(array)

Computes inverse tangent.

paraview.vtk.numpy_interface.algorithms.arctan2(array1, val2)

Computes inverse tangent using two arguments.

paraview.vtk.numpy_interface.algorithms.arctanh(array)

Computes inverse hyperbolic tangent.

paraview.vtk.numpy_interface.algorithms.area(ds)

Returns the surface area of each 2D cell in a mesh.

paraview.vtk.numpy_interface.algorithms.aspect(ds)

Returns the aspect ratio of each cell in a mesh. See Verdict documentation for details.

paraview.vtk.numpy_interface.algorithms.aspect_gamma(ds)

Returns the aspect gamma of each cell in a mesh. This metric compares root-mean-square edge length to volume. See Verdict documentation for details.

paraview.vtk.numpy_interface.algorithms.bitwise_or(array1, array2)[source]

Implements element by element or (bitwise, | in C/C++) operation. If one of the arrays is a NoneArray, this will return the array that is not NoneArray, treating NoneArray as 0 in the or operation.

paraview.vtk.numpy_interface.algorithms.ceil(array)

Returns the ceiling of floating point values.

paraview.vtk.numpy_interface.algorithms.condition(ds)

Returns the condition number of each cell in a mesh. See Verdict documentation for details.

paraview.vtk.numpy_interface.algorithms.cos(array)

Computes cosine of values in radians.

paraview.vtk.numpy_interface.algorithms.cosh(array)

Computes hyperbolic cosine.

paraview.vtk.numpy_interface.algorithms.count_per_block(array, axis=None, controller=None)[source]

Return the number of elements of each block in a VTKCompositeDataArray along an axis.

  • if axis is None, the number of all elements (ntuples * ncomponents) is

returned. - if axis is 0, the number of tuples is returned.

paraview.vtk.numpy_interface.algorithms.cross(array1, val2)

Return the cross product of two vectors.

paraview.vtk.numpy_interface.algorithms.curl(array, ds=None)

Returns the curl a vector field.

paraview.vtk.numpy_interface.algorithms.det(array)

Returns the determinant of 2D matrices.

paraview.vtk.numpy_interface.algorithms.determinant(array)

Returns the determinant of 2D matrices.

paraview.vtk.numpy_interface.algorithms.diagonal(ds)

Returns the diagonal length of each cell in a dataset. See Verdict documentation for details

paraview.vtk.numpy_interface.algorithms.divergence(array, ds=None)

Returns the divergence of a vector field.

paraview.vtk.numpy_interface.algorithms.divide(array1, val2)

Element by element division. Both elements can be single values or arrays. Same as /.

paraview.vtk.numpy_interface.algorithms.dot(array1, val2)

Returns the dot product of two vectors.

paraview.vtk.numpy_interface.algorithms.eigenvalue(array)

Returns the eigenvalues of 3x3 matrices. Currently only works with symmetric matrices.

paraview.vtk.numpy_interface.algorithms.eigenvector(array)

Returns the eigenvectors of 3x3 matrices. Currently only works with symmetric matrices.

paraview.vtk.numpy_interface.algorithms.exp(array)

The exponential function.

paraview.vtk.numpy_interface.algorithms.expand_dims(array1, val2)

Insert a new dimension, corresponding to a given position in the array shape. In VTK, this function’s main use is to enable an operator to work on a vector and a scalar field. For example, say you want to divide each component of a vector by the magnitude of that vector. You might try this:

>>> v
VTKArray([[ 1.,  1.,  1.],
       [ 1.,  1.,  1.],
       [ 1.,  1.,  1.],
       [ 1.,  1.,  1.],
       [ 1.,  1.,  1.]])
>>> algs.mag(v)
VTKArray([ 1.73205081,  1.73205081,  1.73205081,  1.73205081,  1.73205081])
>>> v / algs.mag(v)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: operands could not be broadcast together with shapes (5,3) (5)

The division operator does not know how to map a scalar to a vector due to a mismatch in dimensions. This can be solved by making the scalar a vector of 1 component (increasing its dimension to 2) as follows:

>>> v / algs.expand_dims(algs.mag(v), 1)
VTKArray([[ 0.57735027,  0.57735027,  0.57735027],
       [ 0.57735027,  0.57735027,  0.57735027],
       [ 0.57735027,  0.57735027,  0.57735027],
       [ 0.57735027,  0.57735027,  0.57735027],
       [ 0.57735027,  0.57735027,  0.57735027]])
paraview.vtk.numpy_interface.algorithms.flatnonzero(array)

Return indices that are non-zero in the flattened version of the input array.

paraview.vtk.numpy_interface.algorithms.floor(array)

Returns the floor of floating point values.

paraview.vtk.numpy_interface.algorithms.gradient(array, ds=None)

Returns the gradient of scalars or vectors.

paraview.vtk.numpy_interface.algorithms.hypot(array1, val2)

Given the ‘legs’ of a right triangle, return its hypotenuse.

paraview.vtk.numpy_interface.algorithms.inv(array)

Returns the inverse of 3x3 matrices.

paraview.vtk.numpy_interface.algorithms.inverse(array)

Returns the inverse of 3x3 matrices.

paraview.vtk.numpy_interface.algorithms.isnan(array)

Returns a bool array, true if values is nan.

paraview.vtk.numpy_interface.algorithms.jacobian(ds)

Returns the Jacobian of a dataset.

paraview.vtk.numpy_interface.algorithms.laplacian(array, ds=None)

Returns the Laplacian of a scalar field.

paraview.vtk.numpy_interface.algorithms.ln(array)

Returns the natural logarithm of its input.

paraview.vtk.numpy_interface.algorithms.log(array)

Returns the natural logarithm of its input.

paraview.vtk.numpy_interface.algorithms.log10(array)

Returns the base 10 logarithm of its input.

paraview.vtk.numpy_interface.algorithms.logical_not(array)

Computes the truth value of NOT x element-wise.

paraview.vtk.numpy_interface.algorithms.mag(array)

Returns the magnitude of vectors.

paraview.vtk.numpy_interface.algorithms.make_cell_mask_from_NaNs(dataset, array)[source]

This method will create a ghost array corresponding to an input with NaN values. For each NaN value, the output array will have a corresponding value of vtk.vtkDataSetAttributes.HIDDENCELL. These values are also combined with any ghost values that the dataset may have.

paraview.vtk.numpy_interface.algorithms.make_mask_from_NaNs(array, ghost_array=<paraview.vtk.numpy_interface.dataset_adapter.VTKNoneArray object>, is_cell=False)[source]

This method will create a ghost array corresponding to an input with NaN values. For each NaN value, the output array will have a corresponding value of vtk.vtkDataSetAttributes.HIDDENPOINT or HIDDENCELL is the is_cell argument is true. If an input ghost_array is passed, the array is bitwise_or’ed with it, simply adding the new ghost values to it.

paraview.vtk.numpy_interface.algorithms.make_point_mask_from_NaNs(dataset, array)[source]

This method will create a ghost array corresponding to an input with NaN values. For each NaN value, the output array will have a corresponding value of vtk.vtkDataSetAttributes.HIDDENPOINT. These values are also combined with any ghost values that the dataset may have.

paraview.vtk.numpy_interface.algorithms.make_vector(arrayx, arrayy, arrayz=None)[source]

Given 2 or 3 scalar arrays, returns a vector array. If only 2 scalars are provided, the third component will be set to 0.

paraview.vtk.numpy_interface.algorithms.max(array, axis=None, controller=None)[source]

Returns the max of all values along a particular axis (dimension). Given an array of m tuples and n components: * Default is to return the max of all values in an array. * axis=0: Return the max values of all tuples and return a

one tuple, n-component array.
  • axis=1: Return the max values of all components of each tuple and return an m-tuple, 1-component array.

When called in parallel, this function will compute the max across processes when a controller argument is passed or the global controller is defined. To disable parallel summing when running in parallel, pass a dummy controller as follows:

max(array, controller=vtk.vtkDummyController()).

paraview.vtk.numpy_interface.algorithms.max_angle(ds)

Returns the maximum angle of each cell in a dataset. See Verdict documentation for details

paraview.vtk.numpy_interface.algorithms.max_per_block(array, axis=None, controller=None)[source]

Returns the max of all values along a particular axis (dimension) for each block of a VTKCompositeDataArray. Given an array of m tuples and n components: * Default is to return the max of all values in an array. * axis=0: Return the max values of all components and return a one

tuple, n-component array.
  • axis=1: Return the max values of all components of each tuple and return an m-tuple, 1-component array.

When called in parallel, this function will compute the max across processes when a controller argument is passed or the global controller is defined. To disable parallel summing when running in parallel, pass a dummy controller as follows:

max_per_block(array, controller=vtk.vtkDummyController()).

paraview.vtk.numpy_interface.algorithms.mean(array, axis=None, controller=None, size=None)[source]

Returns the mean of all values along a particular axis (dimension). Given an array of m tuples and n components: * Default is to return the mean of all values in an array. * axis=0: Return the mean values of all components and return a one

tuple, n-component array.
  • axis=1: Return the mean values of all components of each tuple and return an m-tuple, 1-component array.

When called in parallel, this function will compute the mean across processes when a controller argument is passed or the global controller is defined. To disable parallel summing when running in parallel, pass a dummy controller as follows:

mean(array, controller=vtk.vtkDummyController()).

paraview.vtk.numpy_interface.algorithms.mean_per_block(array, axis=None, controller=None)[source]

Returns the mean of all values along a particular axis (dimension) for each block of a VTKCompositeDataArray.

Given an array of m tuples and n components: * Default is to return the mean of all values in an array. * axis=0: Return the mean values of all components and return a one

tuple, n-component array.
  • axis=1: Return the mean values of all components of each tuple and return an m-tuple, 1-component array.

When called in parallel, this function will compute the mean across processes when a controller argument is passed or the global controller is defined. To disable parallel summing when running in parallel, pass a dummy controller as follows:

mean(array, controller=vtk.vtkDummyController()).

paraview.vtk.numpy_interface.algorithms.min(array, axis=None, controller=None)[source]

Returns the min of all values along a particular axis (dimension). Given an array of m tuples and n components: * Default is to return the min of all values in an array. * axis=0: Return the min values of all tuples and return a one

tuple, n-component array.
  • axis=1: Return the min values of all components of each tuple and return an m-tuple, 1-component array.

When called in parallel, this function will compute the min across processes when a controller argument is passed or the global controller is defined. To disable parallel summing when running in parallel, pass a dummy controller as follows:

min(array, controller=vtk.vtkDummyController()).

paraview.vtk.numpy_interface.algorithms.min_angle(ds)

Returns the minimum angle of each cell in a dataset.

paraview.vtk.numpy_interface.algorithms.min_per_block(array, axis=None, controller=None)[source]

Returns the min of all values along a particular axis (dimension) for each block of a VTKCompositeDataArray. Given an array of m tuples and n components: * Default is to return the min of all values in an array. * axis=0: Return the min values of all components and return a one

tuple, n-component array.
  • axis=1: Return the min values of all components of each tuple and return an m-tuple, 1-component array.

When called in parallel, this function will compute the min across processes when a controller argument is passed or the global controller is defined. To disable parallel summing when running in parallel, pass a dummy controller as follows:

min_per_block(array, controller=vtk.vtkDummyController()).

paraview.vtk.numpy_interface.algorithms.mod(array1, val2)

Computes x1 - floor(x1 / x2) * x2, the result has the same sign as the divisor x2. It is equivalent to the Python modulus operator x1 % x2. Same as remainder.

paraview.vtk.numpy_interface.algorithms.multiply(array1, val2)

Element by element multiplication. Both elements can be single values or arrays. Same as *.

paraview.vtk.numpy_interface.algorithms.negative(array)

Numerical negative, element-wise.

paraview.vtk.numpy_interface.algorithms.nonzero(array)

Return the indices of the non-zero elements of the input array.

paraview.vtk.numpy_interface.algorithms.norm(array)

Computes the normalized values of vectors.

paraview.vtk.numpy_interface.algorithms.power(array1, val2)

First array elements raised to powers from second array, element-wise.

paraview.vtk.numpy_interface.algorithms.reciprocal(array)

Return the reciprocal (1/x) of the argument, element-wise.

paraview.vtk.numpy_interface.algorithms.remainder(array1, val2)

Computes x1 - floor(x1 / x2) * x2, the result has the same sign as the divisor x2. It is equivalent to the Python modulus operator x1 % x2. Same as mod.

paraview.vtk.numpy_interface.algorithms.rint(array)

Round elements of the array to the nearest integer.

paraview.vtk.numpy_interface.algorithms.shape(array)[source]

Returns the shape (dimensions) of an array.

paraview.vtk.numpy_interface.algorithms.shear(ds)

Returns the shear of each cell in a dataset. See Verdict documentation for details.

paraview.vtk.numpy_interface.algorithms.sin(array)

Computes sine of values in radians.

paraview.vtk.numpy_interface.algorithms.sinh(array)

Computes hyperbolic sine.

paraview.vtk.numpy_interface.algorithms.skew(ds)

Returns the skew of each cell in a dataset. See Verdict documentation for details.

paraview.vtk.numpy_interface.algorithms.sqrt(array)

Computes square root.

paraview.vtk.numpy_interface.algorithms.square(array)

Return the element-wise square of the input.

paraview.vtk.numpy_interface.algorithms.std(array, axis=None, controller=None)[source]

Returns the standard deviation of all values along a particular axis (dimension). Given an array of m tuples and n components: * Default is to return the standard deviation of all values in an array. * axis=0: Return the standard deviation values of all components and

return a one tuple, n-component array.
  • axis=1: Return the standard deviation values of all components of each tuple and return an m-tuple, 1-component array.

When called in parallel, this function will compute the standard deviation across processes when a controller argument is passed or the global controller is defined. To disable parallel summing when running in parallel, pass a dummy controller as follows:

std(array, controller=vtk.vtkDummyController()).

paraview.vtk.numpy_interface.algorithms.strain(array, ds=None)

Given a deformation vector, this function computes the infinitesimal (Cauchy) strain tensor. It can also be used to compute strain rate if the input is velocity.

paraview.vtk.numpy_interface.algorithms.subtract(array1, val2)

Returns the difference of two values element-wise. Same as x - y.

paraview.vtk.numpy_interface.algorithms.sum(array, axis=None, controller=None)[source]

Returns the sum of all values along a particular axis (dimension). Given an array of m tuples and n components: * Default is to return the sum of all values in an array. * axis=0: Sum values of all components and return a one tuple,

n-component array.
  • axis=1: Sum values of all components of each tuple and return an m-tuple, 1-component array.

When called in parallel, this function will sum across processes when a controller argument is passed or the global controller is defined. To disable parallel summing when running in parallel, pass a dummy controller as follows:

sum(array, controller=vtk.vtkDummyController()).

paraview.vtk.numpy_interface.algorithms.sum_per_block(array, axis=None, controller=None)[source]

Returns the sum of all values along a particular axis (dimension) for each block of an VTKCompositeDataArray.

Given an array of m tuples and n components: * Default is to return the sum of all values in an array. * axis=0: Sum values of all components and return a one tuple,

n-component array.
  • axis=1: Sum values of all components of each tuple and return an m-tuple, 1-component array.

When called in parallel, this function will sum across processes when a controller argument is passed or the global controller is defined. To disable parallel summing when running in parallel, pass a dummy controller as follows:

sum_per_block(array, controller=vtk.vtkDummyController()).

paraview.vtk.numpy_interface.algorithms.surface_normal(ds)

Returns the surface normal of each cell in a dataset.

paraview.vtk.numpy_interface.algorithms.tan(array)

Computes tangent of values in radians.

paraview.vtk.numpy_interface.algorithms.tanh(array)

Computes hyperbolic tangent.

paraview.vtk.numpy_interface.algorithms.trace(array)

Returns the trace of square matrices.

paraview.vtk.numpy_interface.algorithms.unstructured_from_composite_arrays(points, arrays, controller=None)[source]

Given a set of VTKCompositeDataArrays, creates a vtkUnstructuredGrid. The main goal of this function is to transform the output of XXX_per_block() methods to a single dataset that can be visualized and further processed. Here arrays is an iterable (e.g. list) of (array, name) pairs. Here is an example:

centroid = mean_per_block(composite_data.Points) T = mean_per_block(composite_data.PointData[‘Temperature’]) ug = unstructured_from_composite_arrays(centroid, (T, ‘Temperature’))

When called in parallel, this function makes sure that each array in the input dataset is represented only on 1 process. This is important because methods like mean_per_block() return the same value for blocks that are partitioned on all of the participating processes. If the same point were to be created across multiple processes in the output, filters like histogram would report duplicate values erroneously.

paraview.vtk.numpy_interface.algorithms.var(array, axis=None, controller=None)[source]

Returns the variance of all values along a particular axis (dimension). Given an array of m tuples and n components: * Default is to return the variance of all values in an array. * axis=0: Return the variance values of all components and return a one

tuple, n-component array.
  • axis=1: Return the variance values of all components of each tuple and return an m-tuple, 1-component array.

When called in parallel, this function will compute the variance across processes when a controller argument is passed or the global controller is defined. To disable parallel summing when running in parallel, pass a dummy controller as follows:

var(array, controller=vtk.vtkDummyController()).

paraview.vtk.numpy_interface.algorithms.vertex_normal(ds)

Returns the normal at each vertex of a dataset, which is defined as the average of the cell normals of all cells containing that vertex.

paraview.vtk.numpy_interface.algorithms.volume(ds)

Returns the volume of each cell in a dataset. Use sum to calculate total volume of a dataset.

paraview.vtk.numpy_interface.algorithms.vorticity(array, ds=None)

Given a velocity field, calculates vorticity.

paraview.vtk.numpy_interface.algorithms.where(array)

Returns the location (indices) of an array where the given expression is true. For scalars, it returns a single array of indices. For vectors and matrices, it returns two arrays: first with tuple indices, second with component indices. The output of this method can be used to extract the values from the array also by using it as the index of the [] operator.

For example:

>>> algs.where(algs.array([1,2,3]) == 2)
(array([1]),)
>>> algs.where(algs.array([[1,2,3], [2,1,1]]) == 2)
(array([0, 1]), array([1, 0]))
>>> a = array([[1,2,3], [2,1,1]])
>>> indices = algs.where(a > 2)
>>> a[indices]
array([3])