class ErosionModel

Erosion Model

Base class for common functions of all terrainbento erosion models.

class ErosionModel(clock, grid, precipitator=None, runoff_generator=None, flow_director='FlowDirectorSteepest', depression_finder=None, flow_accumulator_kwargs=None, boundary_handlers=None, output_writers=None, output_interval=None, save_first_timestep=True, output_prefix='terrainbento_output', fields=None)[source]

Bases: object

Base class providing common functionality for terrainbento models.

An ErosionModel is the skeleton for the models of terrain evolution in terrainbento.

This is a base class that does not implement any processes, but rather simply handles I/O and setup. Derived classes are meant to include Landlab components to model actual erosion processes.

It is expected that a derived model will define an __init__ and a run_one_step method. If desired, the derived model can overwrite the existing run_for, run, and finalize methods.

The following at-node fields must be specified in the grid:
  • topographic__elevation

__init__(clock, grid, precipitator=None, runoff_generator=None, flow_director='FlowDirectorSteepest', depression_finder=None, flow_accumulator_kwargs=None, boundary_handlers=None, output_writers=None, output_interval=None, save_first_timestep=True, output_prefix='terrainbento_output', fields=None)[source]
Parameters
  • clock (terrainbento Clock instance) –

  • grid (landlab model grid instance) – The grid must have all required fields.

  • precipitator (terrainbento precipitator, optional) – An instantiated version of a valid precipitator. See the precipitator module for valid options. The precipitator creates rain. Default value is the UniformPrecipitator with a rainfall flux of 1.0.

  • runoff_generator (terrainbento runoff_generator, optional) –

    An instantiated version of a valid runoff generator. See the runoff generator module for valid options. The runoff generator converts rain into runoff. This runoff is then accumulated into surface water discharge (\(Q\)) and used by channel erosion components. Default value is SimpleRunoff in which all rainfall turns into runoff. For the drainage area version of the stream power law use the default precipitator and runoff_generator.

    If the default values of both the precipitator and runoff_generator are used, then \(Q\) will be equal to drainage area.

  • flow_director (str, optional) – String name of a Landlab FlowDirector. Default is “FlowDirectorSteepest”.

  • depression_finder (str, optional) – String name of a Landlab depression finder. Default is None.

  • flow_accumulator_kwargs (dictionary, optional) – Dictionary of any additional keyword arguments to pass to the Landlab FlowAccumulator. Default is an empty dictionary.

  • boundary_handlers (dictionary, optional) – Dictionary with name: instance key-value pairs. Each entry must be a valid instance of a terrainbento boundary handler. See the boundary handlers module for valid options.

  • output_writers (dictionary of output writers.) – Classes or functions used to write incremental output (e.g. make a diagnostic plot). These should be passed in a dictionary with two keys: “class” and “function”. The value associated with each of these should be a list containing the uninstantiated output writers. See the Jupyter notebook examples for more details.

  • output_interval (float, optional) – Default is the Clock’s stop time.

  • save_first_timestep (bool, optional) – Indicates whether model output should be saved at time zero. Default is True.

  • output_prefix (str, optional) – String prefix for names of output netCDF files. Default is "terrainbento_output".

  • fields (list, optional) – List of field names to write as netCDF output. Default is to only write out “topographic__elevation”.

Returns

ErosionModel

Return type

object

Examples

This model is a base class and is not designed to be run on its own. We recommend that you look at the terrainbento tutorials for examples of usage.

calculate_cumulative_change()[source]

Calculate cumulative node-by-node changes in elevation.

create_and_move_water(step)[source]

Create and move water.

Run the precipitator, the runoff generator, and the flow accumulator, in that order.

finalize()[source]

Finalize model.

This base-class method does nothing. Derived classes can override it to run any required finalization steps.

finalize__run_one_step(step)[source]

Finalize run_one_step method.

This base-class method increments model time and updates boundary conditions.

classmethod from_dict(params, output_writers=None)[source]

