Read data from a pickled Landlab grid file into a RasterModelGrid.
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 cPickle 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
|
---|
Examples
>>> from landlab import VoronoiDelaunayGrid
>>> from landlab.io.native_landlab import load_grid, save_grid
>>> import numpy as np
>>> import os
>>> x = np.random.rand(20)
>>> y = np.random.rand(20)
>>> grid_out = VoronoiDelaunayGrid(x, y)
>>> save_grid(grid_out, 'testsavedgrid.grid', clobber=True)
>>> grid_in = load_grid('testsavedgrid.grid')
>>> os.remove('testsavedgrid.grid') #to remove traces of this test
save_grid
(grid, path, clobber=False)[source]¶Save a grid and fields to a Landlab “native” format.
This method uses cPickle to save a grid as a cPickle 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
path : str
clobber : bool (default False)
|
---|
Examples
>>> from landlab import RasterModelGrid
>>> from landlab.io.native_landlab import save_grid
>>> import os
>>> grid_out = RasterModelGrid(4,5,2.)
>>> save_grid(grid_out, 'testsavedgrid.grid', clobber=True)
>>> os.remove('testsavedgrid.grid') #to remove traces of this test