Loader class for vtu and pvtu files.
More...
|
def | __init__ (self, offset, get=1, file='data', type='vtu', mirrorPlane=None, rotateX=0, rotateY=0, rotateZ=0, scaleX=1, scaleY=1, scaleZ=1, silent=0) |
|
def | getTime (self) |
|
def | getVar (self, varname) |
|
def | getData (self) |
|
def | getPointData (self) |
|
def | getVars (self) |
|
def | getVarnames (self) |
|
def | getBounds (self) |
|
def | getVert (self, icell) |
|
def | getPointList (self) |
|
def | getCenterPoints (self) |
|
def | getSurface (self) |
|
def | getPieces (self, nBWidth, nBHeight, nIgnore) |
|
def | showValues (self, icell) |
|
def | getIcellByPoint (self, x, y) |
|
def | getPoints (self) |
|
def | mirror (self) |
|
def | reflectVar (self, var) |
|
def | getNdim (self) |
|
def | getAll (self) |
|
|
| tend = default_timer() |
| self.nblocks = self.data.GetMaximumNumberOfPieces() self.data.SetUpdateNumberOfPieces(self.nblocks) self.xBlockList=[] self.yBlockList=[] More...
|
|
Loader class for vtu and pvtu files.
Definition at line 50 of file read.py.
◆ __init__()
def read.load.__init__ |
( |
|
self, |
|
|
|
offset, |
|
|
|
get = 1 , |
|
|
|
file = 'data' , |
|
|
|
type = 'vtu' , |
|
|
|
mirrorPlane = None , |
|
|
|
rotateX = 0 , |
|
|
|
rotateY = 0 , |
|
|
|
rotateZ = 0 , |
|
|
|
scaleX = 1 , |
|
|
|
scaleY = 1 , |
|
|
|
scaleZ = 1 , |
|
|
|
silent = 0 |
|
) |
| |
Definition at line 54 of file read.py.
56 self.filenameout = file
59 self.mirrorPlane=mirrorPlane
62 self.rotateX = rotateX
63 self.rotateY = rotateY
64 self.rotateZ = rotateZ
71 self.filename=
''.join([self.filenameout,repr(offset).zfill(4),
'.vtu'])
72 self.datareader = v.vtkXMLUnstructuredGridReader()
74 self.filename=
''.join([self.filenameout,repr(offset).zfill(4),
'.pvtu'])
75 self.datareader = v.vtkXMLPUnstructuredGridReader()
77 self.filename=
''.join([self.filenameout,repr(offset).zfill(4),
'.vti'])
78 self.datareader = v.vtkXMLImageDataReader()
80 print(
'Unknown filetype')
82 if (self.silent == 0): print(
'========================================')
83 if (self.silent == 0): print(
'loading file %s' % (self.filename))
◆ getAll()
def read.load.getAll |
( |
|
self | ) |
|
Definition at line 401 of file read.py.
406 if (self.silent == 0): print(
'Reading data time= %f sec' % (tdata-t0))
408 if self.mirrorPlane !=
None:
409 if (self.silent == 0): print(
'========== Mirror about plane ',self.mirrorPlane,
' ... ============')
413 if (self.silent == 0): print(
'========== Initializing ... ============')
418 if (self.silent == 0): print(
'Getting vars time= %f sec' % (tvars-tdata))
422 if (self.silent == 0): print(
'Getting points time= %f sec' % (tpoints-tvars))
427 if (self.silent == 0): print(
'========== Finished loading %d cells in %f sec, have a nice day! ===========' % (self.ncells, (tend-t0) ))
◆ getBounds()
def read.load.getBounds |
( |
|
self | ) |
|
Definition at line 159 of file read.py.
160 return self.data.GetBounds()
◆ getCenterPoints()
def read.load.getCenterPoints |
( |
|
self | ) |
|
Definition at line 197 of file read.py.
197 def getCenterPoints(self):
202 except AttributeError:
207 except AttributeError:
208 if self.getNdim() == 2
or self.getNdim() == 3:
209 self.centerpoints=np.empty((self.ncells,2))
210 for icell
in range(self.ncells):
211 vert=self.getVert(icell)
212 self.centerpoints[icell,0]=vert[:,0].mean()
213 self.centerpoints[icell,1]=vert[:,1].mean()
214 if self.getNdim() == 1 :
215 self.centerpoints=np.empty((self.ncells))
216 for icell
in range(self.ncells):
217 vert=self.getVert(icell)
218 self.centerpoints[icell]=vert.mean()
221 if (self.silent == 0): print(
'Getting cell center coordiantes time=%f sec' % (tend-tstart))
222 return self.centerpoints
◆ getData()
def read.load.getData |
( |
|
self | ) |
|
Definition at line 104 of file read.py.
105 self.datareader.SetFileName(self.filename)
106 self.datareader.Update()
107 self.data = self.datareader.GetOutput()
108 self.ncells = self.data.GetNumberOfCells()
111 if (self.rotateX != 0
or self.rotateY != 0
or self.rotateZ != 0
112 or self.scaleX != 1
or self.scaleY != 1
or self.scaleZ != 1):
113 transform = v.vtkTransform()
114 transform.RotateX(self.rotateX)
115 transform.RotateY(self.rotateY)
116 transform.RotateZ(self.rotateZ)
117 transform.Scale(self.scaleX, self.scaleY, self.scaleZ)
118 transfilter = v.vtkTransformFilter()
119 transfilter.SetTransform(transform)
120 transfilter.SetInputData(self.data)
121 self.data = transfilter.GetOutput()
◆ getIcellByPoint()
def read.load.getIcellByPoint |
( |
|
self, |
|
|
|
x, |
|
|
|
y |
|
) |
| |
Definition at line 339 of file read.py.
339 def getIcellByPoint(self,x,y):
340 radii2 = (self.getCenterPoints()[:,0]-x)**2 + (self.getCenterPoints()[:,1]-y)**2
341 icell=radii2.argmin()
◆ getNdim()
def read.load.getNdim |
( |
|
self | ) |
|
Definition at line 389 of file read.py.
392 if abs(self.data.GetBounds()[1] - self.data.GetBounds()[0]) <= smalldouble:
393 self.ndim=self.ndim - 1
394 if abs(self.data.GetBounds()[3] - self.data.GetBounds()[2]) <= smalldouble:
395 self.ndim=self.ndim - 1
396 if abs(self.data.GetBounds()[5] - self.data.GetBounds()[4]) <= smalldouble:
397 self.ndim=self.ndim - 1
◆ getPieces()
def read.load.getPieces |
( |
|
self, |
|
|
|
nBWidth, |
|
|
|
nBHeight, |
|
|
|
nIgnore |
|
) |
| |
Definition at line 246 of file read.py.
246 def getPieces(self,nBWidth,nBHeight,nIgnore):
250 except AttributeError:
253 [self.xBlockList,self.yBlockList]
254 except AttributeError:
260 nPoints = np.shape(pts)[0]
264 nBSize=(nBWidth+1)*(nBHeight+1)
266 nBlocks=int(nPoints/nBSize)
269 for iBlock
in range(nBlocks):
271 end =(iBlock+1)*nBSize-1
273 for i
in range(start,start+nBWidth+1):
274 self.xBlockList.append(pts[i][0])
275 self.yBlockList.append(pts[i][1])
277 for i
in range(start+nBWidth,end+1,nBWidth+1):
278 self.xBlockList.append(pts[i][0])
279 self.yBlockList.append(pts[i][1])
281 for i
in range(end,end-nBWidth-1,-1):
282 self.xBlockList.append(pts[i][0])
283 self.yBlockList.append(pts[i][1])
285 for i
in range(end-nBWidth,start-1,-nBWidth-1):
286 self.xBlockList.append(pts[i][0])
287 self.yBlockList.append(pts[i][1])
289 self.xBlockList.append(
None)
290 self.yBlockList.append(
None)
◆ getPointData()
def read.load.getPointData |
( |
|
self | ) |
|
Definition at line 125 of file read.py.
125 def getPointData(self):
127 if self.data.GetPointData().GetNumberOfArrays() == 0:
128 c2p = v.vtkCellDataToPointData()
132 c2p.SetInputData(self.data)
133 self.pointdata=c2p.GetOutput()
139 self.pointdata=self.data
◆ getPointList()
def read.load.getPointList |
( |
|
self | ) |
|
Definition at line 174 of file read.py.
174 def getPointList(self):
178 except AttributeError:
181 [self.xlist,self.ylist]
182 except AttributeError:
183 if self.data.GetCell(0).GetCellType() != 8 :
184 if (self.silent == 0): print(
"Can handle pixel types only")
188 for icell
in range(self.ncells):
189 pts=ah.vtk2array(self.data.GetCell(icell).GetPoints().GetData())
190 self.xlist.extend((pts[0][0],pts[1][0],pts[3][0],pts[2][0],
None))
191 self.ylist.extend((pts[0][1],pts[1][1],pts[3][1],pts[2][1],
None))
193 if (self.silent == 0): print(
'Getting formatted pointlist time=%f sec' % (tend-tstart))
194 return [self.xlist,self.ylist]
◆ getPoints()
def read.load.getPoints |
( |
|
self | ) |
|
Definition at line 345 of file read.py.
348 except AttributeError:
352 except AttributeError:
353 vtk_points=self.data.GetPoints().GetData()
354 self.points=ah.vtk2array(vtk_points)
◆ getSurface()
def read.load.getSurface |
( |
|
self | ) |
|
Definition at line 225 of file read.py.
225 def getSurface(self):
226 def calcSurface(icell):
227 vert=self.getVert(icell)
228 return np.sqrt(((vert[0][0]-vert[1][0])**2+(vert[0][1]-vert[1][1])**2)*
229 ((vert[1][0]-vert[2][0])**2+(vert[1][1]-vert[2][1])**2))
234 except AttributeError:
238 except AttributeError:
240 surface=list(map(calcSurface,list(range(self.ncells))))
241 self.surface=np.array(surface)
243 if (self.silent == 0): print(
'Getting cell surface (assuming rectangles) time=%f sec' % (tend-tstart))
◆ getTime()
def read.load.getTime |
( |
|
self | ) |
|
Definition at line 89 of file read.py.
91 self.time=ah.vtk2array(self.data.GetFieldData().GetArray(0))[0]
92 except AttributeError:
◆ getVar()
def read.load.getVar |
( |
|
self, |
|
|
|
varname |
|
) |
| |
Definition at line 97 of file read.py.
97 def getVar(self,varname):
99 exec(
"tmp=self.%s" % (varname))
101 except AttributeError:
102 print(
"Unknown variable", varname)
◆ getVarnames()
def read.load.getVarnames |
( |
|
self | ) |
|
Definition at line 151 of file read.py.
151 def getVarnames(self):
152 nvars= self.data.GetCellData().GetNumberOfArrays()
154 for i
in range(nvars):
155 varnames.append(self.data.GetCellData().GetArrayName(i))
◆ getVars()
def read.load.getVars |
( |
|
self | ) |
|
Definition at line 142 of file read.py.
143 nvars= self.data.GetCellData().GetNumberOfArrays()
144 for i
in range(nvars):
145 varname = self.data.GetCellData().GetArrayName(i)
146 if (self.silent == 0): print(
"Assigning variable:", varname)
147 vtk_values = self.data.GetCellData().GetArray(varname)
148 exec(
"self.%s = ah.vtk2array(vtk_values)[0:self.ncells]" % (varname))
◆ getVert()
def read.load.getVert |
( |
|
self, |
|
|
|
icell |
|
) |
| |
Definition at line 163 of file read.py.
163 def getVert(self,icell):
164 if self.data.GetCell(icell).GetCellType() == 8 :
165 pts=ah.vtk2array(self.data.GetCell(icell).GetPoints().GetData())
166 return np.array((pts[0][0:2],pts[1][0:2],pts[3][0:2],pts[2][0:2]))
167 if self.data.GetCell(icell).GetCellType() == 3 :
168 pts=ah.vtk2array(self.data.GetCell(icell).GetPoints().GetData())
169 return np.array((pts[0][0],pts[1][0]))
171 if (self.silent == 0): print(
"Can handle only type 3 or type 8")
◆ mirror()
def read.load.mirror |
( |
|
self | ) |
|
Definition at line 367 of file read.py.
369 vr=v.vtkReflectionFilter() 370 vr.SetInputData(self.data) 371 vr.SetPlane(self.mirrorPlane) 372 self.data=vr.GetOutput() 375 self.ncells = self.data.GetNumberOfCells()
◆ reflectVar()
def read.load.reflectVar |
( |
|
self, |
|
|
|
var |
|
) |
| |
Definition at line 378 of file read.py.
378 def reflectVar(self,var):
379 if self.mirrorPlane == 0:
380 CC=self.getCenterPoints()
384 if (self.silent == 0): print(
'reflection of this plane not yet implemented, sorry')
◆ showValues()
def read.load.showValues |
( |
|
self, |
|
|
|
icell |
|
) |
| |
Definition at line 332 of file read.py.
332 def showValues(self,icell):
333 if (self.silent == 0): print(
'=======================================================')
334 if (self.silent == 0): print(
'icell= %d; x=%e; y=%e' % (icell,self.getCenterPoints()[icell,0],self.getCenterPoints()[icell,1]))
335 for varname
in self.getVarnames():
336 exec(
"if (self.silent == 0): print '%s =', self.%s[icell]" % (varname,varname))
◆ centerpoints
◆ data
◆ datareader
◆ filename
◆ filenameout
◆ isLoaded
◆ mirrorPlane
◆ ncells
◆ ndim
◆ offset
◆ pointdata
◆ points
◆ rotateX
◆ rotateY
◆ rotateZ
◆ scaleX
◆ scaleY
◆ scaleZ
◆ silent
◆ surface
◆ tend
self.nblocks = self.data.GetMaximumNumberOfPieces() self.data.SetUpdateNumberOfPieces(self.nblocks) self.xBlockList=[] self.yBlockList=[]
for i in range(nIgnore,self.nblocks): self.data.SetUpdatePiece(i) self.data.Update() pts = ah.vtk2array(self.data.GetPoints().GetData()) nPoints = np.shape(pts)[0]
for i in range(nPoints): if ((i < (nBWidth+1))or(i%(nBWidth+1)==nBWidth)): self.xBlockList.append(pts[i][0]) self.yBlockList.append(pts[i][1]) self.xBlockList.append(None) self.yBlockList.append(None) for i in range(nPoints): if (i%(nBWidth+1)==0): self.xBlockList.append(pts[i][0]) self.yBlockList.append(pts[i][1]) self.xBlockList.append(None) self.yBlockList.append(None) for i in range(nPoints): if (i>(nBWidth+1)*nBHeight): self.xBlockList.append(pts[i][0]) self.yBlockList.append(pts[i][1]) self.xBlockList.append(None) self.yBlockList.append(None)
self.data.SetUpdateNumberOfPieces(1) self.data.SetUpdatePiece(0) self.data.Update()
Definition at line 328 of file read.py.
◆ time
◆ type
◆ xBlockList
◆ xlist
◆ yBlockList
◆ ylist
The documentation for this class was generated from the following file: