flopy.export.vtk module

The vtk module provides functionality for exporting model inputs and outputs to VTK.

class Pvd[source]

Bases: object

Simple class to build a Paraview Data File (PVD)

add_timevalue(file, timevalue)[source]

Method to add a Dataset record to the pvd file

Parameters:
  • file (os.PathLike or str) – vtu file name

  • timevalue (float) – time step value in model time

write(f)[source]

Method to write a pvd file from the PVD object.

Parameters:

f (os.PathLike or str) – PVD file name

class Vtk(model=None, modelgrid=None, vertical_exageration=1, binary=True, xml=False, pvd=False, shared_points=False, smooth=False, point_scalars=False)[source]

Bases: object

Class that builds VTK objects and exports models to VTK files

Parameters:
  • model (flopy.ModelInterface object) – any flopy model object, example flopy.modflow.Modflow() object

  • modelgrid (flopy.discretization.Grid object) – any flopy modelgrid object, example. VertexGrid

  • vertical_exageration (float) – floating point value to scale vertical exaggeration of the vtk points default is 1.

  • binary (bool) – flag that indicates if Vtk will write a binary or text file. Binary is preferred as paraview has a bug (8/4/2021) where is cannot represent NaN values from ASCII (non xml) files. In this case no-data values are set to 1e+30.

  • xml (bool) – flag to write xml based VTK files

  • pvd (bool) – boolean flag to write a paraview pvd file for transient data. This file maps vtk files to a model time.

  • shared_points (bool) – boolean flag to share points in grid polyhedron construction. Default is False, as paraview has a bug (8/4/2021) where some polyhedrons will not properly close when using shared points. If shared_points is True file size will be slightly smaller.

  • smooth (bool) – boolean flag to interpolate vertex elevations based on shared cell elevations. Default is False.

  • point_scalars (bool) – boolean flag to write interpolated data at each point based “shared vertices”.

add_array(array, name, masked_values=None, dtype=None)[source]

Method to set an array to the vtk grid

Parameters:
  • array (np.ndarray, list) – list of array values to set to the vtk_array

  • name (str) – array name for vtk

  • masked_values (list, None) – list of values to set equal to nan

  • dtype (vtk datatype object) – method to supply and force a vtk datatype

add_cell_budget(cbc, text=None, kstpkper=None, masked_values=None)[source]

Method to add cell budget data to vtk

Parameters:
  • cbc (flopy.utils.CellBudget object) – flopy binary CellBudget object

  • text (str or None) – The text identifier for the record. Examples include ‘RIVER LEAKAGE’, ‘STORAGE’, ‘FLOW RIGHT FACE’, etc. If text=None all compatible records are exported

  • kstpkper (tuple, list of tuples, None) – tuple or list of tuples of kstpkper, if kstpkper=None all records are selected

  • masked_values (list, None) – list of values to set equal to nan

add_heads(hds, kstpkper=None, masked_values=None)[source]

Method to add head data to a vtk file

Parameters:
  • hds (flopy.utils.LayerFile object) – Binary or Formatted HeadFile type object

  • kstpkper (tuple, list of tuples, None) – tuple or list of tuples of kstpkper, if kstpkper=None all records are selected

  • masked_values (list, None) – list of values to set equal to nan

add_model(model, selpaklist=None, masked_values=None)[source]

Method to add all array and transient list data from a modflow model to a timeseries of vtk files

Parameters:
  • model (fp.modflow.ModelInterface) – any flopy model object

  • selpaklist (list, None) – optional parameter where the user can supply a list of packages to export.

  • masked_values (list, None) – list of values to set equal to nan

add_package(pkg, masked_values=None)[source]

Method to set all arrays within a package to VTK arrays

Parameters:
  • pkg (flopy.pakbase.Package object) – flopy package object, example ModflowWel

  • masked_values (list, None) – list of values to set equal to nan

add_pathline_points(pathlines, timeseries=False)[source]

Method to add particle pathlines to the grid, with points colored by travel-time. Supports MODPATH or MODFLOW6 PRT pathline format, or MODPATH timeseries format.

Parameters:
  • pathlines (pd.dataframe, np.recarray or list) – Particle pathlines, either as a single dataframe or recarray or a list of such, separated by particle ID. If pathlines are not provided separately, the dataframe or recarray must have columns: ‘time’, ‘k’ & ‘particleid’ for MODPATH 3, 5, 6 or 7, and ‘irpt’, ‘iprp’, ‘imdl’, and ‘trelease’ for MODFLOW 6 PRT, so particle pathlines can be distinguished.

  • timeseries (bool, optional) – Whether to plot data as a series of vtk timeseries files for animation or as a single static vtk file. Default is false.

add_transient_array(d, name=None, masked_values=None)[source]

Method to add transient array data to the vtk object

Parameters:
  • d (dict) – dictionary of array2d, arry3d data or numpy array data

  • name (str, None) – parameter name, required when user provides a dictionary of numpy arrays

  • masked_values (list, None) – list of values to set equal to nan

Return type:

None

add_transient_list(mflist, masked_values=None)[source]

Method to add transient list data to a vtk object

Parameters:
  • mflist (flopy.utils.MfList object) –

  • masked_values (list, None) – list of values to set equal to nan

add_transient_vector(d, name, masked_values=None)[source]

Method to add transient vector data to vtk

Parameters:
  • d (dict) – dictionary of vectors

  • name (str) – name of vector to be displayed in vtk

  • masked_values (list, None) – list of values to set equal to nan

add_vector(vector, name, masked_values=None)[source]

Method to add vector data to vtk

Parameters:
  • vector (array) – array of dimension (3, nnodes)

  • name (str) – name of the vector to be displayed in vtk

  • masked_values (list, None) – list of values to set equal to nan

to_pyvista()[source]

Convert VTK object to PyVista meshes. If the VTK object contains 0 or multiple meshes a list of meshes is returned. Otherwise the one mesh is returned alone. PyVista must be installed for this method.

Returns:

PyVista mesh or list of meshes

Return type:

pyvista.DataSet or list of pyvista.DataSet

write(f: str | PathLike, kper=None)[source]

Method to write a vtk file from the VTK object

Parameters:
  • f (str or PathLike) – vtk file name

  • kpers (int, list, tuple) – stress period or list of stress periods to write to vtk. This parameter only applies to transient package data.