# Adding new field to mergeblock data

**URL:** https://discourse.paraview.org/t/adding-new-field-to-mergeblock-data/4253
**Category:** ParaView Support
**Created:** [May 5, 2020, 3:20am UTC](https://discourse.paraview.org/t/adding-new-field-to-mergeblock-data/4253 "2020-05-05T03:20:22Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Mahdi\_Kooshkbaghi](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mahdi_kooshkbaghi/32/3669_2.png) [@Mahdi\_Kooshkbaghi](https://discourse.paraview.org/u/Mahdi_Kooshkbaghi)
#### Post date: [May 5, 2020, 3:20am UTC](https://discourse.paraview.org/t/adding-new-field-to-mergeblock-data/4253/1 "2020-05-05T03:20:22Z")

</div>

I have an issue adding new scalar field to the existing dataset.

- The simulation output is from NEK5000 code.
- First, I read the file, get the `u` and `v` field data.
- Then, Merge the blocks.
- Applied the `servermanager.Fetch`.
- Now the `merge_data` is ready to be converted to `numpy` arrays.
- Get the values of `u` and `v` for _all the points_ and store them in `data_numpy` with the shape `(number of points, 2)`.
- Calculate my desire field. Please note the real `fc` function is more complicated that the toy example below, requiring other python packages, so I can not use the `Calculator`.
- Up to this point everything looks great.
- But when I have tried to add this new field to the `merge_data`,
  - There is no error.
  - I still can use GetRange() function.
  - **But I can not see the filed in the GUI or I can not color my grid with new filed `fc`**

Thanks for help

```python
from paraview.simple import *
nek3d = VisItNek5000Reader(FileName='a.nek3d')
nek3d.PointArrays=['u','v']
merge_data = MergeBlocks(nek3d)
merge_data = servermanager.Fetch(merge_data)

# Get all values of u and v for all the points 
from paraview import numpy_support as ns
import numpy as np
data_numpy = []
for name in ['u', 'v']:
    data_numpy.append(ns.vtk_to_numpy(merge_data.GetPointData().GetArray(name))[:])

data_numpy = np.array(data_numpy).T
# data_numpy has the shape (number of points, 2)
# Calculate some function
fc = data_numpy[:,0]+data_numpy[:,1]

fc = ns.numpy_to_vtk(fc.ravel())
fc.SetName('hrr')
merge_data.GetPointData().AddArray(fc)

```

---

<div class="post-metadata">

### Author: ![Andy\_Bauer](https://discourse.paraview.org/user_avatar/discourse.paraview.org/andy_bauer/32/5442_2.png) [@Andy\_Bauer](https://discourse.paraview.org/u/Andy_Bauer)
#### Post date: [May 5, 2020, 12:27pm UTC](https://discourse.paraview.org/t/adding-new-field-to-mergeblock-data/4253/2 "2020-05-05T12:27:17Z")

</div>

I don’t think `servermanager.Fetch()` is what you want here. That just brings the data to the client. You should use either the `Calculator` filter, or even more efficiently, the `Python Calculator` filter to combine your two separate scalar fields into a single new field.

As a side note, you will also want to add a z-component to the new field in order to have ParaView register this field as a vector field since ParaView really only works in 3D space. Maybe you’re already doing this and I’m just going through your code snippet too fast though.

---

<div class="post-metadata">

### Author: ![Mahdi\_Kooshkbaghi](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mahdi_kooshkbaghi/32/3669_2.png) [@Mahdi\_Kooshkbaghi](https://discourse.paraview.org/u/Mahdi_Kooshkbaghi)
#### Post date: [May 5, 2020, 10:35pm UTC](https://discourse.paraview.org/t/adding-new-field-to-mergeblock-data/4253/3 "2020-05-05T22:35:25Z")

</div>

I am not sure why I don’t need to use `Fetch()`.

- Let assume I have just read the data set with

```python
nek3d = VisItNek5000Reader(FileName='a.nek3d')

```

Here is the `nek3d` object. I can not get the data following the manual chapter 13. It just print the data name.

```python
>>> print(type(nek3d))
<class 'paraview.servermanager.VisItNek5000Reader'>

>>> nek3d.PointData
<paraview.servermanager.FieldDataInformation object at 0x7fef17407050>

>>> print(nek3d.PointData['u'])
Array: u

```

- Now assume I have used the `MergeBlocks`, still the same issue.

```python
>>> merge_data = MergeBlocks(nek3d)
>>> print(type(merge_data))
<class 'paraview.servermanager.MergeBlocks'>
>>> print(merge_data.PointData['u'])
Array: u

```

- If I try to convert in this level without `Fetch()` I got the following error:

```auto
Traceback (most recent call last):
  File "<string>", line 28, in <module>
  File "/usr/local/lib/python3.7/site-packages/paraview/servermanager.py", line 497, in __getattr__
    return getattr(self.SMProxy, name)
AttributeError: 'vtkPVServerManagerCorePython.vtkSMSourceProxy' object has no attribute 'GetPointData'

```

- The only way I can get the point data and hence doing the pointwise calculation is to `Fetch` it.

```python
merge_data = MergeBlocks(nek3d)
merge_data = servermanager.Fetch(merge_data) 
from paraview import numpy_support as ns
import numpy as np
data_numpy = []
for name in ['u', 'v']:
     data_numpy.append(ns.vtk_to_numpy(merge_data.GetPointData().GetArra y(name))[:])
data_numpy = np.array(data_numpy).T

```

Which correctly gave me the `(100000, 2)` dimensional array.

- And now I don’t know how to add the new field to my dataset, as I explained in the first thread.
