[Paraview] pvbatch and paraview to extract images and data.

Andy Bauer andy.bauer at kitware.com
Thu Mar 22 13:16:58 EDT 2012


For rescaling data, the following works for coprocessing:
===============
        for view in cp_views:
            if timestep % view.cpFrequency == 0 or
datadescription.GetForceOutput() == True:
                reps = view.Representations
                for rep in reps:
                    if hasattr(rep, 'Visibility') and rep.Visibility == 1
and hasattr(rep, 'MapScalars') and rep.MapScalars != '':
                        input = rep.Input
                        input.UpdatePipeline() #make sure range is
up-to-date
                        lut = rep.LookupTable
                        if lut == None:
                            continue
                        if rep.ColorAttributeType == 'POINT_DATA':
                            datainformation =
input.GetPointDataInformation()
                        elif rep.ColorAttributeType == 'CELL_DATA':
                            datainformation = input.GetCellDataInformation()
                        else:
                            print 'something strange with color attribute
type', rep.ColorAttributeType

                        if lut.VectorMode != 'Magnitude'
or
datainformation.GetArray(rep.ColorArrayName).GetNumberOfCompo
nents() == 1:
                            datarange =
datainformation.GetArray(rep.ColorArrayName).GetRange(lut.VectorComponent)
                        else:
                            datarange = [0,0]
                            for i in
range(datainformation.GetArray(rep.ColorArrayName).GetNumberOfComponents()):
                                for j in range(2):
                                    datarange[j] +=
datainformation.GetArray(rep.ColorArrayName).GetRange(i)[j]*datainformation.GetArray(rep.ColorAr
rayName).GetRange(i)[j]
                            datarange[0] = math.sqrt(datarange[0])
                            datarange[1] = math.sqrt(datarange[1])

                        rgbpoints = lut.RGBPoints.GetData()
                        numpts = len(rgbpoints)/4
                        minvalue = min(datarange[0], rgbpoints[0])
                        maxvalue = max(datarange[1],
rgbpoints[(numpts-1)*4])
                        if minvalue != rgbpoints[0] or maxvalue !=
rgbpoints[(numpts-1)*4]:
                            # rescale all of the points
                            oldrange = rgbpoints[(numpts-1)*4] -
rgbpoints[0]
                            newrange = maxvalue - minvalue
                            newrgbpoints = list(rgbpoints)
                            for v in range(numpts):
                                newrgbpoints[v*4] =
minvalue+(rgbpoints[v*4] - rgbpoints[0])*newrange/oldrange

                            lut.RGBPoints.SetData(newrgbpoints)
=============
You'll have to modify it some but hopefully that gives you an idea.

To save your data you'll have to specify a writer.  The most general is the
DataSetWriter with vtk file extension.  Something like XMLPolyDataWriter,
XMLUnstructuredGridWriter, etc. could also be used, depending on the output
grid type.  Then for the writer, do "<writer>.FileName = "myfilename.<ext>"
and then <writer>.UpdatePipeline().  The writer information seems like it
should be captured by the python trace but I'm not sure why it isn't.  You
may want to submit this as a bug or feature request.

Andy


On Thu, Mar 22, 2012 at 12:48 PM, 0252525 <s00060942p at gmail.com> wrote:

> Dear All,
>
> I have been recently experimenting with OpenFOAM and paraview, in
> particular pvbatch. In particular, I am interested in exporting images and
> data from paraview, using pvbatch.
>
> To this end, I do the following:
>
> [1] Run OpenFOAM and generate the required "state file" in paraview (say
> pressure.pvsm)
> [2] Run "pvbatch extract.py", where my extract.py looks as follows:
>
> from paraview.simple import *
>
> servermanager.LoadState("/home/jameswh/OpenFOAM/ram-2.1.0/run/tutorials/incompressible/icoFoam/cavity/pressure.pvsm")
> GetActiveSource()
> SetActiveView(GetRenderView())
> Render()
> WriteImage("/home/ram/image1.png")
>
> and it works fine. However, I have two fundamental problems:
>
> [1] If I change my input to OpenFOAM, and run the above (extract.py), the
> images are not scaled to the correct units (pressure). How can I
> automatically rescale the results value? So, say for case 1 run, my min and
> max are 5 and 10, for case 2 run, my min and max and 10 and 20. However,
> since Iam using the pvsm from case 1, my images in case 2 also show 5 and
> 10, rather than 10 and 20. I found the "properties" tag in the *.pvsm file,
> and I notice that the values are "hard coded" How can I say "scale values
> automatically"? I hope my question is clear.
>
> [2] Secondly, I would like to write out values using "Save Data", and I am
> looking for an equivalent of "save data" in pvbatch. I tried doing a python
> trace, but, when I do a Save Data, it does not seem to track/trace anything.
>
> If anyone has encountered the above problems, and possibly have a
> solution, Id be glad if you could point me in the right direction.
>
> Thank you for your time.
>
> regards,
>
> James WH
>
> Research Fellow in Engineering,
> Oxford.
>
> _______________________________________________
> 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://www.paraview.org/mailman/listinfo/paraview
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.paraview.org/pipermail/paraview/attachments/20120322/ee2ef819/attachment.htm>


More information about the ParaView mailing list