# error reading pvti in paraview

**URL:** https://discourse.paraview.org/t/error-reading-pvti-in-paraview/16229
**Category:** ParaView Support
**Tags:** vtk, python
**Created:** [February 24, 2025, 9:26am UTC](https://discourse.paraview.org/t/error-reading-pvti-in-paraview/16229 "2025-02-24T09:26:20Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![aliz2](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aliz2](https://discourse.paraview.org/u/aliz2)
#### Post date: [February 24, 2025, 9:26am UTC](https://discourse.paraview.org/t/error-reading-pvti-in-paraview/16229/1 "2025-02-24T09:26:20Z")

</div>

Hi there,  
I’m trying to generate vtk image data in parallel (pvti) to read from series of vti files written by `vtk.vtkXMLImageDataWriter()` from 2d numpy arrays but getting below error related to extent:

```auto
ERROR: In vtkXMLPStructuredDataReader.cxx, line 429
vtkXMLPImageDataReader (0x9b7b0e0): No available piece provides data for the following extents:
    0 511 0 511 0 10710
The UpdateExtent cannot be filled.

```

Tried the code with random generated numpy array to simplify but still giving same error:

```auto
ERROR: In vtkXMLPStructuredDataReader.cxx, line 429
vtkXMLPImageDataReader (0x13ba61e0): No available piece provides data for the following extents:
    0 99 0 99 0 49
The UpdateExtent cannot be filled.

```

Not sure where I’m missing anything!  
The code:

```auto
import vtk
import numpy as np

def numpy_to_vtk_image_data(numpy_array):
    # Create a vtkImageData object
    image_data = vtk.vtkImageData()
    
    # Set the dimensions of the image data
    height, width = numpy_array.shape
    image_data.SetDimensions(width, height, 1)
    
    # Allocate scalars for the image data
    image_data.AllocateScalars(vtk.VTK_FLOAT, 1)
    
    # Get a pointer to the image data's scalar values
    scalars = image_data.GetPointData().GetScalars()
    
    # Flatten the numpy array and set the scalar values
    flat_numpy_array = numpy_array.flatten()
    for i in range(len(flat_numpy_array)):
        scalars.SetTuple1(i, flat_numpy_array[i])
    
    return image_data

def save_vtk_image_data(image_data, filename):
    # Create a vtkXMLImageDataWriter object
    writer = vtk.vtkXMLImageDataWriter()
    
    # Set the input data for the writer
    writer.SetInputData(image_data)
    
    # Set the filename for the output file
    writer.SetFileName(filename)
    
    # Write the data to the file
    writer.Write()

def create_pvti_file(vti_filenames, pvti_filename, width, height):
    with open(pvti_filename, 'w') as f:
        f.write('<?xml version="1.0"?>\n')
        f.write('<VTKFile type="PImageData" version="0.1" byte_order="LittleEndian">\n')
        f.write(' <PImageData WholeExtent="0 {} 0 {} 0 {}" GhostLevel="0" Origin="0 0 0" Spacing="1 1 1">\n'.format(
            width-1, height-1, len(vti_filenames)-1))
        f.write(' <PPointData Scalars="scalars">\n')
        f.write(' <PDataArray type="Float32" Name="scalars" format="appended" />\n')
        f.write(' </PPointData>\n')
        f.write(' <PCellData>\n')
        f.write(' </PCellData>\n')
        for i, vti_filename in enumerate(vti_filenames):
            f.write(' <Piece Extent="0 {} 0 {} {} {}" Source="{}"/>\n'.format(
                width-1, height-1, i, i, vti_filename))
        f.write(' </PImageData>\n')
        f.write('</VTKFile>\n')

# Example usage
if __name__ == " __main__":
    # Create a series of 2D numpy arrays
    series_of_2d_arrays = [np.random.rand(100, 100) for _ in range(50)]
    
    # Save each 2D numpy array to a VTI file
    vti_filenames = []
    for i, array in enumerate(series_of_2d_arrays):
        vtk_image_data = numpy_to_vtk_image_data(array)
        vti_filename = f"slice_{i}.vti"
        save_vtk_image_data(vtk_image_data, vti_filename)
        vti_filenames.append(vti_filename)
    
    # Create a PVTi file that references all the VTI files
    create_pvti_file(vti_filenames, "output.pvti", series_of_2d_arrays[0].shape[1], series_of_2d_arrays[0].shape[0])

```

sample generated `vti`:

```auto
<?xml version="1.0"?>
<VTKFile type="ImageData" version="0.1" byte_order="LittleEndian" header_type="UInt32" compressor="vtkZLibDataCompressor">
  <ImageData WholeExtent="0 99 0 99 0 0" Origin="0 0 0" Spacing="1 1 1" Direction="1 0 0 0 1 0 0 0 1">
    <Piece Extent="0 99 0 99 0 0" >
      <PointData Scalars="ImageScalars">
        <DataArray type="Float32" Name="ImageScalars" format="appended" RangeMin="8.6207102868e-05" RangeMax="0.99993038177" offset="0" />
      </PointData>
      <CellData>
      </CellData>
    </Piece>
  </ImageData>
  <AppendedData encoding="base64">
   _AgAAAACAAABAHAAA *****
  </AppendedData>
</VTKFile>

```

and the `pvti`:

```auto
<?xml version="1.0"?>
<VTKFile type="PImageData" version="0.1" byte_order="LittleEndian">
  <PImageData WholeExtent="0 99 0 99 0 49" GhostLevel="0" Origin="0 0 0" Spacing="1 1 1">
    <PPointData Scalars="scalars">
      <PDataArray type="Float32" Name="scalars" format="appended" />
    </PPointData>
    <PCellData>
    </PCellData>
    <Piece Extent="0 99 0 99 0 0" Source="slice_0.vti"/>
    <Piece Extent="0 99 0 99 1 1" Source="slice_1.vti"/>
    <Piece Extent="0 99 0 99 2 2" Source="slice_2.vti"/>
    <Piece Extent="0 99 0 99 3 3" Source="slice_3.vti"/>
    <Piece Extent="0 99 0 99 4 4" Source="slice_4.vti"/>
    <Piece Extent="0 99 0 99 5 5" Source="slice_5.vti"/>
    <Piece Extent="0 99 0 99 6 6" Source="slice_6.vti"/>
    <Piece Extent="0 99 0 99 7 7" Source="slice_7.vti"/>
    <Piece Extent="0 99 0 99 8 8" Source="slice_8.vti"/>
    <Piece Extent="0 99 0 99 9 9" Source="slice_9.vti"/>
    <Piece Extent="0 99 0 99 10 10" Source="slice_10.vti"/>
    <Piece Extent="0 99 0 99 11 11" Source="slice_11.vti"/>
    <Piece Extent="0 99 0 99 12 12" Source="slice_12.vti"/>
    <Piece Extent="0 99 0 99 13 13" Source="slice_13.vti"/>
    <Piece Extent="0 99 0 99 14 14" Source="slice_14.vti"/>
    <Piece Extent="0 99 0 99 15 15" Source="slice_15.vti"/>
    <Piece Extent="0 99 0 99 16 16" Source="slice_16.vti"/>
    <Piece Extent="0 99 0 99 17 17" Source="slice_17.vti"/>
    <Piece Extent="0 99 0 99 18 18" Source="slice_18.vti"/>
    <Piece Extent="0 99 0 99 19 19" Source="slice_19.vti"/>
    <Piece Extent="0 99 0 99 20 20" Source="slice_20.vti"/>
    <Piece Extent="0 99 0 99 21 21" Source="slice_21.vti"/>
    <Piece Extent="0 99 0 99 22 22" Source="slice_22.vti"/>
    <Piece Extent="0 99 0 99 23 23" Source="slice_23.vti"/>
    <Piece Extent="0 99 0 99 24 24" Source="slice_24.vti"/>
    <Piece Extent="0 99 0 99 25 25" Source="slice_25.vti"/>
    <Piece Extent="0 99 0 99 26 26" Source="slice_26.vti"/>
    <Piece Extent="0 99 0 99 27 27" Source="slice_27.vti"/>
    <Piece Extent="0 99 0 99 28 28" Source="slice_28.vti"/>
    <Piece Extent="0 99 0 99 29 29" Source="slice_29.vti"/>
    <Piece Extent="0 99 0 99 30 30" Source="slice_30.vti"/>
    <Piece Extent="0 99 0 99 31 31" Source="slice_31.vti"/>
    <Piece Extent="0 99 0 99 32 32" Source="slice_32.vti"/>
    <Piece Extent="0 99 0 99 33 33" Source="slice_33.vti"/>
    <Piece Extent="0 99 0 99 34 34" Source="slice_34.vti"/>
    <Piece Extent="0 99 0 99 35 35" Source="slice_35.vti"/>
    <Piece Extent="0 99 0 99 36 36" Source="slice_36.vti"/>
    <Piece Extent="0 99 0 99 37 37" Source="slice_37.vti"/>
    <Piece Extent="0 99 0 99 38 38" Source="slice_38.vti"/>
    <Piece Extent="0 99 0 99 39 39" Source="slice_39.vti"/>
    <Piece Extent="0 99 0 99 40 40" Source="slice_40.vti"/>
    <Piece Extent="0 99 0 99 41 41" Source="slice_41.vti"/>
    <Piece Extent="0 99 0 99 42 42" Source="slice_42.vti"/>
    <Piece Extent="0 99 0 99 43 43" Source="slice_43.vti"/>
    <Piece Extent="0 99 0 99 44 44" Source="slice_44.vti"/>
    <Piece Extent="0 99 0 99 45 45" Source="slice_45.vti"/>
    <Piece Extent="0 99 0 99 46 46" Source="slice_46.vti"/>
    <Piece Extent="0 99 0 99 47 47" Source="slice_47.vti"/>
    <Piece Extent="0 99 0 99 48 48" Source="slice_48.vti"/>
    <Piece Extent="0 99 0 99 49 49" Source="slice_49.vti"/>
  </PImageData>
</VTKFile>

```

Any clue what’s wrong?
