我正在尝试使用Paraview 4.2从Python脚本中的切片中提取数据。 我有这样的事情:
from paraview.numpy_support import vtk_to_numpy
from paraview.simple import *
import os
os.environ["DISPLAY"] = ":0"
paraview.simple._DisableFirstRenderCameraReset()
# create a new 'XDMF Reader'
xDMFtemporalFieldsxmf = XDMFReader(FileNames=['/XDMF.temporalFields.xmf'])
# Properties modified on xDMFtemporalFieldsxmf
xDMFtemporalFieldsxmf.PointArrayStatus = ['DensityProperty-mesh', 'VelocityField']
xDMFtemporalFieldsxmf.CellArrayStatus = []
# create a new 'Slice'
slice1 = Slice(Input=xDMFtemporalFieldsxmf)
# create a new 'Clip'
clip1 = Clip(Input=slice1)
clip1.ClipType = 'Scalar'
clip1.Value = 1200.0
因此,我要做的就是从剪辑中提取VelocityField数据,最好是为每个数据点指定坐标位置。
这是我的一些探索:
>> print clip1
>> print clip1.PointData.keys()
[]
>> print clip1.FieldData.keys()
[]
>> proxy = servermanager.Proxy(proxy=clip1.SMProxy)
>> for property in proxy:
>> print property
None
0
0
[None, '']
0
1200.0
>> print paraview.numpy_support.vtk_to_numpy(clip1.SMProxy)
AttributeError Traceback (most recent call last)
in ()
----> 1 print paraview.numpy_support.vtk_to_numpy(clip1.SMProxy)
/home/luke/Programs/paraview4.2/lib/site-packages/paraview/numpy_support.pyc in vtk_to_numpy(vtk_array)
202
203 """
--> 204 typ = vtk_array.GetDataType()
205 assert typ in get_vtk_to_numpy_typemap().keys(), \
206 "Unsupported array type %s"%typ
AttributeError: GetDataType
>> data = servermanager.Fetch(clip1)
>> print data
vtkUnstructuredGrid (0x6276dc0)
Debug: Off
Modified Time: 37918079
Reference Count: 1
Registered Events: (none)
Information: 0x65f2f40
Data Released: False
Global Release Data: Off
UpdateTime: 0
Field Data:
Debug: Off
Modified Time: 37918063
Reference Count: 1
Registered Events: (none)
Number Of Arrays: 0
Number Of Components: 0
Number Of Tuples: 0
Number Of Points: 0
Number Of Cells: 0
Cell Data:
Debug: Off
Modified Time: 37918077
Reference Count: 1
Registered Events: (none)
Number Of Arrays: 0
Number Of Components: 0
Number Of Tuples: 0
Copy Tuple Flags: ( 1 1 1 1 1 0 1 1 )
Interpolate Flags: ( 1 1 1 1 1 0 0 1 )
Pass Through Flags: ( 1 1 1 1 1 1 1 1 )
Scalars: (none)
Vectors: (none)
Normals: (none)
TCoords: (none)
Tensors: (none)
GlobalIds: (none)
PedigreeIds: (none)
EdgeFlag: (none)
Point Data:
Debug: Off
Modified Time: 37918079
Reference Count: 1
Registered Events: (none)
Number Of Arrays: 0
Number Of Components: 0
Number Of Tuples: 0
Copy Tuple Flags: ( 1 1 1 1 1 0 1 1 )
Interpolate Flags: ( 1 1 1 1 1 0 0 1 )
Pass Through Flags: ( 1 1 1 1 1 1 1 1 )
Scalars: (none)
Vectors: (none)
Normals: (none)
TCoords: (none)
Tensors: (none)
GlobalIds: (none)
PedigreeIds: (none)
EdgeFlag: (none)
Bounds:
Xmin,Xmax: (1, -1)
Ymin,Ymax: (1, -1)
Zmin,Zmax: (1, -1)
Compute Time: 0
Number Of Points: 0
Point Coordinates: 0
Locator: 0
Number Of Pieces: 1
Piece: -1
Ghost Level: 0
任何进一步的探索似乎总是使我回到FieldDataInformation或PointDataInformation对象-而不是实际数据!
用于提取点XYZ位置的先前方法是:
data = servermanager.Fetch(clip1)
d2 = data.GetPoints()
xyz = zeros((d2.GetNumberOfPoints(), 3))
for i in range(d2.GetNumberOfPoints()):
xyz[i,:] = data.GetPoint(i)
编辑-此输出为:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
in ()
1 data = servermanager.Fetch(clip1)
2 d2 = data.GetPoints()
----> 3 xyz = zeros((d2.GetNumberOfPoints(), 3))
4 for i in range(d2.GetNumberOfPoints()):
5 xyz[i,:] = data.GetPoint(i)
AttributeError: 'NoneType' object has no attribute 'GetNumberOfPoints'
但是,是的,它似乎不再起作用了,我认为通过所有这些Numpy集成,它会变得有些整洁。
EDIT2:Utkarsh问题的输出:
>> clip1.UpdatePipeline()
>> rawData = servermanager.Fetch(clip1)
>> import vtk.numpy_interface.dataset_adapter as dsa
>> # Wrap the raw data object to access NumPy friendly API
>> data = dsa.WrapDataObject(rawData) # Note I changed this from Utkarsh's "data" to "rawData"
>> print data.Points
>> print data.PointData["VelocityField"]
得到:
None