Python 3.x 从原始VTK(.vtu)文件读取数据

Python 3.x 从原始VTK(.vtu)文件读取数据,python-3.x,numpy,vtk,Python 3.x,Numpy,Vtk,我想使用Python VTK模块从.vtu文件中提取数据数组。文件如下所示:文件末尾的原始数据被写入: <?xml version="1.0"?> <VTKFile type="UnstructuredGrid" version="0.1" byte_order="LittleEndian"> <UnstructuredGrid> <Piece NumberOfPoints="10471" NumberOfCells="64892">

我想使用Python VTK模块从.vtu文件中提取数据数组。文件如下所示:文件末尾的原始数据被写入:

<?xml version="1.0"?>
<VTKFile type="UnstructuredGrid" version="0.1" byte_order="LittleEndian">
  <UnstructuredGrid>
    <Piece NumberOfPoints="10471" NumberOfCells="64892">
      <PointData>
        <DataArray type="Float64" Name="potential" NumberOfComponents="1" format="appended" offset="0"/>
        <DataArray type="Float64" Name="electric field" NumberOfComponents="3" format="appended" offset="83772"/>
      </PointData>
      <CellData>
        <DataArray type="Int32" Name="GeometryIds" format="appended" offset="335080"/>
      </CellData>
      <Points>
        <DataArray type="Float64" NumberOfComponents="3" format="appended" offset="594652"/>
      </Points>
      <Cells>
        <DataArray type="Int32" Name="connectivity" format="appended" offset="845960"/>
        <DataArray type="Int32" Name="offsets" format="appended" offset="1865068"/>
        <DataArray type="Int32" Name="types" format="appended" offset="2124640"/>
      </Cells>
    </Piece>
  </UnstructuredGrid>
<AppendedData encoding="raw">

不幸的是,此程序将NoneType打印为输出,我不确定需要更改什么才能提取潜在阵列中的数据存储?

您没有使用正确的读取器,这是一个.vtu文件,您必须使用vtkXMLUnstructuredGridReader


您没有使用正确的读取器,这是一个.vtu文件,您必须使用vtkXMLUnstructuredGridReader


一个更轻量级的解决方案是使用我编写的。除了numpy之外,它没有必需的依赖项。安装

pip install meshio
并用

进口网西奥 mesh=meshio.readfoo.vtu mesh.points、mesh.cells、mesh.point_数据。。。
一个更轻量级的解决方案是使用我编写的。除了numpy之外,它没有必需的依赖项。安装

pip install meshio
并用

进口网西奥 mesh=meshio.readfoo.vtu mesh.points、mesh.cells、mesh.point_数据。。。
pip install meshio