# Programmable Filter - Multi-Block - Selecting Block Data

**URL:** https://discourse.paraview.org/t/programmable-filter-multi-block-selecting-block-data/4469
**Category:** ParaView Support
**Tags:** python
**Created:** [June 2, 2020, 3:59am UTC](https://discourse.paraview.org/t/programmable-filter-multi-block-selecting-block-data/4469 "2020-06-02T03:59:39Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![carl](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/c/ee7513/32.png) [@carl](https://discourse.paraview.org/u/carl)
#### Post date: [June 2, 2020, 3:59am UTC](https://discourse.paraview.org/t/programmable-filter-multi-block-selecting-block-data/4469/1 "2020-06-02T03:59:39Z")

</div>

I have a multi-block data set which I want to feed all the data through a python function to calculate a new variable within a Programmable Filter.

My function requires a single float value. However, I can only get a tuple, and not a float (see below). Is there a way to getting the individual values? For example can first extract and loop the block 1 data, followed by the block 2 data within a single Programmable Filter?

Or do I have to filter the data to individual blocks before the Programmable Filter, then reassemble the data again? I don’t really want to merge blocks.

```
data = inputs[0].CellData['T']

print('\n\ndata[0]: ' +str(data[0])) 
print('\ndata[0] Type: ' +str(type(data[0])))
print('\n\ndata: ' +str(data))

```

This code yields the below:

> data[0]: [540.45123, 541.2982]
> 
> data Type: \<class ‘paraview.vtk.numpy\_interface.dataset\_adapter.VTKCompositeDataArray’

```
data: [VTKArray([540.45123, 540.51917, 544.7528 , 546.45074, 545.62366,
          542.2705 , 544.5187 , 548.7523 , 550.4502 , 549.6231 ,
          546.26996, 546.5184 , 550.752 , 552.4499 , 551.6228 ,
          548.26965, 546.5184 , 550.752 , 552.4499 , 551.6228 ,
          548.26965, 544.5187 , 548.7523 , 550.4502 , 549.6231 ,
          546.26996, 540.51917, 544.7528 , 546.45074, 545.62366,
          542.2705 , 540.45123, 540.45123, 542.51935, 546.753 ,
          548.4509 , 547.62384, 544.2707 , 541.72797, 548.51886,
          552.7525 , 554.4504 , 553.62335, 550.2702 , 545.7275 ,
          552.5184 , 556.752 , 558.4499 , 557.6228 , 554.26965,
          547.72723, 554.51807, 558.7517 , 560.4496 , 559.6225 ,
          556.2693 , 547.72723, 554.51807, 558.7517 , 560.4496 ,
          559.6225 , 556.2693 , 545.7275 , 552.5184 , 556.752 ,
          558.4499 , 557.6228 , 554.26965, 541.72797, 548.51886,
          552.7525 , 554.4504 , 553.62335, 550.2702 , 542.51935,
          546.753 , 548.4509 , 547.62384, 544.2707 , 540.45123,
          540.51917, 544.7528 , 546.45074, 545.62366, 542.2705 ,
          541.72797, 548.51886, 552.7525 , 554.4504 , 553.62335,
          550.2702 , 547.7275 , 554.5184 , 558.752 , 560.4499 ,
          559.6228 , 556.26965, 542.34985, 551.727 , 558.5179 ,
          562.7515 , 564.4494 , 563.62225, 560.2691 , 544.3496 ,
          553.72675, 560.5176 , 564.7512 , 566.44904, 565.62195,
          562.26874, 544.3496 , 553.72675, 560.5176 , 564.7512 ,
          566.44904, 565.62195, 562.26874, 542.34985, 551.72705,
          558.5179 , 562.7515 , 564.4494 , 563.62225, 560.2691 ,
          547.7275 , 554.5184 , 558.752 , 560.4499 , 559.6228 ,
          556.26965, 541.72797, 548.51886, 552.7525 , 554.4504 ,
          553.62335, 550.2702 , 540.51917, 544.7528 , 546.45074,
          545.62366, 542.2705 , 544.5187 , 548.7523 , 550.4502 ,
          549.6231 , 546.26996, 545.7275 , 552.5184 , 556.752 ,
          558.4499 , 557.6228 , 554.26965, 542.34985, 551.727 ,
          558.5179 , 562.7515 , 564.4494 , 563.62225, 560.2691 ,
          546.3494 , 555.72656, 562.5174 , 566.75104, 568.44885,
          567.62177, 564.26855, 548.3491 , 557.72626, 564.5171 ,
          568.7507 , 570.44855, 569.6214 , 566.2682 , 548.3491 ,
          557.72626, 564.5171 , 568.7507 , 570.44855, 569.6214 ,
          566.2682 , 546.3494 , 555.72656, 562.5174 , 566.751 ,
          568.44885, 567.62177, 564.26855, 542.3499 , 551.72705,
          558.5179 , 562.7515 , 564.4494 , 563.62225, 560.2691 ,
          545.7275 , 552.5184 , 556.752 , 558.4499 , 557.6228 ,
          554.26965, 544.5187 , 548.7523 , 550.4502 , 549.6231 ,
          546.26996, 546.5184 , 550.752 , 552.4499 , 551.6228 ,
          548.26965, 547.72723, 554.51807, 558.7517 , 560.4496 ,
          559.6225 , 556.2693 , 544.3496 , 553.72675, 560.5176 ,
          564.7512 , 566.44904, 565.62195, 562.26874, 548.3491 ,
          557.72626, 564.5171 , 568.7507 , 570.44855, 569.6214 ,
          566.2682 , 550.3488 , 559.72595, 566.5168 , 570.75037,
          572.44824, 571.6211 , 568.2679 , 550.3488 , 559.72595,
          566.5168 , 570.75037, 572.44824, 571.6211 , 568.2679 ,
          548.3491 , 557.72626, 564.5171 , 568.7507 , 570.44855,
          569.6214 , 566.2682 , 544.3496 , 553.72675, 560.5176 ,
          564.7512 , 566.44904, 565.62195, 562.26874, 547.72723,
          554.51807, 558.7517 , 560.4496 , 559.6225 , 556.2693 ,
          546.5184 , 550.752 , 552.4499 , 551.6228 , 548.26965,
          546.5184 , 550.752 , 552.4499 , 551.6228 , 548.26965,
          547.72723, 554.51807, 558.7517 , 560.4496 , 559.6225 ,
          556.2693 , 544.3496 , 553.72675, 560.5176 , 564.7512 ,
          566.44904, 565.62195, 562.26874, 548.3491 , 557.72626,
          564.5171 , 568.7507 , 570.44855, 569.6214 , 566.2682 ,
          550.3488 , 559.72595, 566.5168 , 570.75037, 572.44824,
          571.6211 , 568.2679 , 550.3488 , 559.72595, 566.5168 ,
          570.75037, 572.44824, 571.6211 , 568.2679 , 548.3491 ,
          557.72626, 564.5171 , 568.7507 , 570.44855, 569.6214 ,
          566.2682 , 544.3496 , 553.72675, 560.5176 , 564.7512 ,
          566.44904, 565.62195, 562.26874, 547.72723, 554.51807,
          558.7517 , 560.4496 , 559.6225 , 556.2693 , 546.5184 ,
          550.752 , 552.4499 , 551.6228 , 548.26965, 544.5187 ,
          548.7523 , 550.4502 , 549.6231 , 546.26996, 545.7275 ,
          552.5184 , 556.752 , 558.4499 , 557.6228 , 554.26965,
          542.34985, 551.72705, 558.5179 , 562.7515 , 564.4494 ,
          563.62225, 560.2691 , 546.3494 , 555.72656, 562.5174 ,
          566.751 , 568.44885, 567.62177, 564.26855, 548.3491 ,
          557.72626, 564.5171 , 568.7507 , 570.44855, 569.6214 ,
          566.2682 , 548.3491 , 557.72626, 564.5171 , 568.7507 ,
          570.44855, 569.6214 , 566.2682 , 546.3494 , 555.72656,
          562.5174 , 566.751 , 568.44885, 567.62177, 564.26855,
          542.34985, 551.727 , 558.5179 , 562.7515 , 564.44934,
          563.62225, 560.2691 , 545.7275 , 552.5184 , 556.752 ,
          558.4499 , 557.6228 , 554.26965, 544.5187 , 548.7523 ,
          550.4502 , 549.6231 , 546.26996, 540.51917, 544.7528 ,
          546.45074, 545.62366, 542.2705 , 541.72797, 548.51886,
          552.7525 , 554.4504 , 553.62335, 550.2702 , 547.7275 ,
          554.5184 , 558.752 , 560.4499 , 559.6228 , 556.26965,
          542.3499 , 551.72705, 558.5179 , 562.7515 , 564.4494 ,
          563.62225, 560.2691 , 544.3496 , 553.72675, 560.5176 ,
          564.7512 , 566.44904, 565.62195, 562.26874, 544.3496 ,
          553.72675, 560.5176 , 564.7512 , 566.44904, 565.62195,
          562.26874, 542.34985, 551.727 , 558.5179 , 562.7515 ,
          564.44934, 563.62225, 560.2691 , 547.7275 , 554.5184 ,
          558.752 , 560.4499 , 559.6228 , 556.26965, 541.72797,
          548.51886, 552.7525 , 554.4504 , 553.62335, 550.27014,
          540.51917, 544.7528 , 546.45074, 545.62366, 542.2705 ,
          540.45123, 542.51935, 546.753 , 548.4509 , 547.62384,
          544.2707 , 541.72797, 548.51886, 552.7525 , 554.4504 ,
          553.62335, 550.2702 , 545.7275 , 552.5184 , 556.752 ,
          558.4499 , 557.6228 , 554.26965, 547.72723, 554.51807,
          558.7517 , 560.4496 , 559.6225 , 556.2693 , 547.72723,
          554.51807, 558.7517 , 560.4496 , 559.6225 , 556.2693 ,
          545.7275 , 552.5184 , 556.752 , 558.4499 , 557.6228 ,
          554.26965, 541.72797, 548.51886, 552.7525 , 554.4504 ,
          553.62335, 550.27014, 542.51935, 546.753 , 548.4509 ,
          547.62384, 544.2707 , 540.45123, 540.45123, 540.51917,
          544.7528 , 546.45074, 545.62366, 542.2705 , 544.5187 ,
          548.7523 , 550.4502 , 549.6231 , 546.26996, 546.5184 ,
          550.752 , 552.4499 , 551.6228 , 548.26965, 546.5184 ,
          550.752 , 552.4499 , 551.6228 , 548.26965, 544.5187 ,
          548.7523 , 550.4502 , 549.6231 , 546.26996, 540.51917,
          544.7528 , 546.45074, 545.62366, 542.2705 , 540.45123],
         dtype=float32), VTKArray([541.2982 , 541.2982 , 543.29877, 547.2982 , 549.2979 ,
          549.2979 , 547.2982 , 543.29877, 543.29877, 549.2982 ,
          553.29767, 543.7664 , 555.29736, 545.7661 , 555.29736,
          545.7661 , 553.29767, 543.7664 , 549.2982 , 543.29877,
          547.2982 , 553.29767, 543.7664 , 557.2972 , 547.76587,
          559.2968 , 549.76556, 559.2968 , 549.76556, 557.2972 ,
          547.76587, 553.29767, 543.7664 , 547.2982 , 541.2982 ,
          549.2979 , 555.29736, 545.7661 , 559.2968 , 549.76556,
          561.2965 , 551.76526, 561.2965 , 551.76526, 559.2968 ,
          549.76556, 555.29736, 545.7661 , 549.2979 , 541.2982 ,
          541.2982 , 549.2979 , 555.29736, 545.7661 , 559.2968 ,
          549.76556, 561.2965 , 551.76526, 561.2965 , 551.76526,
          559.2968 , 549.76556, 555.29736, 545.7661 , 549.2979 ,
          541.2982 , 547.2982 , 553.29767, 543.7664 , 557.2972 ,
          547.76587, 559.2968 , 549.76556, 559.2968 , 549.76556,
          557.2972 , 547.76587, 553.29767, 543.7664 , 547.2982 ,
          543.29877, 549.2982 , 553.29767, 543.7664 , 555.29736,
          545.7661 , 555.29736, 545.7661 , 553.29767, 543.7664 ,
          549.2982 , 543.29877, 543.29877, 547.2982 , 549.2979 ,
          549.2979 , 547.2982 , 543.29877, 541.2982 , 541.2982 ],
         dtype=float32)]

```

---

<div class="post-metadata">

### Author: ![carl](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/c/ee7513/32.png) [@carl](https://discourse.paraview.org/u/carl)
#### Post date: [June 2, 2020, 8:45pm UTC](https://discourse.paraview.org/t/programmable-filter-multi-block-selecting-block-data/4469/2 "2020-06-02T20:45:12Z")

</div>

I’ve been working on this but have got stuck again.

To simplify things I thought I’d MergeBlocks to make a single data set problem first (will move to multi block in the future)

I have a simple code to interpolate the Fraction Solid based on the cell Temperature.

My challenge is getting the np array back into vtk format. I’ve searched the forums and read the manual and [https://blog.kitware.com/improved-vtk-numpy-integration/](https://blog.kitware.com/improved-vtk-numpy-integration/) but am still stuck.

Any help would be appreciated.

```
import numpy as np
import vtk
import vtk.util.numpy_support as ns

# Define FS data
FSdata = [[550.0, 575.0, 600.0],[1.0, 0.8, 0.0]]

# Get data
numCells = inputs[0].GetNumberOfCells()
temp = inputs[0].CellData['T']

# Create empty np array
outData = np.empty(numCells, dtype = float)

# Loop all cells to calculate/interpolate value
for i in range(0,numCells):
    outData[i] = np.interp(temp[i], FSdata[0][:], FSdata[1][:])

print('outData: ' +str(outData))
print('outData Type: ' +str(type(outData)))

# Convert np array to vtk format
vtk_array = ns.numpy_to_vtk(outData,i,float)

print('vtk_array: ' +str(vtk_array))

output.CellData.append( vtk_array , 'FracLiquid')

```

Current error:

Traceback (most recent call last):  
File “”, line 22, in   
File “”, line 26, in RequestData  
File “C:\Program Files\ParaView 5.8.0-Windows-Python3.7-msvc2015-64bit\bin\Lib\site-packages\vtkmodules\util\numpy\_support.py”, line 148, in numpy\_to\_vtk  
result\_array = create\_vtk\_array(vtk\_typecode)  
File “C:\Program Files\ParaView 5.8.0-Windows-Python3.7-msvc2015-64bit\bin\Lib\site-packages\vtkmodules\util\numpy\_support.py”, line 102, in create\_vtk\_array  
return vtkDataArray.CreateDataArray(vtk\_arr\_type)  
TypeError: CreateDataArray argument %Id: %V

outData: [0.97226465 0.88038135 0.80968359 … 0.87161035 0.96482227 1.]  
outData Type: \<class ‘numpy.ndarray’\>

---

<div class="post-metadata">

### Author: ![Kenichiro-Yoshimi](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@Kenichiro-Yoshimi](https://discourse.paraview.org/u/Kenichiro-Yoshimi)
#### Post date: [June 3, 2020, 12:31am UTC](https://discourse.paraview.org/t/programmable-filter-multi-block-selecting-block-data/4469/3 "2020-06-03T00:31:51Z")

</div>

Hello,

You do not have to convert numpy arrary into vtk data array.

```python
import numpy as np

# Define FS data
FSdata = [[550.0, 575.0, 600.0], [1.0, 0.8, 0.0]]

# Get data
numCells = inputs[0].GetNumberOfCells()
temp = inputs[0].CellData['T']

# Create empty np array
outData = np.empty(numCells, dtype=float)

# calculate/interpolate value at each cell
outData = np.interp(temp, FSdata[0][:], FSdata[1][:])

# Add the numpy array as a cell data set
output.CellData.append(outData, 'FracLiquid')

```

You can see more detailed description:

> <https://stackoverflow.com/questions/59273490/python-read-vtk-file-add-data-set-then-write-vtk>
