landlab

Input and output in native landlab format

Read data from a pickled Landlab grid file into a RasterModelGrid.

Read Landlab native

load_grid(path) Load a grid and its fields from a Landlab “native” format.
save_grid(grid, path[, clobber]) Save a grid and fields to a Landlab “native” format.
load_grid(path)[source]

Load a grid and its fields from a Landlab “native” format.

This method uses pickle to load a saved grid. It assumes you saved using vmg.save() or save_grid, i.e., that the pickle file is a .grid file.

Caution: Pickling can be slow, and can produce very large files. Caution 2: Future updates to Landlab could potentially render old saves unloadable.

Parameters:path (str) – Path to output file, either without suffix, or ‘.grid’

Examples

>>> from landlab import VoronoiDelaunayGrid
>>> from landlab.io.native_landlab import load_grid, save_grid
>>> import numpy as np
>>> import tempfile
>>> x = np.random.rand(20)
>>> y = np.random.rand(20)
>>> grid_out = VoronoiDelaunayGrid(x, y)
>>> with tempfile.TemporaryDirectory() as tmpdirname:
...     fname = os.path.join(tmpdirname, 'testsavedgrid.grid')
...     save_grid(grid_out, fname, clobber=True)
...     grid_in = load_grid(fname)
save_grid(grid, path, clobber=False)[source]

Save a grid and fields to a Landlab “native” format.

This method uses pickle to save a grid as a pickle file. All fields will be saved, along with the grid.

The recommended suffix for the save file is ‘.grid’. This will be added to your save if you don’t include it.

Caution: Pickling can be slow, and can produce very large files. Caution 2: Future updates to Landlab could potentially render old saves unloadable.

Parameters:
  • grid (object of subclass ModelGrid) – Grid object to save
  • path (str) – Path to output file, either without suffix, or ‘.grid’
  • clobber (bool (default False)) – Set to True to allow overwrites of existing files

Examples

>>> from landlab import RasterModelGrid
>>> from landlab.io.native_landlab import save_grid
>>> import tempfile
>>> grid_out = RasterModelGrid((4, 5), xy_spacing=2.)
>>> with tempfile.TemporaryDirectory() as tmpdirname:
...     fname = os.path.join(tmpdirname, 'testsavedgrid.grid')
...     save_grid(grid_out, fname, clobber=True)