Construct a terrainbento model from an input parameter dictionary.

The input parameter dictionary portion associated with the “grid” keword will be passed directly to the Landlab create_grid. function.

Parameters
  • params (dict) – Dictionary of input parameters.

  • output_writers (dictionary of output writers.) – Classes or functions used to write incremental output (e.g. make a diagnostic plot). These should be passed in a dictionary with two keys: “class” and “function”. The value associated with each of these should be a list containing the uninstantiated output writers. See the Jupyter notebook examples for more details.

Examples

>>> params = {
...     "grid": {
...         "RasterModelGrid": [
...             (4, 5),
...             {
...                 "fields": {
...                     "node": {
...                         "topographic__elevation": {
...                             "constant": [{"value": 0.0}]
...                         }
...                     }
...                 }
...             },
...         ]
...     },
...     "clock": {"step": 1, "stop": 200},
... }
>>> model = ErosionModel.from_dict(params)
>>> model.clock.step
1.0
>>> model.clock.stop
200.0
>>> model.grid.shape
(4, 5)
classmethod from_file(file_like)[source]

Construct a terrainbento model from a file.

Parameters

file_like (file_like or str) – Contents of a parameter file, a file-like object, or the path to a parameter file.

Examples

>>> from io import StringIO
>>> filelike = StringIO('''
... grid:
...   RasterModelGrid:
...     - [4, 5]
...     - fields:
...         node:
...           topographic__elevation:
...             constant:
...               - value: 0.0
... clock:
...   step: 1
...   stop: 200
... ''')
>>> model = ErosionModel.from_file(filelike)
>>> model.clock.step
1.0
>>> model.clock.stop
200.0
>>> model.grid.shape
(4, 5)
property model_time

Return current time of model integration in model time units.

remove_output_netcdfs()[source]

Remove all netCDF files written by a model run.

run()[source]

Run the model until complete.

The model will run for the duration indicated by the input file or dictionary parameter "stop", at a time step specified by the parameter "step", and create ouput at intervals of "output_duration".

run_for(step, runtime)[source]

Run model without interruption for a specified time period.

run_for runs the model for the duration runtime with model time steps of step.

Parameters
  • step (float) – Model run timestep.

  • runtime (float) – Total duration for which to run model.

run_output_writers()[source]

Run all output writers.

save_to_xarray_dataset(filename='terrainbento.nc', time_unit='time units', reference_time='model start', space_unit='space units')[source]

Save model output to xarray dataset.

If you would like to have CF compliant NetCDF make sure that your time and space units and reference times will work with standard decoding.

The default time unit and reference time will give the time dimention a value of “time units since model start”. The default space unit will give a value of “space unit”.

Parameters
  • filename (str, optional) – The file path where the file should be saved. The default value is “terrainbento.nc”.

  • time_unit (str, optional) – Name of time unit. Default is “time units”.

  • time (reference) – Reference tim. Default is “model start”.

  • space_unit (str, optional) – Name of space unit. Default is “space unit”.

to_xarray_dataset(time_unit='time units', reference_time='model start', space_unit='space units')[source]

Convert model output to an xarray dataset.

If you would like to have CF compliant NetCDF make sure that your time and space units and reference times will work with standard decoding.

The default time unit and reference time will give the time dimention a value of “time units since model start”. The default space unit will give a value of “space unit”.

Parameters
  • time_unit (str, optional) – Name of time unit. Default is “time units”.

  • time (reference) – Reference tim. Default is “model start”.

  • space_unit (str, optional) – Name of space unit. Default is “space unit”.

update_boundary_conditions(step)[source]

Run all boundary handlers forward by step.

Parameters

step (float) – Timestep in unit of model time.

write_output()[source]

Write output to file as a netCDF.

Filenames will have the value of "output_filename" from the input file or parameter dictionary as the first part of the file name and the model run iteration as the second part of the filename.

main()[source]

Executes model.