# Querying attribute value within dataset

**URL:** https://discourse.paraview.org/t/querying-attribute-value-within-dataset/6119
**Category:** ParaView Support
**Tags:** python, vtk
**Created:** [December 23, 2020, 5:12pm UTC](https://discourse.paraview.org/t/querying-attribute-value-within-dataset/6119 "2020-12-23T17:12:54Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![nwood99](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/n/a88e57/32.png) [@nwood99](https://discourse.paraview.org/u/nwood99)
#### Post date: [December 23, 2020, 5:12pm UTC](https://discourse.paraview.org/t/querying-attribute-value-within-dataset/6119/1 "2020-12-23T17:12:54Z")

</div>

Hello,

I am trying to apply a moving slice filter to my dataset. I wish for the slice plane to move back and forth along the y-axis. This movement is somewhat complicated, so I included the desired origin y-coordinate as an attribute in the dataset. The attached image shows what the data looks like. I’m plotting Temperature, with TIME storing the time index. The attribute Yc, stored as a scalar field, stores the desired slice plane y-coordinate. I am attempting to move the slice origin with the python animation track shown in the image. However, when I reassign the slice origin, I am struggling with querying the value of Yc. I thought that since Yc is stored as a scalar field, it would be sufficient to query the field data of “data” with GetFieldData, and then query the scalar value of Yc with the command GetScalars(‘Yc’). However, with this implementation, the slice fails to move. Any clarification on what I am misunderstanding would be greatly appreciated!

Sincerely,  
Nathaniel Wood

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

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [December 23, 2020, 5:57pm UTC](https://discourse.paraview.org/t/querying-attribute-value-within-dataset/6119/2 "2020-12-23T17:57:09Z")

</div>

`FindSource` returns the proxy for the reader, and not the actual dataset. You can either use data-information obtained from the proxy or fetch the data locally and then use that. The former is preferred, if sufficient. For example if `Yc` is simply a single value, you can indeed just use data-information as follows:

```auto
reader = FindSource(...)
ycArrayInfo = reader.FieldData["Yc"]
component_range = ycArrayInfo.GetRange(0)
# component_range is a tuple `(min, max)`. if it's a single value,
# they'll be the same, so you can use that in your code subsequently.

```

---

<div class="post-metadata">

### Author: ![nwood99](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/n/a88e57/32.png) [@nwood99](https://discourse.paraview.org/u/nwood99)
#### Post date: [December 23, 2020, 6:30pm UTC](https://discourse.paraview.org/t/querying-attribute-value-within-dataset/6119/3 "2020-12-23T18:30:24Z")

</div>

Utkarsh,

Based on your suggestion, I have modified the macro so that it now reads:

```python
def start_cue(self): pass
def tick(self): 
reader=FindSource("X_FULL_*") #load in data
ycArrayInfo=reader.FieldData["Yc"] #get Yc field data
ycRange=ycArrayInfo.GetRange[0] #find range of Yc (repeats the same value twice)
yTemp=ycRange[0] #get value of Yc
tempOrigin=tempSlice.SliceType.Origin #query origin of slice
tempOrigin[1]=yTemp #reset y-coordinate of origin to the value Yc
tempSlice.SliceType.Origin=tempOrigin #reassign slice origin
def end_cue(self): pass

```

I believe this is now reading in the value of Yc properly, and correctly overwriting the origin of the slice filter. However, as the linked animation shows, the slice still does not move. Am I implementing the FindSource incorrectly? My thanks for any continued assistance that you can provide!

Sincerely,  
Nathaniel Wood

[sample\_animation\_compressed.wmv](https://discourse.paraview.org/uploads/short-url/7gnP3KLbh12enkUA5n0sQrjRK45.wmv) (1.6 MB)

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [December 23, 2020, 6:40pm UTC](https://discourse.paraview.org/t/querying-attribute-value-within-dataset/6119/4 "2020-12-23T18:40:12Z")

</div>

Can you share a sample dataset with me, that’ll make this easier? Feel free to email me directly with the dataset.

---

<div class="post-metadata">

### Author: ![nwood99](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/n/a88e57/32.png) [@nwood99](https://discourse.paraview.org/u/nwood99)
#### Post date: [December 23, 2020, 6:46pm UTC](https://discourse.paraview.org/t/querying-attribute-value-within-dataset/6119/5 "2020-12-23T18:46:21Z")

</div>

Utkarsh,

I have emailed a small representative dataset to email address that notified me of your response. Please let me know if you did not receive it.

Sincerely,  
Nathaniel Wood

---

<div class="post-metadata">

### Author: ![nwood99](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/n/a88e57/32.png) [@nwood99](https://discourse.paraview.org/u/nwood99)
#### Post date: [December 23, 2020, 6:54pm UTC](https://discourse.paraview.org/t/querying-attribute-value-within-dataset/6119/6 "2020-12-23T18:54:19Z")

</div>

Utkarsh,

My last attempt at sending a dataset failed because of file size constraints. Here is a small sample dataset, consisting of 20 time steps, each represented by a given .vtk file. Please let me know if this is inadequate!

Sincerely,

Nathaniel Wood

[sample\_dataset.zip](https://discourse.paraview.org/uploads/short-url/uQdWnyogVosWizy5XSTW2NvS9pw.zip) (1.81 MB)

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [December 23, 2020, 7:29pm UTC](https://discourse.paraview.org/t/querying-attribute-value-within-dataset/6119/7 "2020-12-23T19:29:02Z")

</div>

Here’s a working state file: [state.pvsm](https://discourse.paraview.org/uploads/short-url/oh3FERN8S1njmmiOZfS46CIdju6.pvsm) (328.2 KB)

The script I used is this:

```python
from paraview import simple

def start_cue(self): pass

def tick(self):
    reader = simple.FindSource("X_FULL_*")
    yc = reader.FieldData["Yc"].GetRange(0)[0]

    slice = simple.FindSource("Slice1")
    slice.SliceType.Origin[1] = yc

def end_cue(self): pass

```

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [December 23, 2020, 7:32pm UTC](https://discourse.paraview.org/t/querying-attribute-value-within-dataset/6119/8 "2020-12-23T19:32:56Z")

</div>

I just noticed it lagging behind by 1 frame…I recall there’s something about ensuring the pipeline is updated…give me a few to figure that out.

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [December 23, 2020, 7:35pm UTC](https://discourse.paraview.org/t/querying-attribute-value-within-dataset/6119/9 "2020-12-23T19:35:53Z")

</div>

Here’s an updated state file: [state-fixed.pvsm](https://discourse.paraview.org/uploads/short-url/vdGbxIFHIGysnuK7Ue1aY9slRnb.pvsm) (328.3 KB) .

The script is as follows:

```python
from paraview import simple

def start_cue(self): pass

def tick(self):
    reader = simple.FindSource("X_FULL_*")
    time = self.GetClockTime()
    reader.UpdatePipeline(time)
    yc = reader.FieldData["Yc"].GetRange(0)[0]

    slice = simple.FindSource("Slice1")
    slice.SliceType.Origin[1] = yc

def end_cue(self): pass

```

---

<div class="post-metadata">

### Author: ![nwood99](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/n/a88e57/32.png) [@nwood99](https://discourse.paraview.org/u/nwood99)
#### Post date: [December 23, 2020, 8:51pm UTC](https://discourse.paraview.org/t/querying-attribute-value-within-dataset/6119/10 "2020-12-23T20:51:25Z")

</div>

Utkarsh,

This works! My thanks for all your help!

Sincerely,  
Nathaniel Wood
