dataio module

Functions for reading and writing data from vtk, vtu, vertex files, and stl.

Created: Wed April 05 2017

Author: Christopher Strickland

Email: cstric12@utk.edu

planktos.dataio.load_netcdf(*args, **kwargs)[source]

Load a NetCDF file. Does not automatically read in any data.

Parameters:

filename (string) – path and filename of the NetCDF file

Returns:

NetCDF4 Dataset object

planktos.dataio.netcdf_dep(func)[source]

Decorator for NetCDF readers to check package import.

planktos.dataio.pyvista_dep(func)[source]

Decorator for pyvista writers to check package import.

planktos.dataio.read_2DEulerian_Data_From_vtk(*args, **kwargs)[source]

Reads ascii Structured Points VTK files using the Python VTK library, where the file contains 2D IB2d data, either scalar or vector.

The call signature is set up for easy looping over the sort of file name sturcture used by IB2d.

Parameters:
  • path (string) – directory containing the vtk files

  • simNum (string) – sim number as a string, as given in the filename (with leading zeros)

  • strChoice (string) – prefix on the filenames. typically ‘u’ or ‘uX’ or ‘uY’ in IB2d

  • xy (bool, default=False) – if True, also return mesh data

Returns:

  • data (one or two arrays) – one array if scalar data, two arrays (x,y) if vector data. NOTE: the data is indexed [y,x] so will need to be transposed.

  • x, y (mesh data as 1D arrays, only if xy=True) – contains the spatial mesh points in the x and y directions respectively

planktos.dataio.read_IB2d_vertices(filename)[source]

Import a Lagrangian mesh from an IB2d ascii vertex file.

Parameters:

filename (string) – path and filename of the vertex file

Returns:

array – Nx2 array of 2D vertices

planktos.dataio.read_stl_mesh(*args, **kwargs)[source]

Import a mesh from an stl file and return the vertex information as an Nx3x3 array along with the maximum vector length. Uses the numpy-stl library.

Parameters:
  • filename (string) – path and filename of the STL file

  • unit_conv (float, optional) – scalar to multiply the mesh by in order to convert units

Returns:

  • array of shape Nx3x3 – Each row is a mesh element consisting of three 3D points. For a given row n, this is represented as a 3x3 matrix where each row is a point and each column is a spatial dimension.

  • float – Length of the longest side of any triangle

planktos.dataio.read_vtk_Rectilinear_Grid_Vector(*args, **kwargs)[source]

Reads an ascii VTK file with Rectilinear Grid Vector data and TIME info using the VTK Python library.

Parameters:

filename (string) – path and filename of the VTK file

Returns:

  • list of arrays – vector data as numpy arrays, one array for each dimension of the vector in order of x, y, z. Each array is indexed as [x,y,z]

  • list of arrays – 1D arrays of grid points in the x, y, and z directions

  • time (float)

planktos.dataio.read_vtk_Structured_Points(*args, **kwargs)[source]

Read in either Scalar or Vector data from an ascii VTK Structured Points file using the VTK Python library.

Used by read_2DEulerian_Data_From_vtk.

Note: if the file has both scalar and vector data, only the scalar data will be returned.

Parameters:

filename (string) – path and filename of the VTK file

Returns:

  • e_data (array, indexed [z,y,x] (scalar data only))

  • e_data_X, e_data_Y, e_data_Z (arrays, indexed [z,y,x] (vector data only)) – one array for each component of the vector field: X, Y, and Z respectively

  • origin (tuple) – origin field of VTK

  • spacing (tuple) – spacing of grid

planktos.dataio.read_vtk_Unstructured_Grid_Points(*args, **kwargs)[source]

Read immersed mesh data from an ascii Unstructured Grid VTK file, such as those exported from VisIt. Uses the VTK Python library. The mesh should contain only singleton points (vertices).

Parameters:

filename (string) – path and filename of the VTK file

Returns:

  • points (array) – each row is a vertex

  • bounds (array) – bounds field data

planktos.dataio.read_vtu_mesh_velocity(filename)[source]

Reads ascii COMSOL velocity data in a vtu or equivalent text file. It is assumed that the data is on a regular grid. Currently, there is no support for multiple time points, so the file must contain data from only a single time.

Parameters:

filename (string) – path and filename of the VTU file

Returns:

  • data (list of arrays) – one array for each spatial component of velocity, where each element of an array is a gridpoint. arrays are indexed [x,y,z]

  • grid (list of arrays) – spatial grid in each direction (1D arrays)

planktos.dataio.stl_dep(func)[source]

Decorator for STL readers to check package import.

planktos.dataio.vtk_dep(func)[source]

Decorator for VTK readers to check package import.

planktos.dataio.write_vtk_2D_rectilinear_grid_scalars(*args, **kwargs)[source]

Write scalar data to an ascii VTK Rectilinear Grid file (e.g. vorticity). Expects data to be on a 2D rectilinear grid. Uses the pyvista library.

The call signature is formated for easy looping over many time points, resulting in one VTK file per time. The filename will be based on the title string and the cycle number. The VTK file will contain field data on both CYCLE (integer time step number) and TIME (float time in seconds).

Parameters:
  • path (string) – directory where data should go

  • title (string) – title to prepend to filename

  • data (ndarray) – scalar data, must be 2D

  • grid_points (tuple (length 2)) – grid points in each direction; environment.flow_points

  • cycle (int) – dump number, e.g. integer time step in the simulation

  • time (float) – simulation time (generally understood to be in seconds)

  • binary (bool) – whether or not the VTK should be binary (vs. ascii for, e.g., debugging)

planktos.dataio.write_vtk_point_data(*args, **kwargs)[source]

Write point data to an ascii VTK file, such as agent positions.

The call signature is formated for easy looping over many time points, resulting in one VTK file per time. The filename will be based on the title string and the cycle number. The VTK file will be formatted as PolyData and will contain field data on both CYCLE (integer time step number) and TIME (float time in seconds).

Parameters:
  • path (string) – directory where data should go

  • title (string) – title to prepend to filename

  • data (ndarray) – position data, must be of shape Nx3

  • cycle (int, optional) – dump number, e.g. integer time step in the simulation

  • time (float, optional) – simulation time (generally understood to be in seconds)

planktos.dataio.write_vtk_rectilinear_grid_vectors(*args, **kwargs)[source]

Write vector data on a 2D or 3D uniform grid (e.g. fluid velocity). Uses the pyvista library.

The call signature is formated for easy looping over many time points, resulting in one VTK file per time. The filename will be based on the title string and the cycle number. The VTK file will contain field data on both CYCLE (integer time step number) and TIME (float time in seconds).

Parameters:
  • path (str) – path to a directory where the data should go. If the directory does not exist, it will be created.

  • title (str) – title to prepend to filenames

  • data (list of ndarrays) – list of numpy array of regular grid data. The ndarrays must not include a time component (e.g., the dimension of the array should match the length of the list which should match the length of parameter L)

  • grid_points (tuple) – grid points in each direction; environment.flow_points

  • cycle (int, optional) – dump number, which will also be included in the filename

  • time (float, optional) – time stamp

  • binary (bool) – whether or not the VTK should be binary (vs. ascii for, e.g., debugging)