Output of Landlab grid and field data in Legacy VTK format#
- write_legacy_vtk(path, grid, z_at_node='topographic__elevation', fields=None, clobber=False)[source]#
Write grid and field to a legacy VTK format file or file-like object.
- Parameters:
path (file-like) – Path to file or a file-like object
grid (Landlab grid object) – The grid for which to output data
z_at_node (str or (n_nodes, ) ndarray) – Field name or array of values to use for z coordinate
fields (list of str (optional)) – List of node fields to output; default is all node fields
clobber (bool (optional)) – Ok to overwrite existing file (default False)
Examples
>>> import io >>> import numpy as np >>> from landlab import HexModelGrid >>> from landlab.io.legacy_vtk import write_legacy_vtk
>>> grid = HexModelGrid((3, 2)) >>> topo = grid.add_zeros("topographic__elevation", at="node") >>> topo[:] = np.arange(len(topo)) >>> water = grid.add_zeros("surface_water__depth", at="node") >>> water[:] = 0.1 * (7.0 - topo)
>>> vtk_file = write_legacy_vtk(io.StringIO(), grid) >>> lines = vtk_file.getvalue().splitlines() >>> print(lines[0]) # vtk DataFile Version 2.0 >>> for i in range(5, 13): ... print(lines[i]) ... POINTS 7 float 0.5 0.0 0.0 1.5 0.0 1.0 0.0 0.866025 2.0 1.0 0.866025 3.0 2.0 0.866025 4.0 0.5 1.732051 5.0 1.5 1.732051 6.0 >>> for i in range(14, 21): ... print(lines[i]) ... CELLS 6 24 3 3 0 1 3 3 2 0 3 4 3 1 3 5 2 3 3 6 3 4 3 6 5 3 >>> for i in range(22, 29): ... print(lines[i]) ... CELL_TYPES 6 5 5 5 5 5 5 >>> for i in range(30, 49): ... print(lines[i]) ... POINT_DATA 7 SCALARS topographic__elevation float 1 LOOKUP_TABLE default 0.0 1.0 2.0 3.0 4.0 5.0 6.0 SCALARS surface_water__depth float 1 LOOKUP_TABLE default 0.7 0.6 0.5 0.4 0.3 0.2 0.1