### Instantiate and Run BasicChRt Model (Minimal Example) Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/derived_models/model_basicChRt.html This snippet demonstrates the minimal setup to instantiate the BasicChRt model and run it for a single time step. It requires importing necessary classes and setting up a clock and grid with initial conditions. ```python from landlab import RasterModelGrid from landlab.values import random, constant from terrainbento import Clock, BasicChRt clock = Clock(start=0, stop=100, step=1) grid = RasterModelGrid((5,5)) _ = random(grid, "topographic__elevation") _ = constant(grid, "lithology_contact__elevation", value=-10.) model = BasicChRt(clock, grid) ``` ```python model.run_one_step(1.) assert model.model_time == 1.0 ``` -------------------------------- ### Constructing a BasicRt Model Instance Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/derived_models/model_basicRt.html This example demonstrates the minimal setup required to instantiate the BasicRt model. Ensure you have a Clock and a RasterModelGrid with the necessary fields initialized. ```python from landlab import RasterModelGrid from landlab.values import random, constant from terrainbento import Clock, BasicRt clock = Clock(start=0, stop=100, step=1) grid = RasterModelGrid((5,5)) _ = random(grid, "topographic__elevation") _ = constant(grid, "lithology_contact__elevation", value=-10.) model = BasicRt(clock, grid) ``` -------------------------------- ### Constructing and Running BasicRtTh Model Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/derived_models/model_basicRtTh.html This snippet demonstrates the minimal setup for constructing a BasicRtTh model instance. It requires importing necessary components from landlab and terrainbento, initializing a clock and grid, and then instantiating the model. The example shows how to run the model for a single step and check the model time. ```python from landlab import RasterModelGrid from landlab.values import random, constant from terrainbento import Clock, BasicRtTh clock = Clock(start=0, stop=100, step=1) grid = RasterModelGrid((5,5)) _ = random(grid, "topographic__elevation") _ = constant(grid, "lithology_contact__elevation", value=-10.) model = BasicRtTh(clock, grid) model.run_one_step(1.) print(model.model_time) ``` -------------------------------- ### RandomPrecipitator Initialization and Example Usage Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/precipitators/random_precipitation.html Demonstrates how to initialize the RandomPrecipitator with a Landlab grid and shows an example of generating initial precipitation values and then running the precipitator for one time step. The output shows the precipitation values before and after the run. ```python import numpy as np from landlab import RasterModelGrid from terrainbento import RandomPrecipitator grid = RasterModelGrid((5,5)) precipitator = RandomPrecipitator(grid) np.round( grid.at_node["rainfall__flux"].reshape(grid.shape), decimals=2) precipitator.run_one_step(10) np.round( grid.at_node["rainfall__flux"].reshape(grid.shape), decimals=2) ``` -------------------------------- ### Instantiate BasicDd Model Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/derived_models/model_basicDd.html This example demonstrates the minimal setup required to instantiate the BasicDd model. Ensure you have a Clock and a RasterModelGrid with topographic elevation defined. The model can then be constructed with these components. ```python from landlab import RasterModelGrid from landlab.values import random from terrainbento import Clock, BasicDd clock = Clock(start=0, stop=100, step=1) grid = RasterModelGrid((5,5)) _ = random(grid, "topographic__elevation") model = BasicDd(clock, grid) ``` -------------------------------- ### Import and Initialize BasicSa Model Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/derived_models/model_basicSa.html Demonstrates how to import necessary classes and initialize the BasicSa model with a clock and grid. This is the starting point for using the model. ```python from landlab import RasterModelGrid from landlab.values import random from terrainbento import Clock, BasicSa clock = Clock(start=0, stop=100, step=1) grid = RasterModelGrid((5,5)) _ = random(grid, "topographic__elevation") _ = random(grid, "soil__depth") model = BasicSa(clock, grid) ``` -------------------------------- ### Construct BasicChRtTh Model Instance Source: https://terrainbento.readthedocs.io/en/latest/source/terrainbento.derived_models.model_basicChRtTh.html This is a minimal example to demonstrate how to construct an instance of model BasicChRtCh. For more detailed examples, including steady-state test examples, see the terrainbento tutorials. To begin, import the model class. ```python from landlab import RasterModelGrid from landlab.values import random, constant from terrainbento import Clock, BasicChRtTh clock = Clock(start=0, stop=100, step=1) grid = RasterModelGrid((5,5)) _ = random(grid, "topographic__elevation") _ = constant(grid, "lithology_contact__elevation", value=-10.) ``` -------------------------------- ### Initialize BasicSa Model Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/derived_models/model_basicSa.html This is a minimal example to demonstrate how to construct an instance of the BasicSa model. It requires a Landlab grid and clock, and allows for customization of various model parameters. ```python from landlab import RasterModelGrid from landlab.decorators import grid_element from terrainbento import Clock, BasicSa GRID_EXAMPLE_DIAMETER = 5000.0 GRID_EXAMPLE_NROWS = 10 GRID_EXAMPLE_NCOLS = 10 # Instantiate a grid mg = RasterModelGrid((GRID_EXAMPLE_NROWS, GRID_EXAMPLE_NCOLS), xy_spacing=GRID_EXAMPLE_DIAMETER / GRID_EXAMPLE_NROWS) # Add fields to the grid mg.add_zeros("topographic__elevation", at="node") mg.add_zeros("soil__depth", at="node") # Set initial conditions for elevation and soil depth mg.at_node["topographic__elevation"] = mg.node_y / 10.0 mg.at_node["soil__depth"] = 1.0 # Instantiate a clock clock = Clock(span=100.0, dt=1.0) # Instantiate the model basic_sa = BasicSa(clock, mg, m_sp=0.5, n_sp=1.0, water_erodibility=0.0001, regolith_transport_parameter=0.1, soil_production__maximum_rate=0.001, soil_production__decay_depth=0.5, soil_transport_decay_depth=0.5) ``` -------------------------------- ### Instantiate BasicStTh Model Source: https://terrainbento.readthedocs.io/en/latest/source/terrainbento.derived_models.model_basicStTh.html Demonstrates the minimal setup required to construct an instance of the BasicStTh model. Ensure you have a Clock and a RasterModelGrid with topographic elevation defined. ```python from landlab import RasterModelGrid from landlab.values import random from terrainbento import Clock, BasicStTh clock = Clock(start=0, stop=100, step=1) grid = RasterModelGrid((5,5)) _ = random(grid, "topographic__elevation") model = BasicStTh(clock, grid) ``` -------------------------------- ### Constructing and Running BasicChRtTh Model Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/derived_models/model_basicChRtTh.html Demonstrates the minimal setup for instantiating and running a single step of the BasicChRtTh model. Requires importing necessary classes and setting up initial grid conditions. ```python from landlab import RasterModelGrid from landlab.values import random, constant from terrainbento import Clock, BasicChRtTh clock = Clock(start=0, stop=100, step=1) grid = RasterModelGrid((5,5)) _ = random(grid, "topographic__elevation") _ = constant(grid, "lithology_contact__elevation", value=-10.) model = BasicChRtTh(clock, grid) model.run_one_step(1.) print(model.model_time) ``` -------------------------------- ### Constructing a BasicDdRt Model Instance Source: https://terrainbento.readthedocs.io/en/latest/source/terrainbento.derived_models.model_basicDdRt.html This example demonstrates the minimal setup required to instantiate the BasicDdRt model. It requires a Landlab grid with elevation and lithology contact elevation fields, and a terrainbento Clock instance. Ensure that the necessary fields are initialized on the grid before creating the model. ```python from landlab import RasterModelGrid from landlab.values import random, constant from terrainbento import Clock, BasicDdRt clock = Clock(start=0, stop=100, step=1) grid = RasterModelGrid((5,5)) _ = random(grid, "topographic__elevation") _ = constant(grid, "lithology_contact__elevation", value=-10.) model = BasicDdRt(clock, grid) ``` -------------------------------- ### Instantiate BasicDdSt Model Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/derived_models/model_basicDdSt.html This is a minimal example to demonstrate how to construct an instance of model BasicDdSt. For more detailed examples, including steady-state test examples, see the terrainbento tutorials. ```python from landlab.components import LinearDiffuser, StreamPowerSmoothThresholdEroder from terrainbento.base_class import StochasticErosionModel class BasicDdSt(StochasticErosionModel): r""" **BasicDdSt** model program. This model program uses a stochastic treatment of runoff and discharge, and includes an erosion threshold in the water erosion law. The threshold depends on cumulative incision depth, and therefore can vary in space and time. It combines models :py:class:`BasicDd` and :py:class:`BasicSt`. The model evolves a topographic surface, :math:`\eta (x,y,t)`, with the following governing equation: .. math:: \frac{\partial \eta}{\partial t} = -\left[K_{q}\hat{Q}^{m}S^{n} - \omega_{ct} \left(1-e^{-K_{q}\hat{Q}^{m}S^{n} / \omega_{ct}}\right)\right)] + D \nabla^2 \eta where :math:`\hat{Q}` is the local stream discharge (the hat symbol indicates that it is a random-in-time variable) and :math:`S` is the local slope gradient. :math:`m` and :math:`n` are the discharge and slope exponent, respectively, :math:`\omega_c` is the critical stream power required for erosion to occur, :math:`K` is the erodibility by water, and :math:`D` is the regolith transport parameter. :math:`\omega_{ct}` may change through time as it increases with cumulative incision depth: .. math:: \omega_{ct}\left(x,y,t\right) = \mathrm{max}\left(\omega_c + b D_I\left(x, y, t\right), \omega_c \right) where :math:`\omega_c` is the threshold when no incision has taken place, :math:`b` is the rate at which the threshold increases with incision depth, and :math:`D_I` is the cumulative incision depth at location :math:`\left(x,y\right)` and time :math:`t`. Refer to `Barnhart et al. (2019) `_ Table 5 for full list of parameter symbols, names, and dimensions. The following at-node fields must be specified in the grid: - ``topographic__elevation`` """ _required_fields = ["topographic__elevation"] def __init__( self, clock, grid, m_sp=0.5, n_sp=1.0, water_erodibility=0.0001, regolith_transport_parameter=0.1, water_erosion_rule__threshold=0.01, water_erosion_rule__thresh_depth_derivative=0.0, infiltration_capacity=1.0, **kwargs ): """ Parameters ---------- clock : terrainbento Clock instance grid : landlab model grid instance The grid must have all required fields. m_sp : float, optional Drainage area exponent (:math:`m`). Default is 0.5. n_sp : float, optional Slope exponent (:math:`n`). Default is 1.0. water_erodibility : float, optional Water erodibility (:math:`K`). Default is 0.0001. regolith_transport_parameter : float, optional Regolith transport efficiency (:math:`D`). Default is 0.1. water_erosion_rule__threshold : float, optional Erosion rule threshold when no erosion has occured (:math:`\omega_c`). Default is 0.01. water_erosion_rule__thresh_depth_derivative : float, optional Rate of increase of water erosion threshold as increased incision occurs (:math:`b`). Default is 0.0. infiltration_capacity: float, optional Infiltration capacity (:math:`I_m`). Default is 1.0. **kwargs : Keyword arguments to pass to :py:class:`StochasticErosionModel`. These arguments control the discharge :math:`\hat{Q}`. Returns ------- BasicDdSt : model object Examples -------- This is a minimal example to demonstrate how to construct an instance of model **BasicDdSt**. For more detailed examples, including steady-state test examples, see the terrainbento tutorials. """ super( BasicDdSt, self, clock=clock, grid=grid, m_sp=m_sp, n_sp=n_sp, water_erodibility=water_erodibility, regolith_transport_parameter=regolith_transport_parameter, water_erosion_rule__threshold=water_erosion_rule__threshold, water_erosion_rule__thresh_depth_derivative=water_erosion_rule__thresh_depth_derivative, infiltration_capacity=infiltration_capacity, **kwargs, ) ``` -------------------------------- ### Initialize BasicDdSt Model Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/derived_models/model_basicDdSt.html Demonstrates how to import necessary components, set up the clock and grid, and instantiate the BasicDdSt model. This is the starting point for using the model. ```python from landlab import RasterModelGrid from landlab.values import random from terrainbento import Clock, BasicDdSt clock = Clock(start=0, stop=100, step=1) grid = RasterModelGrid((5,5)) _ = random(grid, "topographic__elevation") model = BasicDdSt(clock, grid) ``` -------------------------------- ### Instantiate and Run BasicRtVs Model Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/derived_models/model_basicRtVs.html Demonstrates the minimal setup for creating and running a BasicRtVs model instance. Requires importing necessary landlab and terrainbento components. ```python from landlab import RasterModelGrid from landlab.values import random, constant from terrainbento import Clock, BasicRtVs clock = Clock(start=0, stop=100, step=1) grid = RasterModelGrid((5,5)) _ = random(grid, "topographic__elevation") _ = random(grid, "soil__depth") _ = constant(grid, "lithology_contact__elevation", value=-10.) model = BasicRtVs(clock, grid) model.run_one_step(1.) print(model.model_time) ``` -------------------------------- ### Instantiate BasicHySt Model Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/derived_models/model_basicHySt.html This is a minimal example to demonstrate how to construct an instance of model BasicHySt. It requires a Landlab grid and a terrainbento Clock. ```python from landlab import RasterModelGrid from landlab.values import random from terrainbento import Clock, BasicHySt clock = Clock(start=0, stop=100, step=1) grid = RasterModelGrid((5,5)) ``` -------------------------------- ### BasicCh Model Initialization Example Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/derived_models/model_basicCh.html Demonstrates how to construct an instance of the BasicCh model. Requires a terrainbento Clock and a Landlab RasterModelGrid with topographic elevation data. The model can then be run for a specified duration. ```python from landlab import RasterModelGrid from landlab.values import random from terrainbento import Clock, BasicCh clock = Clock(start=0, stop=100, step=1) grid = RasterModelGrid((5,5)) _ = random(grid, "topographic__elevation") model = BasicCh(clock, grid) model.run_one_step(1.) print(model.model_time) ``` -------------------------------- ### Constructing a BasicRtVs Model Instance Source: https://terrainbento.readthedocs.io/en/latest/source/terrainbento.derived_models.model_basicRtVs.html This snippet demonstrates the minimal setup required to instantiate the BasicRtVs model. It requires a Clock and a RasterModelGrid with specific fields initialized. ```python from landlab import RasterModelGrid from landlab.values import random, constant from terrainbento import Clock, BasicRtVs clock = Clock(start=0, stop=100, step=1) grid = RasterModelGrid((5,5)) _ = random(grid, "topographic__elevation") _ = random(grid, "soil__depth") _ = constant(grid, "lithology_contact__elevation", value=-10.) model = BasicRtVs(clock, grid) ``` -------------------------------- ### Constructing a BasicCh Model Instance Source: https://terrainbento.readthedocs.io/en/latest/source/terrainbento.derived_models.model_basicCh.html This snippet demonstrates the minimal setup required to instantiate the BasicCh model. It requires a Clock instance, a RasterModelGrid, and initial topographic elevation data. ```python from landlab import RasterModelGrid from landlab.values import random from terrainbento import Clock, BasicCh clock = Clock(start=0, stop=100, step=1) grid = RasterModelGrid((5,5)) _ = random(grid, "topographic__elevation") model = BasicCh(clock, grid) ``` -------------------------------- ### Instantiate BasicVs Model Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/derived_models/model_basicVs.html This example demonstrates how to construct an instance of the BasicVs model. It requires a Landlab grid with 'topographic__elevation' and 'soil__depth' fields, and a terrainbento Clock instance. The model is then initialized with these components. ```python from landlab import RasterModelGrid from landlab.values import random from terrainbento import Clock, BasicVs clock = Clock(start=0, stop=100, step=1) grid = RasterModelGrid((5,5)) _ = random(grid, "topographic__elevation") _ = random(grid, "soil__depth") model = BasicVs(clock, grid) ``` -------------------------------- ### Initialize UniformPrecipitator and Set Rainfall Flux Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/precipitators/uniform_precipitation.html Demonstrates how to create a UniformPrecipitator instance and set a specific rainfall flux value. The example shows the initial state of the 'rainfall__flux' field on the grid. ```python from landlab import RasterModelGrid from terrainbento import UniformPrecipitator grid = RasterModelGrid((5,5)) precipitator = UniformPrecipitator(grid, rainfall_flux=3.4) print(grid.at_node["rainfall__flux"].reshape(grid.shape)) ``` -------------------------------- ### BasicSt Model Initialization and Single Step Run Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/derived_models/model_basicSt.html Demonstrates the minimal setup for creating a BasicSt model instance and running it for a single time step. Ensure necessary Landlab components and terrainbento's Clock are initialized. ```python from landlab import RasterModelGrid from landlab.values import random from terrainbento import Clock, BasicSt clock = Clock(start=0, stop=100, step=1) grid = RasterModelGrid((5,5)) _ = random(grid, "topographic__elevation") model = BasicSt(clock, grid) model.run_one_step(1.) print(model.model_time) ``` -------------------------------- ### BasicStTh Model Initialization and Basic Usage Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/derived_models/model_basicStTh.html Demonstrates how to instantiate and run the BasicStTh model for a single time step. Ensure you have a Landlab grid and a terrainbento Clock instance. ```python from landlab import RasterModelGrid from landlab.values import random from terrainbento import Clock, BasicStTh clock = Clock(start=0, stop=100, step=1) grid = RasterModelGrid((5,5)) _ = random(grid, "topographic__elevation") model = BasicStTh(clock, grid) model.run_one_step(1.) print(model.model_time) ``` -------------------------------- ### Internal Function Example Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/model_template/model_template.html An example of an internal helper function within the model class. ```python def my_internal_function(self): """Do something necessary to instantiate or run ``ModelTemplate``.""" # replace pass with function. pass ``` -------------------------------- ### Construct BasicStVs Model Instance Source: https://terrainbento.readthedocs.io/en/latest/source/terrainbento.derived_models.model_basicStVs.html This snippet demonstrates the minimal setup required to construct an instance of the BasicStVs model. It includes importing necessary classes, initializing a Clock and RasterModelGrid, and setting up required fields on the grid. ```python from landlab import RasterModelGrid from landlab.values import random from terrainbento import Clock, BasicStVs clock = Clock(start=0, stop=100, step=1) grid = RasterModelGrid((5,5)) _ = random(grid, "topographic__elevation") _ = random(grid, "soil__depth") model = BasicStVs(clock, grid) ``` -------------------------------- ### BasicStVs Model Initialization and Single Step Run Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/derived_models/model_basicStVs.html Demonstrates how to instantiate the BasicStVs model and execute a single time step. Ensure 'topographic__elevation' and 'soil__depth' fields are initialized on the grid. ```python from landlab import RasterModelGrid from landlab.values import random from terrainbento import Clock, BasicStVs clock = Clock(start=0, stop=100, step=1) grid = RasterModelGrid((5,5)) _ = random(grid, "topographic__elevation") _ = random(grid, "soil__depth") model = BasicStVs(clock, grid) model.run_one_step(1.) print(model.model_time) ``` -------------------------------- ### Example Output of Reshaped Grid Source: https://terrainbento.readthedocs.io/en/latest/source/terrainbento.boundary_handlers.generic_function_baselevel_handler.html This example shows the output of reshaping a grid using the `b.reshape(mg.shape)` method, illustrating how the grid data is structured. ```python >>> print(b.reshape(mg.shape)) [[-10. -10. -10. -10. -10.] [-10. 10. 20. 30. -10.] [-10. 20. 30. 40. -10.] [-10. 30. 40. 50. -10.] [-10. -10. -10. -10. -10.]] ``` -------------------------------- ### Setup for Two Lithologies with Threshold Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/base_class/two_lithology_erosion_model.html Initializes 'substrate__erodibility', 'water_erosion_rule__threshold', and 'erody_wt' for models with two lithologies and a threshold. This setup is used when a threshold is involved in the erosion rule. ```python def _setup_rock_and_till_with_threshold(self): """Set up fields to handle for two layers with different erodibility.""" # Create field for erodibility self.erody = self.grid.add_zeros("node", "substrate__erodibility") # Create field for threshold values self.threshold = self.grid.add_zeros( "node", "water_erosion_rule__threshold" ) # Create array for erodibility weighting function self.erody_wt = np.zeros(self.grid.number_of_nodes) # set values correctly self._update_erodywt() self._update_erodibility_and_threshold_fields() ``` -------------------------------- ### Execute BasicSa Model from File Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/derived_models/model_basicSa.html Entry point for running the BasicSa model from a command-line input file. It handles argument parsing and initiates the model run. ```python import sys try: infile = sys.argv[1] except IndexError: print("Must include input file name on command line") sys.exit(1) ldsp = BasicSa.from_file(infile) ldsp.run() ``` -------------------------------- ### Setup for Two Lithologies with Erodibility Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/base_class/two_lithology_erosion_model.html Initializes the 'substrate__erodibility' field and an erodibility weighting function ('erody_wt') for models with two lithologies. This setup is used when no threshold is involved. ```python def _setup_rock_and_till(self): """Set up fields to handle for two layers with different erodibility.""" # Create field for erodibility self.erody = self.grid.add_zeros("node", "substrate__erodibility") # Create array for erodibility weighting function self.erody_wt = np.zeros(self.grid.number_of_nodes) # Set values correctly self._update_erodywt() self._update_erodibility_field() ``` -------------------------------- ### SimpleRunoff Class Initialization and Example Usage Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/runoff_generators/simple_runoff.html Demonstrates how to initialize the SimpleRunoff generator and shows an example of its output. This snippet requires numpy and landlab. The output shows the 'rainfall__flux' and the resulting 'water__unit_flux_in' after applying the runoff proportion. ```python import numpy as np from landlab import RasterModelGrid from terrainbento import RandomPrecipitator, SimpleRunoff grid = RasterModelGrid((5,5)) precipitator = RandomPrecipitator(grid) runoff_generator = SimpleRunoff(grid, runoff_proportion=0.3) np.round( grid.at_node["rainfall__flux"].reshape(grid.shape), decimals=2) np.round( grid.at_node["water__unit_flux_in"].reshape(grid.shape), decimals=2) ``` -------------------------------- ### Import and Initialize BasicDdVs Model Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/derived_models/model_basicDdVs.html Demonstrates how to import necessary components, create a grid, and initialize the BasicDdVs model with a clock and grid. ```python from landlab import RasterModelGrid from landlab.values import random from terrainbento import Clock, BasicDdVs clock = Clock(start=0, stop=100, step=1) grid = RasterModelGrid((5,5)) _ = random(grid, "topographic__elevation") _ = random(grid, "soil__depth") model = BasicDdVs(clock, grid) ``` -------------------------------- ### BasicCv Model Initialization and Single Step Run Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/derived_models/model_basicCv.html Demonstrates how to instantiate the BasicCv model and run it for a single time step. Ensure you have a Landlab grid and a terrainbento Clock instance. ```python from landlab import RasterModelGrid from landlab.values import random from terrainbento import Clock, BasicCv clock = Clock(start=0, stop=100, step=1) grid = RasterModelGrid((5,5)) _ = random(grid, "topographic__elevation") model = BasicCv(clock, grid) model.run_one_step(1.) print(model.model_time) ``` -------------------------------- ### Example Usage of GenericFuncBaselevelHandler Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/boundary_handlers/generic_function_baselevel_handler.html Demonstrates how to instantiate and use the GenericFuncBaselevelHandler with a custom function to modify baselevel elevations. The example shows setting an outlet condition, defining a function for elevation change, running the handler, and printing the resulting elevation and baselevel arrays. ```python mg.set_watershed_boundary_condition_outlet_id( 0, mg.at_node["topographic__elevation"], -9999.) my_func = lambda grid, t: -(grid.x_of_node + grid.y_of_node) bh = GenericFuncBaselevelHandler(mg, modify_core_nodes = True, function=my_func) bh.run_one_step(10.0) print(z.reshape(mg.shape)) print(b.reshape(mg.shape)) ``` -------------------------------- ### Initialize Model Components Source: https://terrainbento.readthedocs.io/en/latest/source/terrainbento.model_template.html Set up the necessary components for the model, including the clock, grid, and initial random elevation data. ```python from landlab import RasterModelGrid from landlab.values import random from terrainbento import Clock, BasicStVs clock = Clock(start=0, stop=100, step=1) grid = RasterModelGrid((5,5)) _ = random(grid, "topographic__elevation") ``` -------------------------------- ### Get Model Time Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/base_class/erosion_model.html A property that returns the current integration time of the model in its defined time units. ```python @property def model_time(self): """Return current time of model integration in model time units.""" return self._model_time ``` -------------------------------- ### SimpleRunoff Example Source: https://terrainbento.readthedocs.io/en/latest/source/terrainbento.runoff_generators.simple_runoff.html Demonstrates the usage of SimpleRunoff with RandomPrecipitator. Shows how rainfall flux is converted to water unit flux in. ```python import numpy as np np.random.seed(42) from landlab import RasterModelGrid from terrainbento import RandomPrecipitator, SimpleRunoff grid = RasterModelGrid((5,5)) precipitator = RandomPrecipitator(grid) runoff_generator = SimpleRunoff(grid, runoff_proportion=0.3) np.round( grid.at_node["rainfall__flux"].reshape(grid.shape), decimals=2) array([[ 0.37, 0.95, 0.73, 0.6 , 0.16], [ 0.16, 0.06, 0.87, 0.6 , 0.71], [ 0.02, 0.97, 0.83, 0.21, 0.18], [ 0.18, 0.3 , 0.52, 0.43, 0.29], [ 0.61, 0.14, 0.29, 0.37, 0.46]]) np.round( grid.at_node["water__unit_flux_in"].reshape(grid.shape), decimals=2) array([[ 0.11, 0.29, 0.22, 0.18, 0.05], [ 0.05, 0.02, 0.26, 0.18, 0.21], [ 0.01, 0.29, 0.25, 0.06, 0.05], [ 0.06, 0.09, 0.16, 0.13, 0.09], [ 0.18, 0.04, 0.09, 0.11, 0.14]]) ``` -------------------------------- ### Instantiate and Run BasicSaVs Model Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/derived_models/model_basicSaVs.html Demonstrates the basic usage of the BasicSaVs model, including importing necessary components, setting up the grid and clock, and running a single time step. ```python from landlab import RasterModelGrid from landlab.values import random from terrainbento import Clock, BasicSaVs clock = Clock(start=0, stop=100, step=1) grid = RasterModelGrid((5,5)) _ = random(grid, "topographic__elevation") _ = random(grid, "soil__depth") model = BasicSaVs(clock, grid) ``` ```python model.run_one_step(1.) model.model_time ``` -------------------------------- ### Precipitation Changer Initialization Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/boundary_handlers/precip_changer.html Initializes the Precipitation Changer boundary handler. This is typically done within the model setup phase. ```python self.model_time += step ``` -------------------------------- ### Initialize ErosionModel from Dictionary Source: https://terrainbento.readthedocs.io/en/latest/source/terrainbento.base_class.erosion_model.html Demonstrates initializing an ErosionModel instance using a dictionary of parameters. This method is useful for programmatic model setup. ```python 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 model.clock.stop model.grid.shape ``` -------------------------------- ### Instantiate BasicSt Model Source: https://terrainbento.readthedocs.io/en/latest/source/terrainbento.derived_models.model_basicSt.html This snippet demonstrates the minimal setup required to instantiate the BasicSt model. It includes importing necessary classes, initializing a Clock and RasterModelGrid, and creating a BasicSt model instance. ```python from landlab import RasterModelGrid from landlab.values import random from terrainbento import Clock, BasicSt clock = Clock(start=0, stop=100, step=1) grid = RasterModelGrid((5,5)) _ = random(grid, "topographic__elevation") model = BasicSt(clock, grid) ``` -------------------------------- ### Run UniformPrecipitator Step Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/precipitators/uniform_precipitation.html Shows how to advance the UniformPrecipitator by one time step. This example illustrates that the 'rainfall__flux' field remains constant after the step. ```python precipitator.run_one_step(10) print(grid.at_node["rainfall__flux"].reshape(grid.shape)) ``` -------------------------------- ### Initialize Default Clock Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/clock/clock.html Initializes a Clock object with default start, stop, and step values. Demonstrates the default behavior when no parameters are provided. ```python >>> from terrainbento import Clock >>> clock = Clock() >>> clock.start 0.0 >>> clock.stop 100.0 >>> clock.step 10.0 ``` -------------------------------- ### Executing BasicDdVs Model from File Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/derived_models/model_basicDdVs.html This snippet demonstrates how to run the BasicDdVs model using a configuration file. It handles command-line arguments to specify the input file and instantiates the model. Ensure the input file path is provided as a command-line argument. ```python def main(): # pragma: no cover """Executes model.""" import sys try: infile = sys.argv[1] except IndexError: print("Must include input file name on command line") sys.exit(1) my_model = BasicDdVs.from_file(infile) my_model.run() if __name__ == "__main__": main() ``` -------------------------------- ### record_rain_event Source: https://terrainbento.readthedocs.io/en/latest/_modules/terrainbento/base_class/stochastic_erosion_model.html Records a single rain event with its start time, duration, rainfall rate, and runoff rate. This is used internally to build the storm sequence. ```APIDOC ## record_rain_event ### Description Records a single rain event with its start time, duration, rainfall rate, and runoff rate. This is used internally to build the storm sequence. ### Method ```python record_rain_event(event_start_time, event_duration, rainfall_rate, runoff_rate) ``` ### Parameters #### Path Parameters - **event_start_time** (float) - The start time of the rain event. - **event_duration** (float) - The duration of the rain event. - **rainfall_rate** (float) - The rate of rainfall during the event. - **runoff_rate** (float) - The rate of runoff during the event. ### Returns None ``` -------------------------------- ### BasicSa Initialization Source: https://terrainbento.readthedocs.io/en/latest/source/terrainbento.derived_models.model_basicSa.html Initializes the BasicSa model with a clock, grid, and optional parameters for stream power exponents, erodibility, and soil properties. ```APIDOC ## BasicSa ### Description Initializes the terrainbento **BasicSa** model. ### Parameters * **clock** (_terrainbento Clock instance_) – The clock controlling the simulation time. * **grid** (_landlab model grid instance_) – The grid must have all required fields. * **m_sp** (_float_, optional) – Drainage area exponent (m). Defaults to 0.5. * **n_sp** (_float_, optional) – Slope exponent (n). Defaults to 1.0. * **water_erodibility** (_float_, optional) – Water erodibility (K). Defaults to 0.0001. * **regolith_transport_parameter** (_float_, optional) – Regolith transport efficiency (D). Defaults to 0.1. * **soil_production__maximum_rate** (_float_, optional) – Maximum rate of soil production (P0). Defaults to 0.001. * **soil_production__decay_depth** (_float_, optional) – Decay depth for soil production (Hs). Defaults to 0.5. * **soil_transport_decay_depth** (_float_, optional) – Decay depth for soil transport (H0). Defaults to 0.5. * **kwargs** – Keyword arguments to pass to `ErosionModel`. These specify the precipitator and runoff generator. ### Returns * **BasicSa** – An instance of the BasicSa model object. ### Example ```python from landlab import RasterModelGrid from landlab.values import random from terrainbento import Clock, BasicSa clock = Clock(start=0, stop=100, step=1) grid = RasterModelGrid((5,5)) _ = random(grid, "topographic__elevation") _ = random(grid, "soil__depth") model = BasicSa(clock, grid) ``` ```