For rescaling data, the following works for coprocessing:<br>===============<br> for view in cp_views:<br> if timestep % view.cpFrequency == 0 or datadescription.GetForceOutput() == True:<br> reps = view.Representations<br>
for rep in reps:<br> if hasattr(rep, 'Visibility') and rep.Visibility == 1 and hasattr(rep, 'MapScalars') and rep.MapScalars != '':<br> input = rep.Input<br>
input.UpdatePipeline() #make sure range is up-to-date<br> lut = rep.LookupTable<br> if lut == None:<br> continue<br> if rep.ColorAttributeType == 'POINT_DATA':<br>
datainformation = input.GetPointDataInformation()<br> elif rep.ColorAttributeType == 'CELL_DATA':<br> datainformation = input.GetCellDataInformation()<br>
else:<br> print 'something strange with color attribute type', rep.ColorAttributeType<br><br> if lut.VectorMode != 'Magnitude' or datainformation.GetArray(rep.ColorArrayName).GetNumberOfCompo<br>
nents() == 1:<br> datarange = datainformation.GetArray(rep.ColorArrayName).GetRange(lut.VectorComponent)<br> else:<br> datarange = [0,0]<br> for i in range(datainformation.GetArray(rep.ColorArrayName).GetNumberOfComponents()):<br>
for j in range(2):<br> datarange[j] += datainformation.GetArray(rep.ColorArrayName).GetRange(i)[j]*datainformation.GetArray(rep.ColorAr<br>rayName).GetRange(i)[j]<br>
datarange[0] = math.sqrt(datarange[0])<br> datarange[1] = math.sqrt(datarange[1])<br><br> rgbpoints = lut.RGBPoints.GetData()<br> numpts = len(rgbpoints)/4<br>
minvalue = min(datarange[0], rgbpoints[0])<br> maxvalue = max(datarange[1], rgbpoints[(numpts-1)*4])<br> if minvalue != rgbpoints[0] or maxvalue != rgbpoints[(numpts-1)*4]:<br>
# rescale all of the points<br> oldrange = rgbpoints[(numpts-1)*4] - rgbpoints[0]<br> newrange = maxvalue - minvalue<br> newrgbpoints = list(rgbpoints)<br>
for v in range(numpts):<br> newrgbpoints[v*4] = minvalue+(rgbpoints[v*4] - rgbpoints[0])*newrange/oldrange<br><br> lut.RGBPoints.SetData(newrgbpoints)<br>
=============<br>You'll have to modify it some but hopefully that gives you an idea.<br><br>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.<br>
<br>Andy<br>
<br><br><div class="gmail_quote">On Thu, Mar 22, 2012 at 12:48 PM, 0252525 <span dir="ltr"><<a href="mailto:s00060942p@gmail.com" target="_blank">s00060942p@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Dear All,<br><br>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.<br><br>To this end, I do the following:<br>
<br>[1] Run OpenFOAM and generate the required "state file" in paraview (say pressure.pvsm)<br>[2] Run "pvbatch extract.py", where my extract.py looks as follows:<br><br>from paraview.simple import *<br>
servermanager.LoadState("/home/jameswh/OpenFOAM/ram-2.1.0/run/tutorials/incompressible/icoFoam/cavity/pressure.pvsm")<br>GetActiveSource()<br>SetActiveView(GetRenderView())<br>Render()<br>WriteImage("/home/ram/image1.png")<br>
<br>and it works fine. However, I have two fundamental problems:<br><br>[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.<br>
<br>[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.<br>
<br>If anyone has encountered the above problems, and possibly have a solution, Id be glad if you could point me in the right direction.<br><br>Thank you for your time.<br><br>regards,<br><br>James WH<br><br>Research Fellow in Engineering,<br>
Oxford.<br>
<br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the ParaView Wiki at: <a href="http://paraview.org/Wiki/ParaView" target="_blank">http://paraview.org/Wiki/ParaView</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.paraview.org/mailman/listinfo/paraview" target="_blank">http://www.paraview.org/mailman/listinfo/paraview</a><br>
<br></blockquote></div><br>