从Paraview 4.2中提取Python脚本中的数据
我试图使用Paraview 4.2从Python脚本中的一个片段中提取数据。我有这样的想法:从Paraview 4.2中提取Python脚本中的数据,python,numpy,vtk,paraview,Python,Numpy,Vtk,Paraview,我试图使用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' xDMFte
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=['<pathtodata>/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
编辑-此操作的输出为:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-11-e34f36729df1> in <module>()
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'
给出:
None
<vtk.numpy_interface.dataset_adapter.VTKNoneArray object at 0x7f57c4a75390>
无
使用前面的方法会出现什么错误。它应该会起作用。更好的方法如下:
# ensure that the clip1 filter is updated.
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(data)
print data.Points
VTKArray([[ -5. , -5. , -9.15493107],
[ -3. , -5. , -9.75046444],
[ -2. , -5. , -9.50859547],
...,
[ 3.04815888, 3. , 10. ],
[ 4.24629259, 3. , 10. ],
[ 4. , 3.25505328, 10. ]], dtype=float32)
# To access the point data array named VelocityField
print data.PointData["VelocityField"]
这是正确的——我认为这是一种更好的访问数据的方法。我遇到了问题,因为我的初始代码不够明确。它是通过确保所有剪辑和切片都有足够的信息正确处理而修复的。仅供参考,VTKNoneArray返回时,数据集中不存在具有该名称的数组。
>> 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
<vtk.numpy_interface.dataset_adapter.VTKNoneArray object at 0x7f57c4a75390>
# ensure that the clip1 filter is updated.
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(data)
print data.Points
VTKArray([[ -5. , -5. , -9.15493107],
[ -3. , -5. , -9.75046444],
[ -2. , -5. , -9.50859547],
...,
[ 3.04815888, 3. , 10. ],
[ 4.24629259, 3. , 10. ],
[ 4. , 3.25505328, 10. ]], dtype=float32)
# To access the point data array named VelocityField
print data.PointData["VelocityField"]