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 structures via
Python data structures that are easier to perform numerical operations on.
add_arrays_from_data_frame
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 isvtkDataArray
then returns NumPyndarray
). If pdf==True and the input isvtkDataArry
, return a pandas DataFrame.- Return type:
vtkDataArray, ndarray, or DataFrame
convert_cell_conn
convert_string_array
- PVGeo.interface.convert_string_array(arr, name=None)[source]
Convert a numpy array of strings to a vtkStringArray or vice versa.
- Parameters:
arr (numpy.ndarray) – Numpy string array to convert.
name (str, optional) – Name to set the vtkStringArray to.
- Returns:
VTK string array.
- Return type:
vtkStringArray
Notes
Note that this is terribly inefficient. If you have ideas on how to make this faster, please consider opening a pull request.
data_frame_to_table
get_array
get_data_dict
get_dtypes
get_vtk_type
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