import numpy as np import vtk from vtk.numpy_interface import dataset_adapter as dsa import PVGeo from PVGeo.filters import CombineTables ################################################################################ # Create some input tables t0 = vtk.vtkTable() t1 = vtk.vtkTable() # Populate the tables n = 100 titles = ('Array 0', 'Array 1', 'Array 2') arr0 = np.random.random(n) # Table 0 arr1 = np.random.random(n) # Table 0 t0.AddColumn(PVGeo.convert_array(arr0, titles[0])) t0.AddColumn(PVGeo.convert_array(arr1, titles[1])) arr2 = np.random.random(n) # Table 1 t1.AddColumn(PVGeo.convert_array(arr2, titles[2])) arrs = [arr0, arr1, arr2] ################################################################################ # Now use the `CombineTables` filter: output = CombineTables().apply(t0, t1) # Here I verify the result wpdi = dsa.WrapDataObject(output) for i in range(len(titles)): arr = wpdi.RowData[titles[i]]
from PVGeo.filters import ReshapeTable ################################################################################ # Create some input table t0 = vtk.vtkTable() # Populate the tables arrs = [None, None, None] n = 400 ncols = 2 nrows = int(n * len(arrs) / ncols) titles = ('Array 0', 'Array 1', 'Array 2') arrs[0] = np.random.random(n) arrs[1] = np.random.random(n) arrs[2] = np.random.random(n) t0.AddColumn(PVGeo.convert_array(arrs[0], titles[0])) t0.AddColumn(PVGeo.convert_array(arrs[1], titles[1])) t0.AddColumn(PVGeo.convert_array(arrs[2], titles[2])) ################################################################################ # Use the filter to reshape the table order = 'F' newtitles = ['Title %d' % i for i in range(ncols)] output = ReshapeTable(order=order, ncols=ncols, nrows=nrows, names=newtitles).apply(t0) ################################################################################ # Check the output against NumPy wpdi = dsa.WrapDataObject(output) tarr = np.zeros((nrows, ncols)) for i in range(ncols):