pmmoto.io.evtk package
Submodules
pmmoto.io.evtk.evtk module
- pmmoto.io.evtk.evtk.writeArrayToFile(stream, data)
- pmmoto.io.evtk.evtk.writeArraysToFile(stream, x, y, z)
- pmmoto.io.evtk.evtk.writeBlockSize(stream, block_size)
pmmoto.io.evtk.hl module
- pmmoto.io.evtk.hl.cylinderToVTK(path, x0, y0, z0, z1, radius, nlayers, npilars=16, cellData=None, pointData=None, comments=None)
Export cylinder as VTK unstructured grid.
- Parameters:
path (path to file without extension.)
x0 (center of cylinder.)
yo (center of cylinder.)
z0 (lower and top elevation of the cylinder.)
z1 (lower and top elevation of the cylinder.)
radius (radius of cylinder.)
nlayers (Number of layers in z direction to divide the cylinder.)
npilars (Number of points around the diameter of the cylinder.) – Higher value gives higher resolution to represent the curved shape.
cellData (dictionary with 1D arrays that store cell data.) – Arrays should have number of elements equal to ncells = npilars * nlayers.
pointData (dictionary with 1D arrays that store point data.) – Arrays should have number of elements equal to npoints = npilars * (nlayers + 1).
comments (list of comment strings, which will be added to the header section of the file.)
- Return type:
Full path to saved file.
- NOTE: This function only export vertical shapes for now. However, it should be easy to
rotate the cylinder to represent other orientations.
- pmmoto.io.evtk.hl.gridToVTK(path, x, y, z, cellData=None, pointData=None, comments=None)
Writes data values as a rectilinear or rectangular grid.
- Parameters:
path (name of the file without extension where data should be saved.)
x (coordinates of the nodes of the grid. They can be 1D or 3D depending if) – the grid should be saved as a rectilinear or logically structured grid, respectively. Arrays should contain coordinates of the nodes of the grid. If arrays are 1D, then the grid should be Cartesian, i.e. faces in all cells are orthogonal. If arrays are 3D, then the grid should be logically structured with hexahedral cells. In both cases the arrays dimensions should be equal to the number of nodes of the grid.
y (coordinates of the nodes of the grid. They can be 1D or 3D depending if) – the grid should be saved as a rectilinear or logically structured grid, respectively. Arrays should contain coordinates of the nodes of the grid. If arrays are 1D, then the grid should be Cartesian, i.e. faces in all cells are orthogonal. If arrays are 3D, then the grid should be logically structured with hexahedral cells. In both cases the arrays dimensions should be equal to the number of nodes of the grid.
z (coordinates of the nodes of the grid. They can be 1D or 3D depending if) – the grid should be saved as a rectilinear or logically structured grid, respectively. Arrays should contain coordinates of the nodes of the grid. If arrays are 1D, then the grid should be Cartesian, i.e. faces in all cells are orthogonal. If arrays are 3D, then the grid should be logically structured with hexahedral cells. In both cases the arrays dimensions should be equal to the number of nodes of the grid.
cellData (dictionary containing arrays with cell centered data.) – Keys should be the names of the data arrays. Arrays must have the same dimensions in all directions and must contain only scalar data.
pointData (dictionary containing arrays with node centered data.) – Keys should be the names of the data arrays. Arrays must have same dimension in each direction and they should be equal to the dimensions of the cell data plus one and must contain only scalar data.
comments (list of comment strings, which will be added to the header section of the file.)
- Return type:
Full path to saved file.
- pmmoto.io.evtk.hl.imageToVTK(path, origin=(0.0, 0.0, 0.0), spacing=(1.0, 1.0, 1.0), start=None, end=None, cellData=None, pointData=None, comments=None) None
Exports data values as a rectangular image.
- Parameters:
path (name of the file without extension where data should be saved.)
origin (grid origin (default = (0,0,0)))
spacing (grid spacing (default = (1,1,1)))
cellData (dictionary containing arrays with cell centered data.) – Keys should be the names of the data arrays. Arrays must have the same dimensions in all directions and must contain only scalar data.
nodeData (dictionary containing arrays with node centered data.) – Keys should be the names of the data arrays. Arrays must have same dimension in each direction and they should be equal to the dimensions of the cell data plus one and must contain only scalar data.
comments
NOTE: At least, cellData or pointData must be present to infer the dimensions of the image.
- pmmoto.io.evtk.hl.linesToVTK(path, x, y, z, cellData=None, pointData=None, comments=None)
Export line segments that joint 2 points and associated data.
- Parameters:
path (name of the file without extension where data should be saved.)
x (1D list-type object (list, tuple or numpy) with coordinates of the vertex of the lines. It is assumed that each line.) – is defined by two points, then the lenght of the arrays should be equal to 2 * number of lines.
y (1D list-type object (list, tuple or numpy) with coordinates of the vertex of the lines. It is assumed that each line.) – is defined by two points, then the lenght of the arrays should be equal to 2 * number of lines.
z (1D list-type object (list, tuple or numpy) with coordinates of the vertex of the lines. It is assumed that each line.) – is defined by two points, then the lenght of the arrays should be equal to 2 * number of lines.
cellData (dictionary with variables associated to each line.) – Keys should be the names of the variable stored in each array. All 1D list-type object (list, tuple or numpy) must have the same number of elements.
pointData (dictionary with variables associated to each vertex.) – Keys should be the names of the variable stored in each array. All 1D list-type object (list, tuple or numpy) must have the same number of elements.
comments (list of comment strings, which will be added to the header section of the file.)
- Return type:
Full path to saved file.
- pmmoto.io.evtk.hl.pointsToVTK(path, x, y, z, data=None, comments=None) None
Export points and associated data as an unstructured grid.
- Parameters:
path (name of the file without extension where data should be saved.)
x (1D list-type object (list, tuple or numpy) with coordinates of the points.)
y (1D list-type object (list, tuple or numpy) with coordinates of the points.)
z (1D list-type object (list, tuple or numpy) with coordinates of the points.)
data (dictionary with variables associated to each point.) – Keys should be the names of the variable stored in each array. All 1D list-type object (list, tuple or numpy) must have the same number of elements.
comments (list of comment strings, which will be added to the header section of the file.)
- Return type:
Full path to saved file.
- pmmoto.io.evtk.hl.pointsToVTKAsTIN(path, x, y, z, data=None, comments=None, ndim=2)
Export points and associated data as a triangula irregular grid. It builds a triangular grid that has the input points as nodes using the Delaunay triangulation function in Scipy, which requires a convex set of points (check the documentation for further details https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.Delaunay.html).
- Parameters:
path (name of the file without extension where data should be saved.)
x (1D list-type object (list, tuple or numpy) with coordinates of the points.)
y (1D list-type object (list, tuple or numpy) with coordinates of the points.)
z (1D list-type object (list, tuple or numpy) with coordinates of the points.)
data (dictionary with variables associated to each point.) – Keys should be the names of the variable stored in each array. All 1D list-type object (list, tuple or numpy) must have the same number of elements.
comments (list of comment strings, which will be added to the header section of the file.)
ndim (is the number of dimensions considered when calling Delaunay.) – If ndim = 2, then only coordinates x and y are passed. If ndim = 3, then x, y and z coordinates are passed.
- Return type:
Full path to saved file.
REQUIRES: Scipy > 1.2.
- pmmoto.io.evtk.hl.polyLinesToVTK(path, x, y, z, pointsPerLine, cellData=None, pointData=None, comments=None)
Export line segments that joint 2 points and associated data.
- Parameters:
path (name of the file without extension where data should be saved.)
x (1D list-type object (list, tuple or numpy) arrays with coordinates of the vertices of the lines. It is assumed that each line.) – has diffent number of points.
y (1D list-type object (list, tuple or numpy) arrays with coordinates of the vertices of the lines. It is assumed that each line.) – has diffent number of points.
z (1D list-type object (list, tuple or numpy) arrays with coordinates of the vertices of the lines. It is assumed that each line.) – has diffent number of points.
pointsPerLine (1D list-type object (list, tuple or numpy) array that defines the number of points associated to each line. Thus,) – the length of this array define the number of lines. It also implicitly defines the connectivity or topology of the set of lines. It is assumed that points that define a line are consecutive in the x, y and z arrays.
cellData (Dictionary with variables associated to each line.) – Keys should be the names of the variable stored in each array. All 1D list-type object (list, tuple or numpy) must have the same number of elements.
pointData (Dictionary with variables associated to each vertex.) – Keys should be the names of the variable stored in each array. 1D list-type object (list, tuple or numpy) must have the same number of elements.
comments (list of comment strings, which will be added to the header section of the file.)
- Return type:
Full path to saved file.
- pmmoto.io.evtk.hl.rectilinearToVTK(path, x, y, z, cellData=None, pointData=None, comments=None)
Writes data values as a rectilinear or rectangular grid.
- Parameters:
path (name of the file without extension where data should be saved.)
x (coordinates of the nodes of the grid as 1D arrays.) – The grid should be Cartesian, i.e. faces in all cells are orthogonal. Arrays size should be equal to the number of nodes of the grid in each direction.
y (coordinates of the nodes of the grid as 1D arrays.) – The grid should be Cartesian, i.e. faces in all cells are orthogonal. Arrays size should be equal to the number of nodes of the grid in each direction.
z (coordinates of the nodes of the grid as 1D arrays.) – The grid should be Cartesian, i.e. faces in all cells are orthogonal. Arrays size should be equal to the number of nodes of the grid in each direction.
cellData (dictionary containing arrays with cell centered data.) – Keys should be the names of the data arrays. Arrays must have the same dimensions in all directions and must contain only scalar data.
pointData (dictionary containing arrays with node centered data.) – Keys should be the names of the data arrays. Arrays must have same dimension in each direction and they should be equal to the dimensions of the cell data plus one and must contain only scalar data.
comments (list of comment strings, which will be added to the header section of the file.)
- Return type:
Full path to saved file.
- pmmoto.io.evtk.hl.structuredToVTK(path, x, y, z, cellData=None, pointData=None, comments=None)
Writes data values as a rectilinear or rectangular grid.
- Parameters:
path (name of the file without extension where data should be saved.)
x (coordinates of the nodes of the grid as 3D arrays.) – The grid should be structured, i.e. all cells should have the same number of neighbors. Arrays size in each dimension should be equal to the number of nodes of the grid in each direction.
y (coordinates of the nodes of the grid as 3D arrays.) – The grid should be structured, i.e. all cells should have the same number of neighbors. Arrays size in each dimension should be equal to the number of nodes of the grid in each direction.
z (coordinates of the nodes of the grid as 3D arrays.) – The grid should be structured, i.e. all cells should have the same number of neighbors. Arrays size in each dimension should be equal to the number of nodes of the grid in each direction.
cellData (dictionary containing arrays with cell centered data.) – Keys should be the names of the data arrays. Arrays must have the same dimensions in all directions and must contain only scalar data.
pointData (dictionary containing arrays with node centered data.) – Keys should be the names of the data arrays. Arrays must have same dimension in each direction and they should be equal to the dimensions of the cell data plus one and must contain only scalar data.
comments (list of comment strings, which will be added to the header section of the file.)
- Return type:
Full path to saved file.
- pmmoto.io.evtk.hl.unstructuredGridToVTK(path, x, y, z, connectivity, offsets, cell_types, cellData=None, pointData=None, comments=None)
Export unstructured grid and associated data.
- Parameters:
path (name of the file without extension where data should be saved.)
x (1D list-type object (list, tuple or numpy) with coordinates of the vertices of cells. It is assumed that each element) – has diffent number of vertices.
y (1D list-type object (list, tuple or numpy) with coordinates of the vertices of cells. It is assumed that each element) – has diffent number of vertices.
z (1D list-type object (list, tuple or numpy) with coordinates of the vertices of cells. It is assumed that each element) – has diffent number of vertices.
connectivity (1D list-type object (list, tuple or numpy) that defines the vertices associated to each element.) – Together with offset define the connectivity or topology of the grid. It is assumed that vertices in an element are listed consecutively.
offsets (1D list-type object (list, tuple or numpy) with the index of the last vertex of each element in the connectivity array.) – It should have length nelem, where nelem is the number of cells or elements in the grid.
cell_types (1D list-type object (list, tuple or numpy) with an integer that defines the cell type of each element in the grid.) – It should have size nelem. This should be assigned from evtk.vtk.VtkXXXX.tid, where XXXX represent the type of cell. Please check the VTK file format specification for allowed cell types.
cellData (Dictionary with variables associated to each line.) – Keys should be the names of the variable stored in each array. All 1D list-type object (list, tuple or numpy) must have the same number of elements.
pointData (Dictionary with variables associated to each vertex.) – Keys should be the names of the variable stored in each array. All 1D list-type object (list, tuple or numpy) must have the same number of elements.
comments (list of comment strings, which will be added to the header section of the file.)
- Return type:
Full path to saved file.
- pmmoto.io.evtk.hl.writeParallelPoints(path, coordsData, starts, ends, sources, spacing, origin=(0, 0, 0), ghostlevel=0, lower_extent=(0, 0, 0), cellData=None, pointData=None)
Writes a parallel vtk file from grid-like data: VTKStructuredGrid or VTKRectilinearGrid
- Parameters:
path (str) – name of the file without extension.
coordsData (tuple) – 2-tuple (shape, dtype) where shape is the shape of the coordinates of the full mesh and dtype is the dtype of the coordinates.
starts (list) – list of 3-tuple representing where each source file starts in each dimension
source (list) – list of the relative paths of the source files where the actual data is found
ghostlevel (int, optional) – Number of ghost-levels by which the extents in the individual source files overlap.
pointData (dict) – dictionnary containing the information about the arrays containing node centered data. Keys shoud be the names of the arrays. Values are (dtype, number of components)
cellData – dictionnary containing the information about the arrays containing cell centered data. Keys shoud be the names of the arrays. Values are (dtype, number of components)
- pmmoto.io.evtk.hl.writeParallelVTKGrid(path, coordsData, starts, ends, sources, spacing, origin=(0, 0, 0), ghostlevel=0, lower_extent=(0, 0, 0), cellData=None, pointData=None) None
Writes a parallel vtk file from grid-like data: VTKStructuredGrid or VTKRectilinearGrid
- Parameters:
path (str) – name of the file without extension.
coordsData (tuple) – 2-tuple (shape, dtype) where shape is the shape of the coordinates of the full mesh and dtype is the dtype of the coordinates.
starts (list) – list of 3-tuple representing where each source file starts in each dimension
source (list) – list of the relative paths of the source files where the actual data is found
ghostlevel (int, optional) – Number of ghost-levels by which the extents in the individual source files overlap.
pointData (dict) – dictionnary containing the information about the arrays containing node centered data. Keys shoud be the names of the arrays. Values are (dtype, number of components)
cellData – dictionnary containing the information about the arrays containing cell centered data. Keys shoud be the names of the arrays. Values are (dtype, number of components)
pmmoto.io.evtk.vtk module
- class pmmoto.io.evtk.vtk.VtkCellType(tid, name)
Bases:
object
- class pmmoto.io.evtk.vtk.VtkDataType(size, name)
Bases:
object
- class pmmoto.io.evtk.vtk.VtkFile(filepath, ftype, largeFile=False)
Bases:
objectPARAMETERS filepath: filename without extension. ftype: file type, e.g. VtkImageData, etc. largeFile: If size of the stored data cannot be represented by a UInt32.
- addComments(comments)
Insert strings stored in comments list as comments into the xml header section of the file. This method does not make any check for forbidden or special characters in XML comments. This method should be called right after creating the file to avoid including comments in the wrong place within the header. BE AWARE!!!
- addData(name, data)
Adds array description to xml header section.
- Parameters:
name (data array name.)
data (one numpy array or a tuple with 3 numpy arrays. If a tuple, the individual) – arrays must represent the components of a vector field. All arrays must be one dimensional or three-dimensional.
- addHeader(name, dtype, nelem, ncomp)
Adds data array description to xml header section.
- Parameters:
name (data array name.)
dtype (string describing type of the data.) – Format is the same as used by numpy, e.g. ‘float64’.
nelem (number of elements in the array.)
ncomp (number of components, 1 (=scalar) and 3 (=vector).)
- Return type:
This VtkFile to allow chained calls.
- NOTE: This is a low level function. Use addData if you want
to add a numpy array.
- appendData(data)
Append data to binary section. This function writes the header section and the data to the binary file.
- Parameters:
data (one numpy array or a tuple with 3 numpy arrays. If a tuple, the individual) – arrays must represent the components of a vector field. All arrays must be one dimensional or three-dimensional. The order of the arrays must coincide with the numbering scheme of the grid.
- Return type:
This VtkFile to allow chained calls
TODO: Extend this function to accept contiguous C order arrays.
- appendHeader(dtype, nelem, ncomp)
This function only writes the size of the data block that will be appended. The data itself must be written immediately after calling this function.
- Parameters:
dtype (string with data type representation (same as numpy). For example, 'float64')
nelem (number of elements.)
ncomp (number of components, 1 (=scalar) or 3 (=vector).)
- closeAppendedData()
Closes binary section.
It is not necessary to explicitly call this function from an external library.
- closeData(nodeType)
Close data section.
- Parameters:
nodeType (Point or Cell.)
- Return type:
this VtkFile to allow chained calls.
- closeElement(tagName)
- closeGrid()
Closes grid element.
- Returns:
this VtkFile to allow chained calls.
- closePiece()
- getFileName()
Returns absolute path to this file.
- openAppendedData()
Opens binary section.
It is not necessary to explicitly call this function from an external library.
- openData(nodeType, scalars=None, vectors=None, normals=None, tensors=None, tcoords=None)
Open data section.
- Parameters:
nodeType (Point or Cell.)
scalars (default data array name for scalar data.)
vectors (default data array name for vector data.)
normals (default data array name for normals data.)
tensors (default data array name for tensors data.)
tcoords (dafault data array name for tcoords data.)
- Return type:
this VtkFile to allow chained calls.
- openElement(tagName)
Useful to add elements such as: Coordinates, Points, Verts, etc.
- openGrid(start=None, end=None, origin=None, spacing=None)
Open grid section.
- Parameters:
start (array or list of start indexes. Required for Structured, Rectilinear and ImageData grids.)
end (array or list of end indexes. Required for Structured, Rectilinear and ImageData grids.)
origin (3D array or list with grid origin. Only required for ImageData grids.)
spacing (3D array or list with grid spacing. Only required for ImageData grids.)
- Return type:
this VtkFile to allow chained calls.
- openPiece(start=None, end=None, npoints=None, ncells=None, nverts=None, nlines=None, nstrips=None, npolys=None)
Open piece section.
- Parameters:
together. (Next two parameters must be given)
start (array or list with start indexes in each direction.)
end (array or list with end indexes in each direction.)
npoints (number of points in piece (int).)
ncells (number of cells in piece (int). If present,) – npoints must also be given.
npoints. (All the following parameters must be given together with)
values. (They should all be integer)
nverts (number of vertices.)
nlines (number of lines.)
nstrips (number of strips.)
npolys (number of .)
- Return type:
this VtkFile to allow chained calls.
- save()
Closes file
- class pmmoto.io.evtk.vtk.VtkFileType(name, ext)
Bases:
object
- class pmmoto.io.evtk.vtk.VtkGroup(filepath)
Bases:
objectCreates a VtkGroup file that is stored in filepath.
- Parameters:
filepath (filename without extension.)
- addFile(filepath, sim_time, group='', part='0')
Adds file to this VTK group.
- Parameters:
filepath (full path to VTK file.)
sim_time (simulated time.)
group (This attribute is not required; it is only for informational purposes.)
part (It is an integer value greater than or equal to 0.)
See: http://www.paraview.org/Wiki/ParaView/Data_formats#PVD_File_Format for details.
- save()
Closes this VtkGroup.
- class pmmoto.io.evtk.vtk.VtkParallelFile(filepath, ftype)
Bases:
objectClass for a VTK parallel file.
- Parameters:
filepath (str) – filename without extension
ftype (VtkParallelFileType)
- addHeader(name, dtype, ncomp)
Add data array description to xml header section.
- Parameters:
name (str) – data array name.
dtype (str) – data type.
ncomp (int) – number of components, 1 (=scalar) and 3 (=vector).
- Returns:
This VtkFile to allow chained calls.
- Return type:
Notes
This is a low level function. Use addData if you want to add a numpy array.
- addPiece(start=None, end=None, source=None)
Add piece section with extent and source.
- Parameters:
start (array-like, optional) – array or list with start indexes in each direction. Must be given with end.
end (array-like, optional) – array or list with end indexes in each direction. Must be given with start.
source (str) – Source of this piece
- Returns:
This VtkFile to allow chained calls.
- Return type:
- closeData(nodeType)
Close data section.
- Parameters:
nodeType (str) – “Point”, “Cell” or “Field”.
- Returns:
This VtkFile to allow chained calls.
- Return type:
- closeElement(tagName)
- getFileName()
Return absolute path to this file.
- openData(nodeType, scalars=None, vectors=None, normals=None, tensors=None, tcoords=None)
Open data section.
- Parameters:
nodeType (str) – Either “Point”, “Cell” or “Field”.
scalars (str, optional) – default data array name for scalar data.
vectors (str, optional) – default data array name for vector data.
normals (str, optional) – default data array name for normals data.
tensors (str, optional) – default data array name for tensors data.
tcoords (str, optional) – default data array name for tcoords data.
- Returns:
This VtkFile to allow chained calls.
- Return type:
- openElement(tagName)
Open an element. Useful to add elements such as: Coordinates, Points, Verts, etc.
- openGrid(start=None, end=None, origin=None, spacing=None, ghostlevel=0)
Open grid section.
- Parameters:
start (array-like, optional) – array or list of start indexes. Required for Structured, Rectilinear and ImageData grids. The default is None.
end (array-like, optional) – array or list of end indexes. Required for Structured, Rectilinear and ImageData grids. The default is None.
origin (array-like, optional) – 3D array or list with grid origin. Only required for ImageData grids. The default is None.
spacing (array-like, optional) – 3D array or list with grid spacing. Only required for ImageData grids. The default is None.
ghostlevel (int) – Number of ghost-levels by which the extents in the individual pieces overlap.
- Returns:
This VtkFile to allow chained calls.
- Return type:
- save()
Close file.
- class pmmoto.io.evtk.vtk.VtkParallelFileType(vtkftype)
Bases:
objectA wrapper class for parallel vtk file types.
- Parameters:
vtkftype (VtkFileType) – Vtk file type
pmmoto.io.evtk.xml module
- class pmmoto.io.evtk.xml.XmlWriter(filepath, addDeclaration=True)
Bases:
object- addAttributes(**kwargs)
- addComment(sstr)
Adds (open and close) a single comment contained in string sstr. TODO: Add a smart check for the position of the comments in the file. For now,
we rely on the caller.
- addDeclaration()
- addText(text)
- close()
- closeElement(tag=None)
- openElement(tag)