# Paraview arrays to numpy arrays

 Register Blogs Members List Search Today's Posts Mark Forums Read

 April 10, 2014, 09:01 Paraview arrays to numpy arrays #1 Senior Member   Francois Beaubert Join Date: Mar 2009 Location: Lille, France Posts: 142 Rep Power: 9 Hi all, I'm trying to use IPython with numpy to do some of my post-processing. I've encountered the following difficulty: I'm unable to import paraview arrays into numpy ones. Here is a simple example that read an OpenFoam case, sample the data on lines using PlotOverline filter and export them in csv files: Code: ```try: paraview.simple except: from paraview.simple import * paraview.simple._DisableFirstRenderCameraReset() import math # Define geometric parameters D = 0.036 # Define points coordinates in cylindrical coordinates r1 = 0.0 r2 = 0.019 theta1 = 90 theta2 = 90 theta1Rad = theta1 * math.pi/180 theta2Rad = theta2 * math.pi/180 z1 = 1*D z2 = 1*D # Transform points coordinates from cylindrical to cartesian x1 = r1*math.cos(theta1Rad) x2 = r2*math.cos(theta2Rad) y1 = r1*math.sin(theta1Rad) y2 = r2*math.sin(theta2Rad) # Define the OpenFOAM data source case_OpenFOAM = OpenDataFile('./case1.OpenFOAM') case_OpenFOAM.MeshParts = ['internalMesh', 'wall - group'] case_OpenFOAM.VolumeFields = ['p', 'U', 'Ucyl', 'ccCyl'] for i in range(0,10): # Define the source data SetActiveSource(case_OpenFOAM) # Define the line PlotOverLine1 = PlotOverLine( Source="High Resolution Line Source" ) zPos = i*D PlotOverLine1.Source.Point1 = [x1, y1, z1 + zPos] PlotOverLine1.Source.Point2 = [x2, y2, z2 + zPos] PassArrays1 = PassArrays() PassArrays1.PointDataArrays = ['arc_length','ccCyl','U', 'Ucyl', 'p'] source = PassArrays1 # Define filename of the outputs fileName = 'line' + '_r=' + str(r1) + '-' + str(r2) + '_theta=' + str(theta1) + '-' + str(theta2) + '_z=' + str(z1+ zPos) + '-' + str(z2 + zPos) + '.csv' writer = CreateWriter(fileName, source) writer.FieldAssociation = "Points" # or "Cells" writer.UpdatePipeline() del writer``` Everything work correctly but rather than importing the data from the files into numpy arrays with loadtxt, I would prefer to import them directly into numpy arrays right after my PlotOverline: convert paraview arrays directly into numpy arrays I know that some support functions from numpy_support are readily available for this kind of tasks: Code: ```from vtk.util import numpy_support as npvtk vtkarray = npvtk.numpy_to_vtk(numpy_array) numpy_array = npvtk.vtk_to_numpy(vtkarray)``` I've tried to use them without success: Code: ```pParaview = case_OpenFOAM.PointData['p'] pNumpy = npvtk.vtk_to_numpy(pParaview)``` But get the following error messages: Code: ```--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) in () ----> 1 pNumpy = npvtk.vtk_to_numpy(pParaview) /opt/paraviewopenfoam410/lib/paraview-4.1/site-packages/vtk/util/numpy_support.py in vtk_to_numpy(vtk_array) 206 # Get the data via the buffer interface 207 dtype = get_numpy_array_type(typ) --> 208 result = numpy.frombuffer(vtk_array, dtype=dtype) 209 if shape[1] == 1: 210 shape = (shape[0], ) /opt/paraviewopenfoam410/lib/paraview-4.1/site-packages/paraview/servermanager.pyc in __getattr__(self, name) 1433 array = self.FieldData.GetFieldData().GetArrayInformation(self.Name) 1434 if not array: return None -> 1435 return getattr(array, name) 1436 1437 def __repr__(self): AttributeError: __buffer__``` Any advice ? How to manipulate paraview arrays using numpy ? Thank you very much for your help Regards François

 April 13, 2014, 16:48 #2 Super Moderator   Bruno Santos Join Date: Mar 2009 Location: Lisbon, Portugal Posts: 9,736 Blog Entries: 39 Rep Power: 103 Greetings François, I think you're overlooking an important detail with OpenFOAM related data: it's handled as "MultiBlock" data. A few reference threads: Extracting ParaView Data into Python Arrays - see post #2 Get data from Calculator filter in python script post #16 Best regards, Bruno __________________ OpenFOAM: FAQ | Getting started Forum: How to get help, to post code/output and forum guide What am I doing/planning: blog/wiki Read this before sending me PM

 April 14, 2014, 08:33 #3 Senior Member   Francois Beaubert Join Date: Mar 2009 Location: Lille, France Posts: 142 Rep Power: 9 Thanks for the advice Bruno ! I will look at the threads you have mentioned Regards, François

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Dan Pearce OpenFOAM Installation 5 January 8, 2014 06:47 chrisb2244 OpenFOAM Installation 2 August 21, 2013 13:24 Jeffzda ParaView 7 December 6, 2012 09:10 lentschi OpenFOAM Installation 1 March 9, 2011 03:32 smart OpenFOAM Installation 13 November 16, 2009 22:41

All times are GMT -4. The time now is 12:48.