[Paraview] calculate total sum of a variable in CTH data

Su, Simon M CTR USARMY ARL (US) simon.m.su.ctr at mail.mil
Tue Jul 1 08:40:23 EDT 2014


Hello,

I am trying to simply add up all the values of a variable in the CTH dataset using programmable filter with the python code at the end of this email..

The code seems to be working for the other dataset that I worked in the past. But for CTH dataset, it is giving me an error with GetCellData


Traceback (most recent call last):

File "<string>", line 22, in <module>

File "<string>", line 43, in RequestData

File "<string>", line 8, in calculateSum

AttributeError: GetCellData

When I printed the output for CTH dataset it is giving me


vtkNonOverlappingAMR (0x7f96ca7675c0)

Debug: Off

Modified Time: 860345754

Reference Count: 2

Registered Events: (none)

Information: 0x7f96ca767040

Data Released: False

Global Release Data: Off

UpdateTime: 856914636

Field Data:

Debug: Off

Modified Time: 855459763

Reference Count: 1

Registered Events: (none)

Number Of Arrays: 4

Array 0 name = GlobalBounds

Array 1 name = GlobalBoxSize

Array 2 name = MinLevel

Array 3 name = MinLevelSpacing

Number Of Components: 4

Number Of Tuples: 6

Any help is in adding a variable in a CTH dataset is much appreciated.

thank you
-simon

p/s: sorry for the other unfinished email sent....



=========================================
def calculateSum(input, output):
    # Copy the cells etc.
    output.ShallowCopy(input)

    # Get the array to calculate the coefficient
    toSum = output.GetPointData().GetArray("MOMENT_X")

    # for each of the elements, calculate the three roots and store the real and imaginary output in separate arrays
    numPoints = toSum.GetSize()

    # create the output arrays
    sum = vtk.vtkDoubleArray()
    sum.SetNumberOfValues(numPoints)
    sum.SetName("sum")
    tsum = 0

    for i in range(0, numPoints):
        tsum = tsum + toSum.GetValue(i)

    for j in range(0, numPoints):
        sum.SetValue(j, tsum)

    output.GetPointData().AddArray(sum)

input = self.GetInputDataObject(0, 0)
output = self.GetOutputDataObject(0)

if input.IsA("vtkMultiBlockDataSet"):
    output.CopyStructure(input)
    iter = input.NewIterator()
    iter.UnRegister(None)
    iter.InitTraversal()
    while not iter.IsDoneWithTraversal():
        curInput = iter.GetCurrentDataObject()
        curOutput = curInput.NewInstance()
        curOutput.UnRegister(None)
        output.SetDataSet(iter, curOutput)
        calculateSum(curInput, curOutput)
        iter.GoToNextItem();
else:
    calculateSum(input, output)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/paraview/attachments/20140701/e7f6f66e/attachment-0001.html>


More information about the ParaView mailing list