[Paraview] storing output calculated by python running in parallel - write to a file? (UNCLASSIFIED)

Utkarsh Ayachit utkarsh.ayachit at kitware.com
Tue Jul 22 10:31:52 EDT 2014


Ah...no. Alas, you cannot directly use "CreateWriter" in the script
for the Programmable Filter. You'll need to use "save data" after
applying the filter. Alternatively, you can use mpi4py module to
gather the sum result to the root node and then on the root node,
create vtkDelimitedTextWriter directly and save the result out. I can
send you sample script, if you need one.

Utkarsh

p.s.  This email was waiting in draft state for a while for this
sample script, didn't get around to it. Figured I'd at least send this
response and work on the sample script if needed :).

On Mon, Jul 7, 2014 at 11:52 AM, Su, Simon M CTR USARMY ARL (US)
<simon.m.su.ctr at mail.mil> wrote:
> Classification: UNCLASSIFIED
> Caveats: NONE
>
> Hi Utkarsh,
>
> Yes that is exactly what I wanted to do. I am using the programmable filter to
> add up all the values for a cell/point variable by iterating through the
> number of cells/points using python loop and write out the sum. Is there an
> example on how to do this? How will I format the output before writing it to
> the file? In my script below which you helped with last week, how would you
> have the paraview.simple.CreateWriter() class to write out just the sum
> variable?
>
> Thank you very much
> -simon
>
>
>
>
> 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()
>
>     tsum = 0
>
>     for i in range(0, numPoints):
>         tsum = tsum + toSum.GetValue(i)
>     return tsum
>
>
> input = self.GetInputDataObject(0, 0)
> output = self.GetOutputDataObject(0)
> sum = 0
>
> print sum
> if input.IsA("vtkUniformGridAMR"):
>     # This initializes AMR properly. It will share the dataset instances
>     # but we will clone those later.
>     output.ShallowCopy(input)
>
>     iter = input.NewIterator()
>     iter.UnRegister(None)
>     iter.InitTraversal()
>     while not iter.IsDoneWithTraversal():
>         curInput = iter.GetCurrentDataObject()
>         curOutput = curInput.NewInstance()
>         sum = sum + calculateSum(curInput, curOutput)
>         output.SetDataSet(iter, curOutput)
>         curOutput.UnRegister(None)
>         iter.GoToNextItem();
> else:
>     sum = sum + calculateSum(input, output)
>
> # write sum to file
> writer = CreateWriter('foo.csv')
> ......
>
>
>
>
>
>
>
> -----Original Message-----
> From: Utkarsh Ayachit [mailto:utkarsh.ayachit at kitware.com]
> Sent: Monday, July 07, 2014 11:36 AM
> To: Su, Simon M CTR USARMY ARL (US)
> Cc: paraview at paraview.org
> Subject: Re: [Paraview] storing output calculated by python running in
> parallel - write to a file? (UNCLASSIFIED)
>
> Simon,
>
> If you're saving out data generated by a pipeline (which can include
> Programmable filter or Python calculator), then you should use
> CreateWriter(http://www.paraview.org/ParaView3/Doc/Nightly/www/py-doc/paraview.simple.html#paraview.simple.CreateWriter)
> to create a writer and then write the data out -- akin to "Save Data"
> in ParaView.
>
> Utkarsh
>
> On Mon, Jul 7, 2014 at 11:30 AM, Su, Simon M CTR USARMY ARL (US)
> <simon.m.su.ctr at mail.mil> wrote:
>> Classification: UNCLASSIFIED
>> Caveats: NONE
>>
>> Hello,
>>
>> In my python script (ran using pvbatch mypythonscript.py in parallel
>> environment), how do I save out the data I calculated to a file? How
>> will be parallel execution affect the writing of the output to a file
>> (which process will be doing the writing)?
>>
>> In a none parallel mode, this is what I want to do which write the
>> output to out.txt file.
>>
>> f = open('out.txt', 'w')
>> print >> f, 'Filename:', filename  # or f.write('...\n')
>> f.close()
>>
>> what is the parallel equivalent of that?
>>
>> Any help is much appreciated.
>>
>> Thanks
>> -simon
>>
>>
>>
>>
>> Classification: UNCLASSIFIED
>> Caveats: NONE
>>
>>
>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the ParaView Wiki at:
>> http://paraview.org/Wiki/ParaView
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/paraview
>>
>
> Classification: UNCLASSIFIED
> Caveats: NONE
>
>


More information about the ParaView mailing list