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.

addArraysFromDataFrame

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

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

convertArray

PVGeo.interface.convertArray(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

convertCellConn

PVGeo.interface.convertCellConn(cellConn)[source]

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

convertStringArray

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

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

Returns:the converted array
Return type:vtkStringArray

dataFrameToTable

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

Converts a pandas DataFrame to a vtkTable

getArray

PVGeo.interface.getArray(dataset, name, vtkObj=False)[source]

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

getDataDict

PVGeo.interface.getDataDict(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.

getVTKtype

PVGeo.interface.getVTKtype(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

getdTypes

PVGeo.interface.getdTypes(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)

placeArrInTable

PVGeo.interface.placeArrInTable(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

pointsToPolyData

PVGeo.interface.pointsToPolyData(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

tableToDataFrame

PVGeo.interface.tableToDataFrame(table)[source]

Converts a vtkTable to a pandas DataFrame