Just to answer my own questions. Indeed it is possible to skip ProgrammableFilter if you are programming in pvbatch. The data can be accessed in the following way (which was my question). Below is much more efficient, because there is no need for writing data to file. Well, hopefully this information can be usefull for people writing batch programs and are struggling with the proper set of commands to retrieve the data from the arrays. Not much information can be found with google, but just sufficient to give me the right clues to figure it out.
Regards. Eelco import csv,os sm=servermanager sm.Connect() # Here the stuff to read you data, in my case a time series of VTK files UzName='U_Z' Uzcomponent = Calculator() Uzcomponent.AttributeMode = 'point_data' Uzcomponent.Function = UzName Uzcomponent.ResultArrayName = UzName Uzcomponent.UpdatePipeline() cnt=0 uzminlist=[] xpminlist=[] for time in timesteps: SetActiveSource(Uzcomponent) Uzcomponent.UpdatePipeline() print "Quick search at time ",time Udata=sm.Fetch(Uzcomponent) UPoints =Udata.GetPoints() UPointData =Udata.GetPointData() UzArrayData=UPointData.GetArray(UzName) ntuples=UzArrayData.GetNumberOfTuples() uzmin=UzArrayData.GetTuple1(0) xpmin=UPoints.GetPoint(0) for i in range(1,ntuples): uz=UzArrayData.GetTuple1(i) if uz < uzmin: xpmin=UPoints.GetPoint(i) uzmin=UzArrayData.GetTuple1(i) print "Found : ",uzmin,x uzminlist.append(uzmin) xpminlist.append(xpmin) fp=open(csvfile,"w") writer=csv.writer(fp,delimiter=' ') for i in range(0,cnt): ar=[] for j in range(0,3): ar.append(xpminlist[i][j]) ar.append(uzminlist[i]) writer.writerow(ar) fp.close() On Tue, Mar 15, 2011 at 12:04 PM, Eelco van Vliet <eelc...@gmail.com> wrote: > For those interested, I will give here my script how to extract the minimum > value and its location in a serie of time steps, write it to file and put > spheres on the local minimum. > > Since my knowledge of VTK is quite limited, I didn't know how to access the > data, so I use some tricking to get it. Probably a much cleaner way of doing > this is possible. Be free to give suggestions > > In order to get the locations from the ProgrammableFilter, my trick is to > write all the data with CSVWriter to separate files, and then loop over the > time step and read each file which containt the vtkTable data. This can > porbably as well obtained directory from the ProgrammableFilter, but how ? > > Also, I wonder if it is necessary to use the ProgramableFilter in the first > place, because I am using pvbatch. So I am calling a python script from a > python script. The reason was that this allow to create a vtkTable, but > again, this can be done better I guess. > > Anyway, any comments are welcome. I am also still learning this batch > programming in paraview. anyway, the version below works and I am quite > satisfied about the result > > Regards > > Eelco > > > > try: paraview.simple > except: from paraview.simple import * > import os # file i/o tools > import sys # system tools > import re # regular expressions > import subprocess > import pv # load my own parafoam routines > import math > from optparse import OptionParser > > paraview.simple._DisableFirstRenderCameraReset() > > sm=servermanager > sm.Connect() > view = CreateRenderView() > > * > U_pxy_z0_600_t0 = LegacyVTKReader( FileNames=[ List of filename ])* > > * > Calculator2 = Calculator() > Calculator2.AttributeMode = 'point_data' > Calculator2.Function = 'U_Z' > Calculator2.ResultArrayName = 'U_Z' > > # define the programmable filter here to extract the minimum and position > UzMinProgFilter=ProgrammableFilter() > UzMinProgFilter.OutputDataSetType='vtkTable' > UzMinProgFilter.PythonPath = '' > UzMinProgFilter.RequestInformationScript = '' > UzMinProgFilter.Script = "\ > input=inputs[0]\n\ > output=self.GetTableOutput()\n\ > Uzdata = input.PointData['U_Z']\n\ > uzmin = Uzdata[0]\n\ > numPoints = input.GetNumberOfPoints()\n\ > pts = vtk.vtkPoints()\n\ > for i in range(numPoints):\n\ > uz=Uzdata[i]\n\ > if uz < uzmin:\n\ > minpos = input.GetPoint(i)\n\ > uzmin = uz\n\ > vtkTable_xpmin=vtk.vtkFloatArray()\n\ > vtkTable_xpmin.InsertNextValue(minpos[0])\n\ > vtkTable_xpmin.SetName('xpmin')\n\ > vtkTable_ypmin=vtk.vtkFloatArray()\n\ > vtkTable_ypmin.InsertNextValue(minpos[1])\n\ > vtkTable_ypmin.SetName('ypmin')\n\ > vtkTable_zpmin=vtk.vtkFloatArray()\n\ > vtkTable_zpmin.InsertNextValue(minpos[2])\n\ > vtkTable_zpmin.SetName('zpmin')\n\ > vtkTable_uzmin=vtk.vtkFloatArray()\n\ > vtkTable_uzmin.InsertNextValue(uzmin)\n\ > vtkTable_uzmin.SetName('uzmin')\n\ > output.AddColumn(vtkTable_xpmin)\n\ > output.AddColumn(vtkTable_ypmin)\n\ > output.AddColumn(vtkTable_zpmin)\n\ > output.AddColumn(vtkTable_uzmin)\n\ > " > > > csvfile="Minima.csv" > print "Writing all minima to CSV file: ",csvfile > > writer_all=CSVWriter(UzMinProgFilter,FileName=csvfile,WriteAllTimeSteps=1) > writer_all.UpdatePipeline() > > > *cnt=0 > print "Writing images:" > for time in timesteps: > # reading info from file cnt > csvfile="Minima%d%s" % (cnt,'.csv') > fp=open(csvfile,"r") > lineList=fp.readlines() > fp.close() > xp,yp,zp,uz=lineList[-1].split(',') > position=[float(xp),float(yp),float(zp)] > print "Put sphere at ",position > > > MinSphere=Sphere() > MinSphere.Radius=0.001 > MinSphere.Center=position > > rep_sphere = Show(MinSphere,view) > rep_sphere.DiffuseColor = [0.0, 0.0, 0.0] > > > > > On Fri, Mar 4, 2011 at 5:10 PM, Eelco van Vliet <eelc...@gmail.com> wrote: > >> Hi David, >> >> Many thanks for you suggestions. I was away for a while but had some time >> to look at this points this week again. The using the Python calculator >> brought me on the trail of using The Programmable Pythonscript filter. >> >> My quest: I want to extrate the minimum value and its position for a time >> series of VTK files and write the data for all the time step to one single >> file. >> >> With the advice so for, I now have the following construction. >> >> First I read a series of VTK files representating the velocity over a >> cross section >> >> *U_pxy_z0_600_t0 = LegacyVTKReader( FileNames=[ List of filename ])* >> >> Then I extract the U_z velocity component >> >> *Calculator2 = Calculator() >> Calculator2.AttributeMode = 'point_data' >> Calculator2.Function = 'U_Z' >> Calculator2.ResultArrayName = 'U_Z' >> >> >> *Then I create a Programmable Filter >> >> ProgrammableFilter2 = ProgrammableFilter() >> >> ProgrammableFilter2.RequestUpdateExtentScript = '' >> ProgrammableFilter2.PythonPath = '' >> ProgrammableFilter2.RequestInformationScript = '' >> ProgrammableFilter2.OutputDataSetType = 'vtkTable' >> ProgrammableFilter2.Script = 'blabla' >> >> >> For the script of the Programmable filter, I am now doing the following >> >> input=inputs[0] >> >> Uzdata= input.PointData['U_Z'] >> >> numPoints = input.GetNumberOfPoints() >> >> uzmin=Uzdata[0] >> >> for i in range(numPoints): >> >> uz=Uzdata[i] >> >> if uz<uzmin: >> >> minpos=input.GetPoint(i) >> >> uzmin=uz >> >> print "uzmin: ",uzmin,min(Uzdata) >> >> print "minpos: ",minpos >> >> output.RowData.append(uzmin, 'uzmin') >> >> * >> *At this point I am stuck. First of all, the minpos variable is a tuple, >> and I don't know how to apend this to the output.RowData, because it needs >> to be and vtkArray. What is the way to convert a tuple into a vtkArray? >> >> Second of all: if I step over the time step and see correctly the minpos >> and uzmin value updated in the spreadsheet viewer. However, how can I >> collect all the values into one array and then write to a single file ? Or >> should I just write the data of each time step to a seperate file ? >> >> Hopefully someone can give me some advice on how to approach this issue. >> >> Many thanks in advance! >> >> Regards, >> >> Eelco >> >> >> On Fri, Feb 11, 2011 at 10:28 PM, David E DeMarle < >> dave.dema...@kitware.com> wrote: >> >>> I suggest replacing the Calculator and DescriptiveStatistics filters >>> with one python programmable filter (or python calculator if you are >>> using 3.10). That way the data type isn't changed and Fetch will do >>> what you expect it to - produce a standard vtkDataSet with 1 >>> point/cell. >>> >>> The python calculator expression to get an average x,y,and Z point >>> location is: >>> hstack([ >>> [global_mean(inputs[0].Points[:,0])], >>> [global_mean(inputs[0].Points[:,1])], >>> [global_mean(inputs[0].Points[:,2])] >>> ]) >>> >>> If you then Fetch it's output and get the min (or equivalently max or >>> just deliver the whole thing and just look at any of the points) you >>> will get the average X Y and Z coordinates in a 3 component array >>> names Result. >>> >>> David E DeMarle >>> Kitware, Inc. >>> R&D Engineer >>> 28 Corporate Drive >>> Clifton Park, NY 12065-8662 >>> Phone: 518-371-3971 x109 >>> >>> >>> >>> On Fri, Feb 11, 2011 at 10:34 AM, Eelco van Vliet <eelc...@gmail.com> >>> wrote: >>> > Hi David, >>> > >>> > Thanks for you suggestion, I got much closer to what I want, but not >>> quite >>> > yet. I have the feeling I need one slight extra hint :) >>> > >>> > To obtain the position of a minimun value I now do the script below: I >>> get >>> > the mimimum value first with MinMax, then I Threshold the original data >>> on a >>> > range between min and 0.9*min (the minimum values are negative), then I >>> use >>> > the calculator to get the x and y position of this range, and then I >>> use the >>> > DescriptiveStatitics filter to get the average mean of the position. I >>> can >>> > even use Fetch again to obtain the data, but now the very last step: >>> how to >>> > I get the mean data itself ? Sorry, I just don't understand how that >>> > data.objects exactly work, and there is not much assessible >>> documentation on >>> > it. >>> > >>> > I hope you can give me one last hint >>> > >>> > Regards >>> > >>> > Eelco >>> > >>> > mm=MinMax(Uzcomponent) >>> > mm.Operation="MIN" >>> > mindata=sm.Fetch(Uzcomponent,mm,mm) >>> > mindata.GetPointData().GetNumberOfArrays() >>> > a0 = mindata.GetPointData().GetArray(1) >>> > uzname=a0.GetName() >>> > uzmin=a0.GetTuple1(0) >>> > print "minimum of %s found: %g\n "%(uzname,uzmin) >>> > >>> > Threshold1 = Threshold(Uzcomponent) >>> > Threshold1.Scalars=['POINTS',uzname] >>> > Threshold1.ThresholdRange=[uzmin,0.9*uzmin] >>> > >>> > CalcPos = Calculator() >>> > CalcPos.AttributeMode = 'point_data' >>> > CalcPos.Function = 'iHat*coordsX+jHat*coordsY+kHat*coordsZ' >>> > CalcPos.ResultArrayName = 'MinPos' >>> > >>> > DescriptiveStatistics1 = DescriptiveStatistics() >>> > DescriptiveStatistics1.VariablesofInterest = ['MinPos'] >>> > statistics=sm.Fetch(DescriptiveStatistics1) >>> > >>> > >>> > >>> > >>> > On Thu, Feb 10, 2011 at 7:00 PM, David E DeMarle < >>> dave.dema...@kitware.com> >>> > wrote: >>> >> >>> >> The min max filter unfortunately doesn't keep track of which tuple and >>> >> processor it found the min in so you can't get back to the particular >>> >> point or cell it came from. >>> >> >>> >> Instead of using fetch and minmax, try using a values selection. Set >>> >> the value to be that minimum value. Once you extract the selection and >>> >> fetch it to the client, you get a copy of the actuall cell(s)/point(s) >>> >> that have the minimum value and you can query them directly for their >>> >> spatial location. >>> >> >>> >> David E DeMarle >>> >> Kitware, Inc. >>> >> R&D Engineer >>> >> 28 Corporate Drive >>> >> Clifton Park, NY 12065-8662 >>> >> Phone: 518-371-3971 x109 >>> >> >>> >> >>> >> >>> >> On Thu, Feb 10, 2011 at 12:13 PM, Eelco van Vliet <eelc...@gmail.com> >>> >> wrote: >>> >> > Dear Paraviewers, >>> >> > >>> >> > I would like to extract the location of a minimum value from a data >>> set >>> >> > in >>> >> > pvbatch >>> >> > >>> >> > I were able to find the value of the minimum with >>> >> > >>> >> > >>> >> > >>> >> > >>> >> > mm=MinMax(Uzcomponent) >>> >> > mm.Operation="MIN" >>> >> > mindata=sm.Fetch(Uzcomponent,mm,mm) >>> >> > mindata.GetPointData().GetNumberOfArrays() >>> >> > a0 = mindata.GetPointData().GetArray(1) >>> >> > a1 = mindata.GetScalar() >>> >> > print "name 1: ", a0.GetName() >>> >> > print "tuple1: ", a0.GetTuple1(0) >>> >> > >>> >> > Here, a0.GetTyple1 give me the value of the minimum >>> >> > >>> >> > However: How do I find the location of this value ? >>> >> > >>> >> > Any hint appriciate! >>> >> > >>> >> > Regards >>> >> > >>> >> > Eelco >>> >> > >>> >> > >>> >> > _______________________________________________ >>> >> > 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 >>> >> > >>> >> > >>> > >>> > >>> >> >> >
_______________________________________________ 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