landlab.io.obj

Write (x,y,z) data from a Landlab grid + 1 field to a Wavefront OBJ file.

OBJ functions

write_obj(path, grid[, field_for_z, clobber])

Write landlab grid and one field to Wavefront OBJ.

write_obj(path, grid, field_for_z='topographic__elevation', clobber=False)[source]

Write landlab grid and one field to Wavefront OBJ.

Parameters:
  • path (str, or file-like) – Path to output file.

  • grid (Landlab grid object) – Landlab grid object that includes associated values.

  • field_for_z (str, optional) – Name of a field to use for the z-values of the OBJ file.

  • clobber (boolean, optional) – If path exists, clobber the existing file, otherwise raise an exception.

Returns:

The input path used to write the OBJ file.

Return type:

str or file-like

Examples

>>> import io
>>> from landlab import HexModelGrid, RasterModelGrid
>>> from landlab.io.obj import write_obj
>>> grid = HexModelGrid((3, 2), spacing=2.0)
>>> z = grid.add_zeros("topographic__elevation", at="node")
>>> z[3] = 1.0
>>> obj_file = write_obj(io.StringIO(), grid)
>>> print(obj_file.getvalue())
# landlabgrid
#
g landlabgrid
v 1.0 0.0 0.0
v 3.0 0.0 0.0
v 0.0 1.732051 0.0
v 2.0 1.732051 1.0
v 4.0 1.732051 0.0
v 1.0 3.464102 0.0
v 3.0 3.464102 0.0
f 4// 1// 2//
f 4// 3// 1//
f 5// 4// 2//
f 6// 3// 4//
f 7// 4// 5//
f 7// 6// 4//