# Unable to render a StructuredGrid source using ProgrammableSource filter

**URL:** https://discourse.paraview.org/t/unable-to-render-a-structuredgrid-source-using-programmablesource-filter/15659
**Category:** ParaView Support
**Created:** [October 29, 2024, 8:27pm UTC](https://discourse.paraview.org/t/unable-to-render-a-structuredgrid-source-using-programmablesource-filter/15659 "2024-10-29T20:27:07Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jmb64](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@jmb64](https://discourse.paraview.org/u/jmb64)
#### Post date: [October 29, 2024, 8:27pm UTC](https://discourse.paraview.org/t/unable-to-render-a-structuredgrid-source-using-programmablesource-filter/15659/1 "2024-10-29T20:27:07Z")

</div>

As an exercise (being new to Paraview-VTK) I tried to use this piece of python code  
as a ProgrammableSource (Output Type set to StructuredGrid) in PARAVIEW 5.13.  
I am trying to model two concentric spherical surface (radius values of 1 and 2).  
I don’t know how to make those points (scalar “Radius”) magically appear in the RenderView !  
A similar exercise but setting the Output Type to PolyData works fine (Glyph filter following the  
ProgrammableSource is needed though).

import numpy as np  
from vtkmodules.vtkCommonCore import vtkPoints, vtkDoubleArray  
from vtkmodules.vtkCommonDataModel import vtkStructuredGrid

# Define grid dimensions

n\_theta = 18 # Number of points along theta  
n\_phi = 36 # Number of points along phi  
radii = [1.0, 2.0] # Two radial layers

# Initialize points and scalars

points = vtkPoints()  
scalars = vtkDoubleArray()  
scalars.SetName(“Radius”) # Scalar for radius-based coloring

# Fill points in spherical coordinates and convert to Cartesian

for r in radii:  
for theta\_idx in range(n\_theta):  
theta = theta\_idx \* np.pi / (n\_theta - 1)  
for phi\_idx in range(n\_phi):  
phi = phi\_idx \* 2 \* np.pi / (n\_phi - 1)

```
        # Spherical to Cartesian conversion
        x = r * np.sin(theta) * np.cos(phi)
        y = r * np.sin(theta) * np.sin(phi)
        z = r * np.cos(theta)
        
        points.InsertNextPoint(x, y, z)
        scalars.InsertNextValue(r) # Radius as a scalar value

```

# Create the structured grid and assign points and scalars

output.SetDimensions(n\_theta, n\_phi, len(radii))  
output.SetPoints(points)  
output.GetPointData().SetScalars(scalars

 ![image](https://discourse.paraview.org/uploads/default/original/2X/5/545f4c4af190456684c537a7ce677f36ce3dec06.png)

Rendering for the Output Type PolyData gives this :

 ![image](https://discourse.paraview.org/uploads/default/original/2X/7/76ae1247121530bbfb6c7d658da76cd8a68efb44.png)

UPDATE: Thanks to Jean M. Favre suggestion in this 2019 post …

> [@Problem displaying Structured Grid when loading from Programmable Source](https://discourse.paraview.org/t/problem-displaying-structured-grid-when-loading-from-programmable-source/3051):
>
> Hi, I am trying to make a file reader for a structured grid file that is not currently supported, but I can read it into a numpy array. To start simple I tried to make a programmable source which just creates a cube (Output Data Set Type: vtkStructuredGrid) import numpy as np # Cube xs = np.linspace(0,1,10) ys = np.linspace(0,1,10) zs = np.linspace(0,1,10) dims = [len(xs),len(ys),len(zs)] # Setting S-Grid extent output.SetExtent([0,len(xs)-1,0,len(ys)-1,0,len(zs)-1]) # VTK points points =…

ProgrammableSource using StructuredGrid Output Type is working but …

 ![image](https://discourse.paraview.org/uploads/default/original/2X/b/b7b115964863a9713a49b7a571fe733e501ade1d.png)

I guess, the question that comes to my mind now is

1. Why in the PolyData Output type case,references to the vtk pipeline mechanics are not necessary ( i.e. commands like executive.GetOutputInformation(0), …,) ?

2. Also, there seems to have synchronization or communication issue (client-server). The default Outline rendering does show only after pushing the Apply button a second time … Some some of update mechanism seems to be triggered then and the Outline appears.

But I’m way over my head here … speculating on something I barely know 🙂  
Lots of fun ahead !
