Interface

The interface module provides functions to convert/cast between common VTK and NumPy/Pandas data types. These methods provide a simple to use interface for VTK data types so that users can make changes to VTK data strucutres via Python data structures that are a bit easier to perform numerical operations upon.

add_arrays_from_data_frame

PVGeo.interface.add_arrays_from_data_frame(pdo, field, df)[source]

Add all of the arrays from a given data frame to an output’s data

convert_array

PVGeo.interface.convert_array(arr, name='Data', deep=0, array_type=None, pdf=False)[source]

A helper to convert a NumPy array to a vtkDataArray or vice versa

Parameters
  • arr (ndarray or vtkDataArry) – A numpy array or vtkDataArry to convert

  • name (str) – the name of the data array for VTK

  • deep (bool, int) – if input is numpy array then deep copy values

  • pdf (bool) – if input is vtkDataArry, make a pandas DataFrame of the array

Returns

the converted array (if input is a NumPy ndaray then returns vtkDataArray or is input is vtkDataArray then returns NumPy ndarray). If pdf==True and the input is vtkDataArry, return a pandas DataFrame.

Return type

vtkDataArray, ndarray, or DataFrame

convert_cell_conn

PVGeo.interface.convert_cell_conn(cell_connectivity)[source]

Converts cell connectivity arrays to a cell matrix array that makes sense for VTK cell arrays.

convert_string_array

PVGeo.interface.convert_string_array(arr, name='Strings')[source]

A helper to convert a numpy array of strings to a vtkStringArray

Returns

the converted array

Return type

vtkStringArray

data_frame_to_table

PVGeo.interface.data_frame_to_table(df, pdo=None)[source]

Converts a pandas DataFrame to a vtkTable

get_array

PVGeo.interface.get_array(dataset, name, vtk_object=False)[source]

Given an input dataset, this will return the named array as a NumPy array or a vtkDataArray if spceified

get_data_dict

PVGeo.interface.get_data_dict(dataset, field='cell')[source]

Given an input dataset, this will return all the arrays in that object’s cell/point/field/row data as named NumPy arrays in a dictionary.

get_dtypes

PVGeo.interface.get_dtypes(dtype='', endian=None)[source]

This converts char dtypes and an endian to a numpy and VTK data type.

Returns

the numpy data type and the integer type id specified in vtkType.h for VTK data types

Return type

tuple (numpy.dtype, int)

get_vtk_type

PVGeo.interface.get_vtk_type(typ)[source]

This looks up the VTK type for a give python data type.

Returns

the integer type id specified in vtkType.h

Return type

int

place_array_in_table

PVGeo.interface.place_array_in_table(ndarr, titles, pdo)[source]

Takes a 1D/2D numpy array and makes a vtkTable of it

Parameters
  • ndarr (numpy.ndarray) – The 1D/2D array to be converted to a table

  • titles (list or tuple) – The titles for the arrays in the table. Must have same number of elements as columns in input ndarray

  • pdo (vtkTable) – The output data object pointer

Returns

returns the same input pdo table

Return type

vtkTable

points_to_poly_data

PVGeo.interface.points_to_poly_data(points, copy_z=False)[source]

Create vtkPolyData from a numpy array of XYZ points. If the points have more than 3 dimensions, then all dimensions after the third will be added as attributes. Assume the first three dimensions are the XYZ coordinates.

Parameters
  • points (np.ndarray or pandas.DataFrame) – The points and pointdata

  • copy_z (bool) – A flag on whether to append the z values as a PointData array

Returns

points with point-vertex cells

Return type

vtkPolyData

table_to_data_frame

PVGeo.interface.table_to_data_frame(table)[source]

Converts a vtkTable to a pandas DataFrame

wrap_pyvista

PVGeo.interface.wrap_pyvista(dataset)[source]

This will wrap any given VTK dataset via the vtkInterface Python package if it is available and return the wrapped data object. If pyvista is unavailable, then the given object is returned.