# Accessing coordinates in python calculator

**URL:** https://discourse.paraview.org/t/accessing-coordinates-in-python-calculator/8736
**Category:** ParaView Support
**Tags:** python
**Created:** [January 6, 2022, 6:36am UTC](https://discourse.paraview.org/t/accessing-coordinates-in-python-calculator/8736 "2022-01-06T06:36:04Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![psakievich](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/p/48db29/32.png) [@psakievich](https://discourse.paraview.org/u/psakievich)
#### Post date: [January 6, 2022, 6:36am UTC](https://discourse.paraview.org/t/accessing-coordinates-in-python-calculator/8736/1 "2022-01-06T06:36:04Z")

</div>

I’m trying to access the coordinates from a hierarchical box data set (AMReX) to do a computation.

What I really want to do is manipulate the coordinates since we are playing around with adding mesh stretching into our CFD code, but the underlying vtkDataType only uses `vtkUniformGrids`. Or at least that is what it seems to me. After a bunch of trial and error with Programmable filters, I decided to just compute the stretched coordinates and use the `Warp By Vector` filter.

With the regular calculator I can access them just fine with the `coordsX,Y,Z` variables, but when I try to use the python calculator I can’t figure out how to access them at all. There is no `inputs[0].Points` member, or at least calling it doesn’t do anything, and the fields don’t exist in the `PointData`. Any advice here? Is this just not exposed via the python interface?

Phil

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [January 6, 2022, 9:31am UTC](https://discourse.paraview.org/t/accessing-coordinates-in-python-calculator/8736/2 "2022-01-06T09:31:31Z")

</div>

`vtkUniformGrids` have implicit points. You can either convert to a explicit datatype (using AppendDataset) or expose the points (using Calculator)

---

<div class="post-metadata">

### Author: ![psakievich](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/p/48db29/32.png) [@psakievich](https://discourse.paraview.org/u/psakievich)
#### Post date: [January 6, 2022, 3:02pm UTC](https://discourse.paraview.org/t/accessing-coordinates-in-python-calculator/8736/3 "2022-01-06T15:02:50Z")

</div>

Okay thanks. I will test out the first option today. Do you have an example of how I can do this? When I try to use the Append Dataset filter on the AMReX dataset it is grayed out. Also to my question about the `Python Calculator` I take it there is no way for me to access the points then? Calculator will work okay, but I would prefer the python version of the filter if I can use it.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [January 6, 2022, 3:05pm UTC](https://discourse.paraview.org/t/accessing-coordinates-in-python-calculator/8736/4 "2022-01-06T15:05:35Z")

</div>

The data is just not there, so you can’t access it. You could access it with a ProgrammableFilter though.

In the context AMR, converting to UG does not seem to be the right solution though.

---

<div class="post-metadata">

### Author: ![psakievich](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/p/48db29/32.png) [@psakievich](https://discourse.paraview.org/u/psakievich)
#### Post date: [January 6, 2022, 3:19pm UTC](https://discourse.paraview.org/t/accessing-coordinates-in-python-calculator/8736/5 "2022-01-06T15:19:02Z")

</div>

I see. So what is `Calculator` doing? Does it just convert the dataset to `vtkPolyData` or something and add the fields that way? Yes I tried with a programmable filter first. I have a csv file with all the new coordinate locations so I was trying to read them into the dataset with something like

```auto
amr = inputs[0]
outputs = amr
# read csv and name variable table, headers are x, y and z
id = ['x', 'y', 'z']
for i in range(3):
   array = table[id[i]]
   outputs.PointData.append(array, id[i])

```

But this caused my computer to run out of memory doing the computation. It’s a pretty small dataset and I’ve got 32gb of ram on my laptop so that’s not a good sign.

---

<div class="post-metadata">

### Author: ![psakievich](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/p/48db29/32.png) [@psakievich](https://discourse.paraview.org/u/psakievich)
#### Post date: [January 6, 2022, 3:28pm UTC](https://discourse.paraview.org/t/accessing-coordinates-in-python-calculator/8736/6 "2022-01-06T15:28:49Z")

</div>

My original thought was if I can just add the fields for the coordinates to the PointData then I can just use Warp by Vector. I guess that will also convert the data type though. Not really sure of how to get around that.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [January 6, 2022, 3:30pm UTC](https://discourse.paraview.org/t/accessing-coordinates-in-python-calculator/8736/7 "2022-01-06T15:30:25Z")

</div>

> [@psakievich](#):
>
> So what is `Calculator` doing?

It is using GetPoint(), which is defined for all types of dataset.

> But this caused my computer to run out of memory doing the computation. It’s a pretty small dataset and I’ve got 32gb of ram on my laptop so that’s not a good sign.

Thats definitely unexpected.

---

<div class="post-metadata">

### Author: ![psakievich](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/p/48db29/32.png) [@psakievich](https://discourse.paraview.org/u/psakievich)
#### Post date: [January 6, 2022, 4:06pm UTC](https://discourse.paraview.org/t/accessing-coordinates-in-python-calculator/8736/8 "2022-01-06T16:06:10Z")

</div>

I will try a few more things today and post a reproducer script for the memory issue if I can’t figure it out.

---

<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: [January 6, 2022, 5:37pm UTC](https://discourse.paraview.org/t/accessing-coordinates-in-python-calculator/8736/9 "2022-01-06T17:37:32Z")

</div>

If it’s a uniform stretching you could just modify the spacing of each of the underlying vtkImageDatas in the programmable filter.

---

<div class="post-metadata">

### Author: ![psakievich](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/p/48db29/32.png) [@psakievich](https://discourse.paraview.org/u/psakievich)
#### Post date: [January 6, 2022, 7:49pm UTC](https://discourse.paraview.org/t/accessing-coordinates-in-python-calculator/8736/10 "2022-01-06T19:49:10Z")

</div>

Andy, I will have to take a closer look at this. I’m new to this Hierarchical block data structure. The stretching is done with a hyperbolic tangent (channel flow in this case). I’m not opposed to just reimplementing the stretching function we used in the code in a paraview filter if that works.
