Model
pyevtk_tools
- geos.pygeos_tools.model.pyevtk_tools.cGlobalIds(Nx, Ny, Nz, dx, dy, dz, xmin, ymin, zmin, glNx, glNy, glNz, xmin0, ymin0, zmin0)
Compute global ids for cells
- Parameters:
Nx (int) – number of points on the x axis for the block
Ny (int) – number of points on the y axis for the block
Nz (int) – number of points on the z axis for the block
dx (float) – x-axis spacing
dy (float) – y-axis spacing
dz (float) – z-axis spacing
xmin (float) – minimum x value for the block
ymin (float) – minimum y value for the block
zmin (float) – minimum z value for the block
glNx (int) – global number of points on the x axis
glNy (int) – global number of points on the y axis
glNz (int) – global number of points on the z axis
xmin0 (float) – minimum x value for the _0 file
ymin0 (float) – minimum y value for the _0 file
zmin0 (float) – minimum z value for the _0 file
- Returns:
cell global ids for the block
- Return type:
cIds (numpy.array)
- geos.pygeos_tools.model.pyevtk_tools.connectivity(Nx, Ny, Nz)
Compute connectivity and offsets
- Parameters:
Nx (int) – number of points on the x axis
Ny (int) – number of points on the y axis
Nz (int) – number of points on the z axis
- Returns:
2 arrays of connectivity and offsets numCells (int): number of cells
- Return type:
conn, offset (2 np.arrays)
- geos.pygeos_tools.model.pyevtk_tools.pGlobalIds(Nx, Ny, Nz, dx, dy, dz, xmin, ymin, zmin, glNx, glNy, glNz, xmin0, ymin0, zmin0)
Compute global ids for points
- Parameters:
Nx (int) – number of points on the x axis for the block
Ny (int) – number of points on the y axis for the block
Nz (int) – number of points on the z axis for the block
dx (float) – x-axis spacing
dy (float) – y-axis spacing
dz (float) – z-axis spacing
xmin (float) – minimum x value for the block
ymin (float) – minimum y value for the block
zmin (float) – minimum z value for the block
glNx (int) – global number of points on the x axis
glNy (int) – global number of points on the y axis
glNz (int) – global number of points on the z axis
xmin0 (float) – minimum x value for the _0 file
ymin0 (float) – minimum y value for the _0 file
zmin0 (float) – minimum z value for the _0 file
- Returns:
point global ids for the block
- Return type:
pIds (numpy.array)
- geos.pygeos_tools.model.pyevtk_tools.structuredToVTK(path, x, y, z, cellData=None, pointData=None, start=(0, 0, 0))[source]
create the .vts file Modified from : evtk.hl, Copyright (c) 2021 Paulo A. Herrera
- Parameters:
path (str) – path and name of the .vts file (without the extension)
x (3 np.array) – arrays of point coordinates along the x, y, and z axes
y (3 np.array) – arrays of point coordinates along the x, y, and z axes
z (3 np.array) – arrays of point coordinates along the x, y, and z axes
pointData (dict, optional) – 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. Default to None.
cellData (dict, optional) – 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. Default to None.
- Returns:
Full path to saved file.
- Return type:
str
- geos.pygeos_tools.model.pyevtk_tools.unstructuredGridToVTK(path, x, y, z, connectivity, offsets, cell_types, pointData=None, cellData=None)[source]
Modified from pyevtk.hl, Copyright 2010 - 2016 Paulo A. Herrera. All rights reserved.
Export unstructured grid and associated data.
- Parameters:
path (str) – name of the file without extension where data should be saved.
x (array-like) – x coordinates of the vertices.
y (array-like) – y coordinates of the vertices.
z (array-like) – z coordinates of the vertices.
connectivity (array-like) – 1D array 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 (array-like) – 1D array 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 (TYPE) – 1D array 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 (dict, optional) – dictionary with variables associated to each cell. Keys should be the names of the variable stored in each array. All arrays must have the same number of elements.
pointData (dict, optional) – dictionary with variables associated to each vertex. Keys should be the names of the variable stored in each array. All arrays must have the same number of elements.
- Returns:
Full path to saved file.
- Return type:
str
- geos.pygeos_tools.model.pyevtk_tools.writeParallelVTKGrid(path, sources, coordsData, starts=None, ends=None, ghostlevel=0, cellData=None, pointData=None)[source]
Modified from pyevtk.hl, Copyright 2010 - 2016 Paulo A. Herrera. All rights reserved.
Writes a parallel vtk file from grid-like data: VTKStructuredGrid or VTKUnstructuredGrid
- 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
sources (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)
- geos.pygeos_tools.model.pyevtk_tools.x_y_z(nx, ny, nz, dx, dy, dz, xmin, ymin, zmin)
Compute points coordinates (vertices) for .vts file
- Parameters:
nx (int) – number of points on the x axis
ny (int) – number of points on the y axis
nz (int) – number of points on the z axis
dx (float) – x-axis spacing
dy (float) – y-axis spacing
dz (float) – z-axis spacing
xmin (float) – minimum x value
ymin (float) – minimum y value
zmin (float) – minimum z value
- Returns:
arrays of point coordinates along the x, y, and z axes
- Return type:
x,y,z (3 np.array)
- geos.pygeos_tools.model.pyevtk_tools.xyz(Nx, Ny, Nz, dx, dy, dz, xmin, ymin, zmin)
Compute points coordinates (vertices) for .vtu file
- Parameters:
Nx (int) – number of points on the x axis
Ny (int) – number of points on the y axis
Nz (int) – number of points on the z axis
dx (float) – x-axis spacing
dy (float) – y-axis spacing
dz (float) – z-axis spacing
xmin (float) – minimum x value
ymin (float) – minimum y value
zmin (float) – minimum z value
- Returns:
arrays of point coordinates along the x, y, and z axes
- Return type:
x,y,z (3 np.array)
SepModel
- class geos.pygeos_tools.model.SepModel.SEPBin(binfile=None, header=None, data=None, **kwargs)[source]
Bases:
object
Class defining a SEP binary file
- dataFormat
Format type of the binary data
- Type:
str
- bin
SEP binary file
- Type:
str
- head
Associated SEP header file
- Type:
str
- n
Number of elements in each dimension
- Type:
tuple of int
- dataType
Type of data : cells or points
- Type:
str
- data
Model values
- Type:
numpy array
- Parameters:
binfile (str) – Binary filename
header (SEPHeader) – Header associated to this binary SEP file
data (numpy array) – Model values
kwargs – datatype : “cells” or “point”. Default is None
- getModel(datatype=None)[source]
Get the cell or point data from the binary file
- Parameters:
datatype (str) – Type of requested data: ‘cells’ or ‘points’
- Return type:
numpy array
- read(transp=False, **kwargs)[source]
Read data from the binary file. If header provided, can reshape the data
- Parameters:
transp (bool) – Whether or not to reshape the data. Default is False is no header provided, True otherwise.
kwargs – data_format : data format (little/big endian)
- class geos.pygeos_tools.model.SepModel.SEPBlock(sepmodel, bfile, nijk, nb)[source]
Bases:
SEPModel
SEP block Inheritance from SEPModel
- gModel
Global model filename
- Type:
str
- nijk
Block number identification
- Type:
array-like of int
- nblocks
Total number of blocks in each dimension
- Type:
array-like of int
- imin
Index min of the block in the whole dataset
- Type:
tuple of int
- imax
Index max of the block in the whole dataset
- Type:
tuple of int
- n
Number of elements in the block for each dimension
- Type:
tuple of int
- bmin
Origin of the block
- Type:
tuple of float
- gln
Global number of elements for each dimension
- Type:
tuple of int
- glmin
Global origin of the model
- Type:
tuple of float
- Parameters:
sepmodel (SEPModel) – Global model
bfile (str) – Block filename
nijk (array-like of int) – Block number identification
nb (array-like of int) – Total number of blocks in each dimension
- class geos.pygeos_tools.model.SepModel.SEPHeader(header)[source]
Bases:
object
Class defining a SEP Header file
- head
Header filename
- Type:
str
- bin
Binary filename
- Type:
str
- n1, n2, n3
Number of elements in each dimension
- Type:
int
- o1, o2, o3
Position of the origin
- Type:
float
- d1, d2, d3
Step size for each dimension
- Type:
float
- label1, label2, label3
Label for each dimension
- Type:
str
- data_format
Format type of the binary data
- Type:
str
- esize
Size of the elements in octet
- Type:
int
- order
order
- Type:
int
- Parameters:
header (str or dict) – SEP header. Header filename if str, dict containing all the SEP header informations if dict,
- SEPParser(argsList=None)[source]
SEP Header parser
- Parameters:
argsList (list) – List of SEP options
- Return type:
Namespace, extra_args
- convertToSEPDict(genericDict=None, cleanNone=False)[source]
Returns a SEP Header under dictionary format
- Parameters:
genericDict (dict) – Dictionary to be converted to SEP Header dict. Default is self
cleanNone (bool) – Remove None entries from dict or not. Default is False
- Return type:
dict
- copy(headfile=None)[source]
Copy this SEPHeader
- Parameters:
headfile (str (optional)) – New filename of the header. If none, the “head” entry is unaltered
- Return type:
- getNumberOfElements()[source]
Return the number of elements for each dimension
- Return type:
tuple of int
- parseListToSEPDict(headerList)[source]
Returns a dict from parsed SEP header list
- Parameters:
headerList (list) – List of SEP options
- Return type:
dict
- parseStringToSEPDict(headerStr)[source]
Returns a dict containing the parsed options from a SEP header string
- Parameters:
headerStr (str) – string read from a SEP header file
- Return type:
dict
- setLabels(labels)[source]
Set new labels for each dimension
- Parameters:
labels (3d str) – New labels
- setNumberOfElements(n)[source]
Update the number of elements for each dimension
- Parameters:
tuple (3d array or) – New number of elements for each dimension
- class geos.pygeos_tools.model.SepModel.SEPModel(header=None, data=None, name=None)[source]
Bases:
object
Define a SEP model
- Parameters:
header (str or dict) – SEP Header. Header filename if str, dict containing SEP header informations if dict
- copy(header=None)[source]
Copy the SEP model
- Parameters:
header (str) – New header filename
- Return type:
- createAllBlocks(nb, bext='', verbose=False, comm=None)[source]
Partition the original SEP model into blocks and export
- Parameters:
nb (3d array-like) – Number of blocks for each dimension
bext (str) – Suffix to form block filenames
verbose (bool) – Print block information or not
comm (MPI communicator) – MPI communicator
- export(filename=None, directory=None)[source]
Write header and binary in files
- Parameters:
filename (str) – New filename for the export
- getBlock(nijk, nb, bheadfile, r=None, verbose=False)[source]
Return a block partition of the original SEP model
- Parameters:
nijk (3d array-like) – Blocks number ID for each dimension
nb (3d array-like) – Total number of blocks for each dimension
bheadfile (str) – Filename of the block
r (int or str) – Block linear numbering (out of the total number of blocks)
verbose (bool) – Print block information or not
- Return type:
- getGlobalNumberOfElements()[source]
Return the global number of elements for each dimension
- Return type:
array-like
- getMaxValue()[source]
Return the maximal value of the model
- Returns:
maxValue – Model maximal value
- Return type:
float
- getMinAndMaxValues()[source]
Return the minimal and maximal values of the model
- Returns:
minValue (float) – Model minimal value
maxValue (float) – Model maximal value
- getMinValue()[source]
Return the minimal value of the model
- Returns:
minValue – Model minimal value
- Return type:
float
- getModel(datatype=None)[source]
Return the cells or points model
- Parameters:
datatype (str) – “cells” or “points” type model
- Returns
numpy array
- getNumberOfElements()[source]
Return the number of elements for each dimension
- Return type:
array-like
VtkModel
- class geos.pygeos_tools.model.VtkModel.PVTKModel(pvtkfile, vtkfiles=None)[source]
Bases:
object
Parallel VTK model
- filename
Filename of the pvtk header
- Type:
str
- rootname
Root of the filename of all files from the PVTK model
- Type:
str
- pvtktype
VTK type (‘pvtu’ or ‘pvts’)
- Type:
str
- vtkfiles
Contains all sources filenames Block number ID out of the total number of blocks (key) associated to the corresponding VTK filename
- Type:
dict
- vtkmodels
Contains all sources VTKModels Block number ID out of the total number of blocks (key) associated to corresponding VTKModel (VTUModel or VTSModel)
- Type:
dict
- cellInfo
Contains cell data information Cell array names (key) associated to data type and number of components
- Type:
dict
- pointInfo
Contains point data information Point array names (key) associated to data type and number of components
- Type:
dict
- starts
Contains the blocks min indices Block number IDs for each dimension (key) associated to min indices
- Type:
dict
- ends
Contains the blocks max indices Block number IDs for each dimension (key) associated to max indices
- Type:
dict
- nblocks
Number of blocks for each dimension
- Type:
tuple of int
- nbltot
Total number of blocks
- Type:
int
- n
Whole extent of the model
- Type:
tuple of int
- Parameters:
pvtkfile (str) – Filename of the PVTK model
vtkfiles (array-like of str (optional)) – List of filenames of VTK files constituting the PVTK model
- addBlockInfo(block, bijk=None, bn=None)[source]
Add information about a specific block (cell and point informations, min and max indices)
- Parameters:
block (VTKModel) – VTKModel of a specific block from the global PVTK model
bijk (tuple of int (optional)) – Block number Ids for each dimension Required if bn is not given
bn (int (optional)) – Block number Id out of the total number of blocks Required if bijk is not given
- addBlockModel(block, bn)[source]
Add a VTK model source to the PVTK model
- Parameters:
block (VTKModel) – VTKModel of a specific block from the global PVTK model
bn (int) – Block number Id out of the total number of blocks
- addCellInfo(cinfo=None)[source]
Add cell data name and type to the cell information attribute
- Parameters:
cinfo (dict, optional) – Cell array name as key, cell datatype and number of component as value
- addPointInfo(pinfo=None)[source]
Add point data name and type to the point information attribute
- Parameters:
pinfo (dict, optional) – Point array name as key, data type and number of components as value
- addSourceInfo(bijk, bfile, cinfo, pinfo, start=None, end=None)[source]
Add block cell and point infos (arrays datatype), start and end indices of the blocks
- Parameters:
bijk (array-like of int tuple) – Block number Ids
bfile (dict) – Format : “f{blockId}”: filename with blockId the number Id out of the total number of blocks
cinfo (dict) – Cell array names, datatype and number of components
pinfo (dict) – Point array names, datatype and number of components
starts (dict, optional) – Indices min associated to the blocks Required for the export in PVTS format
ends (dict, optional) – Indices max associated to the blocks Required for the export in PVTS format
- export(gids=False, writeBlocks=True)[source]
Write the VTK files as well as the PVTK file
- Parameters:
gids (bool, optional) – Whether or not to add the global Ids to the files
writeBlocks (bool, optional) – If true, all blocks are exported. If False, only the PVTK header is written
- getAllBlocksIndices()[source]
Return the list of all block Ids (ni, nj, nk)
- Return type:
list of tuple of int
- getBlocksEnds()[source]
Return the blocks maximal indices
- Returns:
Block ID associated to max indices tuple
- Return type:
dict
- getBlocksStarts()[source]
Return the blocks minimal indices
- Returns:
Block ID associated to min indices tuple
- Return type:
dict
- getCellInfo()[source]
Return the cell data array names, types and number of components
- Returns:
Cell data array name associated to a tuple of the type and number of components
- Return type:
dict
- getData()[source]
Read the data model
- Return type:
vtkStructuredGrid if self.pvtktype is “pvts” or vtkUnstructuredGrid if “pvtu”
- getPointInfo()[source]
Return the point data array names, types and number of components
- Returns:
Point data array name associated to a tuple of the type and number of components
- Return type:
dict
- getSourceFilesFromHeader()[source]
Return the source files from the PVTK file header
- Return type:
list of str
- getSources()[source]
Return the files of the blocks constituting the PVTK
- Returns:
Block Id and associated rootnames
- Return type:
dict
- setNumberOfBlocks(nblocks)[source]
Set the number of blocks for each dimension and the total number of blocks of the model
- Parameters:
nblocks (array-like of int) – Number of blocks for each dimension
- class geos.pygeos_tools.model.VtkModel.VTKModel(vtkfile, cellData=None, pointData=None)[source]
Bases:
object
Define a VTK model
- filename
Name of the VTK file with extension
- Type:
str
- rootname
Root of the filename
- Type:
str
- vtktype
Type of VTK format
- Type:
str
- cellData
Contains all cell data arrays
- Type:
dict
- pointData
Contains all point data arrays
- Type:
dict
- cgids
Cell global Ids
- Type:
list of int
- pgids
Point global Ids
- Type:
list of int
- bmin
Bound min for each dimension
- Type:
tuple of float
- glmin
Bound min for each dimension for the global model
- Type:
tuple of float
- n
Number of elements for each dimension
- Type:
tuple of int
- gln
Number of elements for each dimension for the global model
- Type:
tuple of int
- d
Step size for each dimension
- Type:
tuple of float
- vertices
Model points coordinates
- Type:
tuple of arrays
- ctype
Cells datatype
- Type:
array-like
- Parameters:
vtkfile (str) – Filename
cellData (dict) – Dictionary containing the cell data
pointData (dict) – Dictionary containing the point data
- addCellData(ckey, cellData)[source]
Append or update cell data
- Parameters:
ckey (str) – Cell data name
cellData (array-like) – Cell data array
- addPointData(pkey, pointData)[source]
Append or update point data
- Parameters:
pkey (str) – Point data name
pointData (array-like) – Point data array
- getPointGlobalIds()[source]
Return the value of the points global Ids
- Return type:
array-like of int
- getReader()[source]
Returns the vtkXMLReader corresponding to the VTK format
- Returns:
Reader for this VTK format
- Return type:
vtkXMLReader
- setCellGlobalIds()[source]
Compute the global ids of the cells
- Parameters:
n (array-like of int) – Number of elements in each dimension
d (array-like of float) – Step sizes for each dimension
bmin (array-like of float) – Minimal bound for each dimension
gln (array-like of int) – Global number of elements for each dimension
glmin (array-like of float) – Global minimal bound for each dimension
- setCellsType(ncells, ctype=12)[source]
Set cell type of all the cells
- Parameters:
ncells (int) – Number of cells
ctype (int) – Type of the cells 12 for vtk.VtkHexahedron.tid
- setGlobalNumberOfElements(gln)[source]
Define the number of elements of the global model
- Parameters:
n (array-like of int) – Number of points
- setGlobalOrigin(glmin)[source]
Define the origin of the global model
- Parameters:
glmin (array-like of float) – Global origin of the model
- setNumberOfElements(n)[source]
Define the number of points, cells, and total number of cells
- Parameters:
n (array-like of int) – Number of points
- setOrigin(bmin)[source]
Define the origin of the model
- Parameters:
bmin (array-like of float) – Origin of the model
- setPointGlobalIds()[source]
Compute the global ids of the points
- Parameters:
n (array-like of int) – Number of elements in each dimension
d (array-like of float) – Step sizes for each dimension
bmin (array-like of float) – Minimal bound for each dimension
gln (array-like of int) – Global number of elements for each dimension
glmin (array-like of float) – Global minimal bound for each dimension
- class geos.pygeos_tools.model.VtkModel.VTSModel(vtkfile, cellData=None, pointData=None)[source]
Bases:
VTKModel
Define a structured grid model Inheritance from VTKModel
- filename
Name of the VTK file
- Type:
str
- rootname
Root of the filename
- Type:
str
- vtktype
Type of VTK format (structured grid = “vts”)
- Type:
str
- cellData
Contains all cell data arrays
- Type:
dict
- pointData
Contains all point data arrays
- Type:
dict
- reader
VTK file reader
- Type:
vtkXMLUnStructuredGridReader
- cgids
Cell global Ids
- Type:
list of int
- pgids
Point global Ids
- Type:
list of int
- bmin
Bound min for each dimension
- Type:
tuple of float
- glmin
Bound min for each dimension for the global model
- Type:
tuple of float
- n
Number of elements for each dimension
- Type:
tuple of int
- gln
Number of elements for each dimension for the global model
- Type:
tuple of int
- d
Step size for each dimension
- Type:
tuple of float
- vertices
Model points coordinates
- Type:
tuple of arrays
- Parameters:
vtkfile (str) – Filename
cellData (dict) – Contains all cell data arrays
pointData (dict) – Contains all point data arrays
- export(gids=False)[source]
Write the .vts file with celldata and pointdata defined in the class
- Parameters:
vertices (array-like) – Coordinates of the points along each dimension
pgids (array-like) – Point global Ids
cgids (array-like) – Cell global Ids
- setVertices()[source]
Compute point coordinates (vertices) for a vts format
- Parameters:
n (array-like of int) – Number of elements in each dimension
d (array-like of float) – Step sizes for each dimension
bmin (array-like of float) – Minimal bound for each dimension
- Returns:
Arrays of point coordinates along each dimension
- Return type:
3d array-like
- class geos.pygeos_tools.model.VtkModel.VTUModel(vtkfile, cellData=None, pointData=None)[source]
Bases:
VTKModel
Define a structured grid model Inheritance from VTKModel
- filename
Name of the VTK file
- Type:
str
- rootname
Root of the filename
- Type:
str
- vtktype
Type of VTK format (unstructured grid = “vtu”)
- Type:
str
- cellData
Contains all cell data arrays
- Type:
dict
- pointData
Contains all point data arrays
- Type:
dict
- reader
VTK file reader
- Type:
vtkXMLUnStructuredGridReader
- cgids
Cell global Ids
- Type:
list of int
- pgids
Point global Ids
- Type:
list of int
- bmin
Bound min for each dimension
- Type:
tuple of float
- glmin
Bound min for each dimension for the global model
- Type:
tuple of float
- n
Number of elements for each dimension
- Type:
tuple of int
- gln
Number of elements for each dimension for the global model
- Type:
tuple of int
- d
Step size for each dimension
- Type:
tuple of float
- vertices
Model points coordinates
- Type:
tuple of arrays
- ctype
Cells datatype
- Type:
array-like
- connectivity
Connectivities
- Type:
array-like
- offsets
Cells offsets
- Type:
array-like
- Parameters:
vtkfile (str) – Filename
cellData (dict (optional)) – Contains all cell data arrays
pointData (dict (optional)) – Contains all point data arrays
- export(gids=False)[source]
Write the .vtu file with celldata and pointdata defined in the class
- Parameters:
vertices (array-like) – Coordinates of the points along each dimension
connectivity (array-like) – Cells point connectivity
offsets (array-like) – Offset into the connectivity of the cells
pgids (array-like) – Point global Ids
cgids (array-like) – Cell global Ids