[Paraview] Calculator and Time history

Eric E. Monson emonson at cs.duke.edu
Tue Mar 17 13:04:29 EDT 2009


Hey David,

I think you'll have trouble using the calculator filter for this  
because even if you time shift your data set, the variable will still  
have the same name so you won't be able to distinguish the original  
and time shifted values to add them together.

In principle you should be able to use a Python Programmable Filter to  
do this, since it can take two inputs and grab the scalars from each  
without worrying about the names. (Note, though, that there are  
sometimes issues with the pipeline updating properly when multiple  
temporal shifts are combined into a PPF -- bug 8156: http://www.vtk.org/Bug/view.php?id=8156 
  )

I use this method to calculate velocity of particles "on the fly". So,  
my example may be a little more complicated than you need because I  
have to make sure particle IDs match each other before calculating the  
difference in their positions, but hopefully you can get the main  
ideas from here:

Attach a Temporal Cache to your data set (size = 2). Attach a Temporal  
Shift Scale to this with a Post Shift of whatever time value (actual  
time, not data set index) you want. Then, highlight both the Cache and  
the Shift Scale together and apply a Python Programmable Filter. My  
output data set is a vtkUnstructuredGrid, so I set the output of the  
PPF to that, and then put my script in the first window. (I'll place  
it at the end of the email.) This script adds a new array to the data  
set containing my calculated values.

NOTE: The catch for me to get the pipeline to update all the temporal  
shifts properly is that I have to "keep visible" the Temporal Shift  
Scale (or something directly branching off of it), or else my  
velocities all come out as zero! (I'll also attach a screen shot of my  
pipeline to make it clear.)

Good luck -- when it works, it works great.
-Eric

------------------------------------------------------
Eric E Monson
Duke Visualization Technology Group

====================
from paraview.vtk import vtkFloatArray

in1 = self.GetInputDataObject(0,1).GetTimeStep(0)

in0 = self.GetInputDataObject(0,0).GetTimeStep(0)

pti0 = in0.GetPoints()
pti1 = in1.GetPoints()
pdi0 = in0.GetPointData()
pdi1 = in1.GetPointData()
pdi0.SetActiveScalars('leuk_globalids')
pdi1.SetActiveScalars('leuk_globalids')
id0 = pdi0.GetScalars()
id1 = pdi1.GetScalars()
numPts = id1.GetSize()

vec = vtkFloatArray()
vec.SetName('velocity')
vec.SetNumberOfComponents(3)
vec.SetNumberOfTuples(numPts)

for ii in range(id1.GetSize()):
	idx1 = ii
	globalID1 = id1.GetValue(idx1)
	idx0 = -1
	for jj in range(id0.GetSize()):
		globalID0tmp = id0.GetValue(jj)
		if globalID0tmp == globalID1:
			idx0 = jj
			break
	if idx0 >= 0:
		# compute velocity and put in vec
		tmpPos = [0.0, 0.0, 0.0]
		pos1 = pti1.GetPoint(idx1)
		pos0 = pti0.GetPoint(idx0)
		for kk in range(len(tmpPos)):
			tmpPos[kk] = pos1[kk] - pos0[kk]
		vec.SetTuple3(ii,tmpPos[0],tmpPos[1],tmpPos[2])
	else:
		# put zero velocity in vec
		vec.SetTuple3(ii,0.0,0.0,0.0)

out1 = self.GetOutputDataObject(0)
out1.ShallowCopy(in1)
out1.GetPointData().AddArray(vec)

====================

-------------- next part --------------
A non-text attachment was scrubbed...
Name: TemporalDiffPipe_sm.jpg
Type: image/jpeg
Size: 6224 bytes
Desc: not available
URL: <http://www.paraview.org/pipermail/paraview/attachments/20090317/01e1c5a5/attachment.jpg>
-------------- next part --------------


On Mar 17, 2009, at 11:05 AM, David Fuentes wrote:

> Hello,
>
> Is there a way to use the Calculator on a variable at two different  
> time
> instances?  I have a time series of data stored in an exodus file.   
> I'm
> trying to accumulate the sum of a variable over time and need to add  
> the
> previous value of a variable to the variable's current value.  Is  
> there
> a way to use the "Temporal Cache", "Temporal Shift Scale", or a  
> similar filter to
> provide the calculator access to a variable at a previous time  
> instance?
>
>
> Thank you,
> David Fuentes
>




More information about the ParaView mailing list