def test_assertion_error(): """Test that the correct assertion error will be raised.""" mg = RasterModelGrid(10, 10) z = mg.add_zeros('topographic__elevation', at='node') z += 200 + mg.x_of_node + mg.y_of_node + np.random.randn(mg.size('node')) mg.set_closed_boundaries_at_grid_edges(bottom_is_closed=True, left_is_closed=True, right_is_closed=True, top_is_closed=True) mg.set_watershed_boundary_condition_outlet_id(0, z, -9999) fa = FlowAccumulator(mg, depression_finder=DepressionFinderAndRouter) sp = FastscapeEroder(mg, K_sp=.0001, m_sp=.5, n_sp=1) ld = LinearDiffuser(mg, linear_diffusivity=0.0001) dt = 100 for i in range(200): fa.run_one_step() flooded = np.where(fa.depression_finder.flood_status == 3)[0] sp.run_one_step(dt=dt, flooded_nodes=flooded) ld.run_one_step(dt=dt) mg.at_node['topographic__elevation'][0] -= 0.001 # Uplift assert_raises(AssertionError, analyze_channel_network_and_plot, mg, threshold=100, starting_nodes=[0], number_of_channels=2)
def test_assertion_error(): """Test that the correct assertion error will be raised.""" mg = RasterModelGrid(10, 10) z = mg.add_zeros('topographic__elevation', at='node') z += 200 + mg.x_of_node + mg.y_of_node + np.random.randn(mg.size('node')) mg.set_closed_boundaries_at_grid_edges(bottom_is_closed=True, left_is_closed=True, right_is_closed=True, top_is_closed=True) mg.set_watershed_boundary_condition_outlet_id(0, z, -9999) fa = FlowAccumulator(mg, flow_director='D8', depression_finder=DepressionFinderAndRouter) sp = FastscapeEroder(mg, K_sp=.0001, m_sp=.5, n_sp=1) ld = LinearDiffuser(mg, linear_diffusivity=0.0001) dt = 100 for i in range(200): fa.run_one_step() flooded = np.where(fa.depression_finder.flood_status==3)[0] sp.run_one_step(dt=dt, flooded_nodes=flooded) ld.run_one_step(dt=dt) mg.at_node['topographic__elevation'][0] -= 0.001 # Uplift assert_raises(AssertionError, analyze_channel_network_and_plot, mg, threshold = 100, starting_nodes = [0], number_of_channels=2)
def test_assertion_error(): """Test that the correct assertion error will be raised.""" mg = RasterModelGrid((10, 10)) z = mg.add_zeros("topographic__elevation", at="node") z += 200 + mg.x_of_node + mg.y_of_node + np.random.randn(mg.size("node")) mg.set_closed_boundaries_at_grid_edges( bottom_is_closed=True, left_is_closed=True, right_is_closed=True, top_is_closed=True, ) mg.set_watershed_boundary_condition_outlet_id(0, z, -9999) fa = FlowAccumulator(mg, flow_director="D8", depression_finder=DepressionFinderAndRouter) sp = FastscapeEroder(mg, K_sp=0.0001, m_sp=0.5, n_sp=1, erode_flooded_nodes=True) ld = LinearDiffuser(mg, linear_diffusivity=0.0001) dt = 100 for i in range(200): fa.run_one_step() sp.run_one_step(dt=dt) ld.run_one_step(dt=dt) mg.at_node["topographic__elevation"][0] -= 0.001 # Uplift with pytest.raises(ValueError): ChannelProfiler(mg, outlet_nodes=[0], number_of_watersheds=2)
class BasicSt(_StochasticErosionModel): """ A StochasticHortonianSPModel generates a random sequency of runoff events across a topographic surface, calculating the resulting water discharge at each node. """ def __init__(self, input_file=None, params=None, BaselevelHandlerClass=None): """Initialize the StochasticDischargeHortonianModel.""" # Call ErosionModel's init super(BasicSt, self).__init__(input_file=input_file, params=params, BaselevelHandlerClass=BaselevelHandlerClass) # Get Parameters: K_sp = self.get_parameter_from_exponent('K_stochastic_sp', raise_error=False) K_ss = self.get_parameter_from_exponent('K_stochastic_ss', raise_error=False) linear_diffusivity = ( self._length_factor**2.) * self.get_parameter_from_exponent( 'linear_diffusivity') # has units length^2/time # check that a stream power and a shear stress parameter have not both been given if K_sp != None and K_ss != None: raise ValueError('A parameter for both K_sp and K_ss has been' 'provided. Only one of these may be provided') elif K_sp != None or K_ss != None: if K_sp != None: K = K_sp else: K = ( self._length_factor**(1. / 2.) ) * K_ss # K_stochastic has units Lengtg^(1/2) per Time^(1/2_ else: raise ValueError('A value for K_sp or K_ss must be provided.') # Instantiate a FlowAccumulator with DepressionFinderAndRouter using D8 method self.flow_router = FlowAccumulator( self.grid, flow_director='D8', depression_finder=DepressionFinderAndRouter) # instantiate rain generator self.instantiate_rain_generator() # Add a field for discharge if 'surface_water__discharge' not in self.grid.at_node: self.grid.add_zeros('node', 'surface_water__discharge') self.discharge = self.grid.at_node['surface_water__discharge'] # Get the infiltration-capacity parameter infiltration_capacity = (self._length_factor) * self.params[ 'infiltration_capacity'] # has units length per time self.infilt = infiltration_capacity # Keep a reference to drainage area self.area = self.grid.at_node['drainage_area'] # Run flow routing and lake filler self.flow_router.run_one_step() # Instantiate a FastscapeEroder component self.eroder = FastscapeEroder(self.grid, K_sp=K, m_sp=self.params['m_sp'], n_sp=self.params['n_sp']) # Instantiate a LinearDiffuser component self.diffuser = LinearDiffuser(self.grid, linear_diffusivity=linear_diffusivity) def calc_runoff_and_discharge(self): """Calculate runoff rate and discharge; return runoff.""" if self.rain_rate > 0.0 and self.infilt > 0.0: runoff = self.rain_rate - ( self.infilt * (1.0 - np.exp(-self.rain_rate / self.infilt))) if runoff < 0: runoff = 0 else: runoff = self.rain_rate self.discharge[:] = runoff * self.area return runoff def run_one_step(self, dt): """ Advance model for one time-step of duration dt. """ # Route flow self.flow_router.run_one_step() # Get IDs of flooded nodes, if any flooded = np.where( self.flow_router.depression_finder.flood_status == 3)[0] # Handle water erosion self.handle_water_erosion(dt, flooded) # Do some soil creep self.diffuser.run_one_step(dt) # update model time self.model_time += dt # Lower outlet self.update_outlet(dt) # Check walltime self.check_walltime()
print("---------------------") #Create incremental counter for controlling progress of mainloop counter = 0 #Create Limits for DHDT plot. Move this somewhere else later.. DHDTLowLim = upliftRate - (upliftRate * 1) DHDTHighLim = upliftRate + (upliftRate * 1) while elapsed_time < totalT: #create copy of "old" topography z0 = mg.at_node['topographic__elevation'].copy() #Call the erosion routines. #expw.run_one_step(dt=dt) #dld.run_one_step(dt=dt) ld.run_one_step(dt=dt) fr.run_one_step() lm.map_depressions() floodedNodes = np.where(lm.flood_status==3)[0] fc.run_one_step(dt=dt, flooded_nodes = floodedNodes) mg.at_node['topographic__elevation'][mg.core_nodes] += uplift_per_step #add uplift mg.at_node['bedrock__elevation'][mg.core_nodes] += uplift_per_step #add uplift #look for nodes where river incises below current soil thickness bad_nodes = mg.at_node['topographic__elevation'] < mg.at_node['bedrock__elevation'] #redefine bedrock to current channel elevation mg.at_node['bedrock__elevation'][bad_nodes] = mg.at_node['topographic__elevation'][bad_nodes] #calculate drainage_density channel_mask = mg.at_node['drainage_area'] > critArea dd = drainage_density.DrainageDensity(mg, channel__mask = channel_mask)
class BasicRtVs(ErosionModel): """ A BasicVsRt computes erosion using linear diffusion, basic stream power with 2 lithologies, and Q ~ A exp( -b S / A). """ def __init__(self, input_file=None, params=None, BaselevelHandlerClass=None): """Initialize the BasicVsRt.""" # Call ErosionModel's init super(BasicVsRt, self).__init__(input_file=input_file, params=params, BaselevelHandlerClass=BaselevelHandlerClass) contact_zone__width = (self._length_factor) * self.params[ 'contact_zone__width'] # has units length self.K_rock_sp = self.get_parameter_from_exponent('K_rock_sp') self.K_till_sp = self.get_parameter_from_exponent('K_till_sp') linear_diffusivity = ( self._length_factor** 2.) * self.get_parameter_from_exponent('linear_diffusivity') recharge_rate = (self._length_factor) * self.params[ 'recharge_rate'] # has units length per time soil_thickness = (self._length_factor) * self.params[ 'initial_soil_thickness'] # has units length K_hydraulic_conductivity = (self._length_factor) * self.params[ 'K_hydraulic_conductivity'] # has units length per time # Set up rock-till self.setup_rock_and_till(self.params['rock_till_file__name'], self.K_rock_sp, self.K_till_sp, contact_zone__width) # Instantiate a FlowAccumulator with DepressionFinderAndRouter using D8 method self.flow_router = FlowAccumulator( self.grid, flow_director='D8', depression_finder=DepressionFinderAndRouter) # Add a field for effective drainage area if 'effective_drainage_area' in self.grid.at_node: self.eff_area = self.grid.at_node['effective_drainage_area'] else: self.eff_area = self.grid.add_zeros('node', 'effective_drainage_area') # Get the effective-area parameter self.sat_param = (K_hydraulic_conductivity * soil_thickness * self.grid.dx) / (recharge_rate) # Instantiate a FastscapeEroder component self.eroder = StreamPowerEroder(self.grid, K_sp=self.erody, m_sp=self.params['m_sp'], n_sp=self.params['n_sp'], use_Q=self.eff_area) # Instantiate a LinearDiffuser component self.diffuser = LinearDiffuser(self.grid, linear_diffusivity=linear_diffusivity) def calc_effective_drainage_area(self): """Calculate and store effective drainage area. Effective drainage area is defined as: $A_{eff} = A \exp ( \alpha S / A) = A R_r$ where $S$ is downslope-positive steepest gradient, $A$ is drainage area, $R_r$ is the runoff ratio, and $\alpha$ is the saturation parameter. """ area = self.grid.at_node['drainage_area'] slope = self.grid.at_node['topographic__steepest_slope'] cores = self.grid.core_nodes self.eff_area[cores] = ( area[cores] * (np.exp(-self.sat_param * slope[cores] / area[cores]))) def setup_rock_and_till(self, file_name, rock_erody, till_erody, contact_width): """Set up lithology handling for two layers with different erodibility. Parameters ---------- file_name : string Name of arc-ascii format file containing elevation of contact position at each grid node (or NODATA) Read elevation of rock-till contact from an esri-ascii format file containing the basal elevation value at each node, create a field for erodibility. Some considerations here: 1. We could represent the contact between two layers either as a depth below present land surface, or as an altitude. Using a depth would allow for vertical motion, because for a fixed surface, the depth remains constant while the altitude changes. But the depth must be updated every time the surface is eroded or aggrades. Using an altitude avoids having to update the contact position every time the surface erodes or aggrades, but any tectonic motion would need to be applied to the contact position as well. Here we'll use the altitude approach because this model was originally written for an application with lots of erosion expected but no tectonics. """ from landlab.io import read_esri_ascii # Read input data on rock-till contact elevation read_esri_ascii(file_name, grid=self.grid, name='rock_till_contact__elevation', halo=1) # Get a reference to the rock-till field self.rock_till_contact = self.grid.at_node[ 'rock_till_contact__elevation'] # Create field for erodibility if 'substrate__erodibility' in self.grid.at_node: self.erody = self.grid.at_node['substrate__erodibility'] else: 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) # Read the erodibility value of rock and till self.rock_erody = rock_erody self.till_erody = till_erody # Read and remember the contact zone characteristic width self.contact_width = contact_width def update_erodibility_field(self): """Update erodibility at each node based on elevation relative to contact elevation. To promote smoothness in the solution, the erodibility at a given point (x,y) is set as follows: 1. Take the difference between elevation, z(x,y), and contact elevation, b(x,y): D(x,y) = z(x,y) - b(x,y). This number could be positive (if land surface is above the contact), negative (if we're well within the rock), or zero (meaning the rock-till contact is right at the surface). 2. Define a smoothing function as: $F(D) = 1 / (1 + exp(-D/D*))$ This sigmoidal function has the property that F(0) = 0.5, F(D >> D*) = 1, and F(-D << -D*) = 0. Here, D* describes the characteristic width of the "contact zone", where the effective erodibility is a mixture of the two. If the surface is well above this contact zone, then F = 1. If it's well below the contact zone, then F = 0. 3. Set the erodibility using F: $K = F K_till + (1-F) K_rock$ So, as F => 1, K => K_till, and as F => 0, K => K_rock. In between, we have a weighted average. Translating these symbols into variable names: z = self.elev b = self.rock_till_contact D* = self.contact_width F = self.erody_wt K_till = self.till_erody K_rock = self.rock_erody """ # Update the erodibility weighting function (this is "F") core = self.grid.core_nodes if self.contact_width > 0.0: self.erody_wt[core] = ( 1.0 / (1.0 + np.exp(-(self.z[core] - self.rock_till_contact[core]) / self.contact_width))) else: self.erody_wt[core] = 0.0 self.erody_wt[np.where(self.z > self.rock_till_contact)[0]] = 1.0 # (if we're varying K through time, update that first) if self.opt_var_precip: erode_factor = self.pc.get_erodibility_adjustment_factor( self.model_time) self.till_erody = self.K_till_sp * erode_factor self.rock_erody = self.K_rock_sp * erode_factor # Calculate the effective erodibilities using weighted averaging self.erody[:] = (self.erody_wt * self.till_erody + (1.0 - self.erody_wt) * self.rock_erody) def run_one_step(self, dt): """ Advance model for one time-step of duration dt. """ # Route flow self.flow_router.run_one_step() # Update effective runoff ratio self.calc_effective_drainage_area() # Zero out effective area in flooded nodes self.eff_area[self.flow_router.depression_finder.flood_status == 3] = 0.0 # Update the erodibility field self.update_erodibility_field() # Do some erosion (but not on the flooded nodes) self.eroder.run_one_step(dt) # Do some soil creep self.diffuser.run_one_step(dt) # calculate model time self.model_time += dt # Lower outlet self.update_outlet(dt) # Check walltime self.check_walltime()
class BasicRtVs(TwoLithologyErosionModel): r"""**BasicRtVs** model program. This model program combines the :py:class:`BasicRt` and :py:class:`BasicVs` programs by allowing for two lithologies, an "upper" layer and a "lower" layer, and using discharge proportional to effective drainage area based on variable source area hydrology. Given a spatially varying contact zone elevation, :math:`\eta_C(x,y))`, model **BasicRtVs** evolves a topographic surface described by :math:`\eta` with the following governing equations: .. math:: \frac{\partial \eta}{\partial t} = - K(\eta,\eta_C) A_{eff}^{m}S^{n} + D\nabla^2 \eta K(\eta, \eta_C ) = w K_1 + (1 - w) K_2 w = \frac{1}{1+\exp \left( -\frac{(\eta -\eta_C )}{W_c}\right)} A_{eff} = A \exp \left( -\frac{-\alpha S}{A}\right) \alpha = \frac{K_{sat} dx }{R_m} where :math:`Q` is the local stream discharge, :math:`S` is the local slope, :math:`m` and :math:`n` are the discharge and slope exponent parameters, :math:`W_c` is the contact-zone width, :math:`K_1` and :math:`K_2` are the erodabilities of the upper and lower lithologies, and :math:`D` is the regolith transport parameter. :math:`\alpha` is the saturation area scale used for transforming area into effective area and it is given as a function of the saturated hydraulic conductivity :math:`K_{sat}`, the soil thickness :math:`H`, the grid spacing :math:`dx`, and the recharge rate, :math:`R_m`. :math:`w` is a weight used to calculate the effective erodibility :math:`K(\eta, \eta_C)` based on the depth to the contact zone and the width of the contact zone. The weight :math:`w` promotes smoothness in the solution of erodibility at a given point. When the surface elevation is at the contact elevation, the erodibility is the average of :math:`K_1` and :math:`K_2`; above and below the contact, the erodibility approaches the value of :math:`K_1` and :math:`K_2` at a rate related to the contact zone width. Thus, to make a very sharp transition, use a small value for the contact zone width. Refer to `Barnhart et al. (2019) <https://doi.org/10.5194/gmd-12-1267-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`` - ``lithology_contact__elevation`` - ``soil__depth`` """ _required_fields = [ "topographic__elevation", "lithology_contact__elevation", "soil__depth", ] def __init__(self, clock, grid, hydraulic_conductivity=0.1, **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_upper : float, optional Water erodibility of the upper layer (:math:`K_{1}`). Default is 0.001. water_erodibility_lower : float, optional Water erodibility of the upper layer (:math:`K_{2}`). Default is 0.0001. contact_zone__width : float, optional Thickness of the contact zone (:math:`W_c`). Default is 1. regolith_transport_parameter : float, optional Regolith transport efficiency (:math:`D`). Default is 0.1. hydraulic_conductivity : float, optional Hydraulic conductivity (:math:`K_{sat}`). Default is 0.1. **kwargs : Keyword arguments to pass to :py:class:`TwoLithologyErosionModel`. Importantly these arguments specify the precipitator and the runoff generator that control the generation of surface water discharge (:math:`Q`). Returns ------- BasicRtVs : model object Examples -------- This is a minimal example to demonstrate how to construct an instance of model **BasicRtVs**. For more detailed examples, including steady-state test examples, see the terrainbento tutorials. To begin, import the model class. >>> 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.) Construct the model. >>> model = BasicRtVs(clock, grid) Running the model with ``model.run()`` would create output, so here we will just run it one step. >>> model.run_one_step(1.) >>> model.model_time 1.0 """ # Call ErosionModel"s init super(BasicRtVs, self).__init__(clock, grid, **kwargs) # ensure Precipitator and RunoffGenerator are vanilla self._ensure_precip_runoff_are_vanilla() # verify correct fields are present. self._verify_fields(self._required_fields) # Set up rock-till boundary and associated grid fields. self._setup_rock_and_till() # Get the effective-area parameter self._Kdx = hydraulic_conductivity * self.grid.dx # Instantiate a FastscapeEroder component self.eroder = FastscapeEroder( self.grid, K_sp=self.erody, m_sp=self.m, n_sp=self.n, discharge_name="surface_water__discharge", ) # Instantiate a LinearDiffuser component self.diffuser = LinearDiffuser( self.grid, linear_diffusivity=self.regolith_transport_parameter ) def _calc_effective_drainage_area(self): r"""Calculate and store effective drainage area. Effective drainage area is defined as: .. math:: A_{eff} = A \exp ( \alpha S / A) = A R_r where :math:`S` is downslope-positive steepest gradient, :math:`A` is drainage area, :math:`R_r` is the runoff ratio, and :math:`\alpha` is the saturation parameter. """ area = self.grid.at_node["drainage_area"] slope = self.grid.at_node["topographic__steepest_slope"] cores = self.grid.core_nodes sat_param = ( self._Kdx * self.grid.at_node["soil__depth"] / self.grid.at_node["rainfall__flux"] ) eff_area = area[cores] * ( np.exp(-sat_param[cores] * slope[cores] / area[cores]) ) self.grid.at_node["surface_water__discharge"][cores] = eff_area def run_one_step(self, step): """Advance model **BasicRtVs** for one time-step of duration step. The **run_one_step** method does the following: 1. Directs flow, accumulates drainage area, and calculates effective drainage area. 2. Assesses the location, if any, of flooded nodes where erosion should not occur. 3. Assesses if a :py:mod:`PrecipChanger` is an active boundary handler and if so, uses it to modify the erodibility by water. 4. Updates the spatially variable erodibility value based on the relative distance between the topographic surface and the lithology contact. 5. Calculates detachment-limited erosion by water. 6. Calculates topographic change by linear diffusion. 7. Finalizes the step using the :py:mod:`ErosionModel` base class function **finalize__run_one_step**. This function updates all boundary handlers handlers by ``step`` and increments model time by ``step``. Parameters ---------- step : float Increment of time for which the model is run. """ # create and move water self.create_and_move_water(step) # Update effective runoff ratio self._calc_effective_drainage_area() # Get IDs of flooded nodes, if any if self.flow_accumulator.depression_finder is None: flooded = [] else: flooded = np.where( self.flow_accumulator.depression_finder.flood_status == 3 )[0] # Zero out effective area in flooded nodes self.grid.at_node["surface_water__discharge"][flooded] = 0.0 # Update the erodibility field self._update_erodibility_field() # Do some erosion (but not on the flooded nodes) self.eroder.run_one_step(step) # Do some soil creep self.diffuser.run_one_step(step) # Finalize the run_one_step_method self.finalize__run_one_step(step)
class BasicRtTh(TwoLithologyErosionModel): r"""**BasicRtTh** model program. This model program combines the :py:class:`BasicRt` and :py:class:`BasicTh` programs by allowing for two lithologies, an "upper" layer and a "lower" layer, and permitting the use of an smooth erosion threshold for each lithology. Given a spatially varying contact zone elevation, :math:`\eta_C(x,y))`, model **BasicRtTh** evolves a topographic surface described by :math:`\eta` with the following governing equations: .. math:: \frac{\partial \eta}{\partial t} = -\left[\omega - \omega_c (1 - e^{-\omega /\omega_c}) \right] + D\nabla^2 \eta \omega = K(\eta, \eta_C) Q^{m} S^{n} K(\eta, \eta_C ) = w K_1 + (1 - w) K_2, \omega_c(\eta, \eta_C ) = w \omega_{c1} + (1 - w) \omega_{c2} w = \frac{1}{1+\exp \left( -\frac{(\eta -\eta_C )}{W_c}\right)} where :math:`Q` is the local stream discharge, :math:`S` is the local slope, :math:`m` and :math:`n` are the discharge and slope exponent parameters, :math:`W_c` is the contact-zone width, :math:`K_1` and :math:`K_2` are the erodabilities of the upper and lower lithologies, :math:`\omega_{c1}` and :math:`\omega_{c2}` are the erosion thresholds of the upper and lower lithologies, and :math:`D` is the regolith transport \parameter. :math:`w` is a weight used to calculate the effective erodibility :math:`K(\eta, \eta_C)` based on the depth to the contact zone and the width of the contact zone. :math:`\omega` is the erosion rate that would be calculated without the use of a threshold and as the threshold increases the erosion rate smoothly transitions between zero and :math:`\omega`. The weight :math:`w` promotes smoothness in the solution of erodibility at a given point. When the surface elevation is at the contact elevation, the erodibility is the average of :math:`K_1` and :math:`K_2`; above and below the contact, the erodibility approaches the value of :math:`K_1` and :math:`K_2` at a rate related to the contact zone width. Thus, to make a very sharp transition, use a small value for the contact zone width. Refer to `Barnhart et al. (2019) <https://doi.org/10.5194/gmd-12-1267-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`` - ``lithology_contact__elevation`` """ _required_fields = [ "topographic__elevation", "lithology_contact__elevation", ] def __init__( self, clock, grid, water_erosion_rule_upper__threshold=1.0, water_erosion_rule_lower__threshold=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_upper : float, optional Water erodibility of the upper layer (:math:`K_{1}`). Default is 0.001. water_erodibility_lower : float, optional Water erodibility of the upper layer (:math:`K_{2}`). Default is 0.0001. water_erosion_rule_upper__threshold : float, optional. Erosion threshold of the upper layer (:math:`\omega_{c1}`). Default is 1. water_erosion_rule_lower__threshold: float, optional. Erosion threshold of the upper layer (:math:`\omega_{c2}`). Default is 1. contact_zone__width : float, optional Thickness of the contact zone (:math:`W_c`). Default is 1. regolith_transport_parameter : float, optional Regolith transport efficiency (:math:`D`). Default is 0.1. **kwargs : Keyword arguments to pass to :py:class:`TwoLithologyErosionModel`. Importantly these arguments specify the precipitator and the runoff generator that control the generation of surface water discharge (:math:`Q`). Returns ------- BasicRtTh : model object Examples -------- This is a minimal example to demonstrate how to construct an instance of model **BasicRtTh**. For more detailed examples, including steady-state test examples, see the terrainbento tutorials. To begin, import the model class. >>> 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.) Construct the model. >>> model = BasicRtTh(clock, grid) Running the model with ``model.run()`` would create output, so here we will just run it one step. >>> model.run_one_step(1.) >>> model.model_time 1.0 """ # Call ErosionModel"s init super(BasicRtTh, self).__init__(clock, grid, **kwargs) if float(self.n) != 1.0: raise ValueError("Model only supports n equals 1.") # verify correct fields are present. self._verify_fields(self._required_fields) # Save the threshold values for rock and till self.rock_thresh = water_erosion_rule_lower__threshold self.till_thresh = water_erosion_rule_upper__threshold # Set up rock-till boundary and associated grid fields. self._setup_rock_and_till_with_threshold() # Instantiate a StreamPowerSmoothThresholdEroder component self.eroder = StreamPowerSmoothThresholdEroder( self.grid, K_sp=self.erody, threshold_sp=self.threshold, m_sp=self.m, n_sp=self.n, use_Q="surface_water__discharge", ) # Instantiate a LinearDiffuser component self.diffuser = LinearDiffuser( self.grid, linear_diffusivity=self.regolith_transport_parameter ) def run_one_step(self, step): """Advance model **BasicRtTh** for one time-step of duration step. The **run_one_step** method does the following: 1. Creates rain and runoff, then directs and accumulates flow. 2. Assesses the location, if any, of flooded nodes where erosion should not occur. 3. Assesses if a :py:mod:`PrecipChanger` is an active boundary handler and if so, uses it to modify the erodibility by water. 4. Updates the spatially variable erodibility and threshold values based on the relative distance between the topographic surface and the lithology contact. 5. Calculates detachment-limited erosion by water. 6. Calculates topographic change by linear diffusion. 7. Finalizes the step using the :py:mod:`ErosionModel` base class function **finalize__run_one_step**. This function updates all boundary handlers handlers by ``step`` and increments model time by ``step``. Parameters ---------- step : float Increment of time for which the model is run. """ # create and move water self.create_and_move_water(step) # Get IDs of flooded nodes, if any if self.flow_accumulator.depression_finder is None: flooded = [] else: flooded = np.where( self.flow_accumulator.depression_finder.flood_status == 3 )[0] # Update the erodibility and threshold field self._update_erodibility_and_threshold_fields() # Do some erosion (but not on the flooded nodes) self.eroder.run_one_step(step, flooded_nodes=flooded) # Do some soil creep self.diffuser.run_one_step(step) # Finalize the run_one_step_method self.finalize__run_one_step(step)
class BasicCv(ErosionModel): """ A BasicCV computes erosion using linear diffusion, basic stream power, and Q~A. It also has basic climate change """ def __init__(self, input_file=None, params=None, BaselevelHandlerClass=None): """Initialize the BasicCv model.""" # Call ErosionModel's init super(BasicCv, self).__init__(input_file=input_file, params=params, BaselevelHandlerClass=BaselevelHandlerClass) K_sp = self.get_parameter_from_exponent('K_sp') linear_diffusivity = ( self._length_factor** 2.) * self.get_parameter_from_exponent('linear_diffusivity') self.climate_factor = self.params['climate_factor'] self.climate_constant_date = self.params['climate_constant_date'] time = [0, self.climate_constant_date, self.params['run_duration']] K = [K_sp * self.climate_factor, K_sp, K_sp] self.K_through_time = interp1d(time, K) # Instantiate a FlowAccumulator with DepressionFinderAndRouter using D8 method self.flow_router = FlowAccumulator( self.grid, flow_director='D8', depression_finder=DepressionFinderAndRouter) # Instantiate a FastscapeEroder component self.eroder = FastscapeEroder(self.grid, K_sp=K[0], m_sp=self.params['m_sp'], n_sp=self.params['n_sp']) # Instantiate a LinearDiffuser component self.diffuser = LinearDiffuser(self.grid, linear_diffusivity=linear_diffusivity) def run_one_step(self, dt): """ Advance model for one time-step of duration dt. """ # Route flow self.flow_router.run_one_step() # Get IDs of flooded nodes, if any flooded = np.where( self.flow_router.depression_finder.flood_status == 3)[0] # Update erosion based on climate self.eroder.K = float(self.K_through_time(self.model_time)) # Do some erosion (but not on the flooded nodes) self.eroder.run_one_step(dt, flooded_nodes=flooded) # Do some soil creep self.diffuser.run_one_step(dt) # calculate model time self.model_time += dt # Lower outlet self.update_outlet(dt) # Check walltime self.check_walltime()
# This lets you know what event number you are at. print ("Storm #", i, " Duration: ", round(durations[i], 2), " Intensity: ", round(intensities[i], 2), " Time in loop: ", round(end-start, 2), "seconds") # Updating total depth of the time series depth += (durations[i]*intensities[i]) # uplifting over the whole storm and interstorm rmg['node']['topographic__elevation'][rmg.core_nodes] += uplift_rate * new_dt rmg1['node']['topographic__elevation'][rmg1.core_nodes] += uplift_rate * new_dt rmg5['node']['topographic__elevation'][rmg5.core_nodes] += uplift_rate * new_dt rmg10['node']['topographic__elevation'][rmg10.core_nodes] += uplift_rate * new_dt lin_diffuse.run_one_step(dt = new_dt) lin_diffuse1.run_one_step(dt = new_dt) lin_diffuse5.run_one_step(dt = new_dt) lin_diffuse10.run_one_step(dt = new_dt) real_time_list.append(round(end - start, 2)) # Keeping track of erosion rates and discharges at the study locations # For each of the tau_c values sampled_peak_discharges.append(peak_Q[sample_das]) sampled_erosion_rates.append(np.amax(np.abs(incision_rate_at_sampling_sites), axis=0)) sampled_erosion_rates1.append(np.amax(np.abs(incision_rate_at_sampling_sites1), axis=0)) sampled_erosion_rates5.append(np.amax(np.abs(incision_rate_at_sampling_sites5), axis=0)) sampled_erosion_rates10.append(np.amax(np.abs(incision_rate_at_sampling_sites10), axis=0)) # These "i" values represent the events where rainfall hits 1 m, 2.5 m,
class BasicHySt(StochasticErosionModel): """ A BasicHySt computes erosion using (1) hybrid alluvium river erosion, (2) linear nhillslope diffusion, and (3) generation of a random sequence of runoff events across a topographic surface. Examples -------- >>> from erosion_model import StochasticRainDepthDepThresholdModel >>> my_pars = {} >>> my_pars['dt'] = 1.0 >>> my_pars['run_duration'] = 1.0 >>> my_pars['infiltration_capacity'] = 1.0 >>> my_pars['K_sp'] = 1.0 >>> my_pars['threshold_sp'] = 1.0 >>> my_pars['linear_diffusivity'] = 0.01 >>> my_pars['mean_storm_duration'] = 0.002 >>> my_pars['mean_interstorm_duration'] = 0.008 >>> my_pars['mean_storm_depth'] = 0.025 >>> srt = StochasticRainDepthDepThresholdModel(params=my_pars) Warning: no DEM specified; creating 4x5 raster grid """ def __init__(self, input_file=None, params=None, BaselevelHandlerClass=None): """Initialize the BasicHySt.""" # Call ErosionModel's init super(BasicHySt, self).__init__(input_file=input_file, params=params, BaselevelHandlerClass=BaselevelHandlerClass) # Get Parameters: K = ((self._length_factor**0.5) # K_stochastic [=] L^(1/2) T^-(1/2) * self.get_parameter_from_exponent('K_stochastic_sp')) linear_diffusivity = ( (self._length_factor**2) * self.get_parameter_from_exponent('linear_diffusivity')) # L^2/T v_s = (self._length_factor) * self.get_parameter_from_exponent( 'v_s') # has units length per time # Instantiate a FlowAccumulator with DepressionFinderAndRouter using D8 method self.flow_router = FlowAccumulator( self.grid, flow_director='D8', depression_finder=DepressionFinderAndRouter) #set methods and fields. method = 'simple_stream_power' discharge_method = 'discharge_field' area_field = None discharge_field = 'surface_water__discharge' # instantiate rain generator self.instantiate_rain_generator() # Add a field for discharge if 'surface_water__discharge' not in self.grid.at_node: self.grid.add_zeros('node', 'surface_water__discharge') self.discharge = self.grid.at_node['surface_water__discharge'] # Get the infiltration-capacity parameter infiltration_capacity = (self._length_factor * self.params['infiltration_capacity']) # L/T self.infilt = infiltration_capacity # Run flow routing and lake filler self.flow_router.run_one_step() # Keep a reference to drainage area self.area = self.grid.at_node['drainage_area'] # Handle solver option try: solver = self.params['solver'] except: solver = 'original' # Instantiate an ErosionDeposition component self.eroder = ErosionDeposition(self.grid, K=K, F_f=self.params['F_f'], phi=self.params['phi'], v_s=v_s, m_sp=self.params['m_sp'], n_sp=self.params['n_sp'], method=method, discharge_method=discharge_method, area_field=area_field, discharge_field=discharge_field, solver=solver) # Instantiate a LinearDiffuser component self.diffuser = LinearDiffuser(self.grid, linear_diffusivity=linear_diffusivity) def calc_runoff_and_discharge(self): """Calculate runoff rate and discharge; return runoff.""" if self.rain_rate > 0.0 and self.infilt > 0.0: runoff = self.rain_rate - ( self.infilt * (1.0 - np.exp(-self.rain_rate / self.infilt))) if runoff < 0: runoff = 0 else: runoff = self.rain_rate self.discharge[:] = runoff * self.area return runoff def run_one_step(self, dt): """ Advance model for one time-step of duration dt. """ # Route flow self.flow_router.run_one_step() # Get IDs of flooded nodes, if any flooded = np.where( self.flow_router.depression_finder.flood_status == 3)[0] # Handle water erosion self.handle_water_erosion(dt, flooded) # Do some soil creep self.diffuser.run_one_step(dt) # calculate model time self.model_time += dt # Lower outlet self.update_outlet(dt) # Check walltime self.check_walltime()
class BasicHyRt(TwoLithologyErosionModel): r"""**BasicHyRt** model program. This model program combines the :py:class:`BasicRt` and :py:class:`BasicHy` programs by allowing for two lithologies, an "upper" layer and a "lower" layer, stream-power-driven sediment erosion and mass conservation. Given a spatially varying contact zone elevation, :math:`\eta_C(x,y))`, model **BasicHyRt** evolves a topographic surface described by :math:`\eta` with the following governing equations: .. math:: \frac{\partial \eta}{\partial t} = \frac{V Q_s}{Q} - K Q^{m}S^{n} + D\nabla^2 \eta Q_s = \int_0^A \left((1-F_f)KQ(A)^{m}S^{n} - \frac{V Q_s}{Q(A)} \right) dA K(\eta, \eta_C ) = w K_1 + (1 - w) K_2 w = \frac{1}{1+\exp \left( -\frac{(\eta -\eta_C )}{W_c}\right)} where :math:`Q` is the local stream discharge, :math:`A` is the local upstream drainage area, :math:`S` is the local slope, :math:`m` and :math:`n` are the discharge and slope exponen parameters, :math:`W_c` is the contact-zone width, :math:`K_1` and :math:`K_2` are the erodabilities of the upper and lower lithologies, and :math:`D` is the regolith transport parameter. :math:`Q_s` is the volumetric sediment discharge, and :math:`V` is the effective settling velocity of the sediment. :math:`w` is a weight used to calculate the effective erodibility :math:`K(\eta, \eta_C)` based on the depth to the contact zone and the width of the contact zone. The weight :math:`w` promotes smoothness in the solution of erodibility at a given point. When the surface elevation is at the contact elevation, the erodibility is the average of :math:`K_1` and :math:`K_2`; above and below the contact, the erodibility approaches the value of :math:`K_1` and :math:`K_2` at a rate related to the contact zone width. Thus, to make a very sharp transition, use a small value for the contact zone width. Refer to `Barnhart et al. (2019) <https://doi.org/10.5194/gmd-12-1267-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`` - ``lithology_contact__elevation`` """ _required_fields = [ "topographic__elevation", "lithology_contact__elevation", ] def __init__(self, clock, grid, solver="basic", settling_velocity=0.001, fraction_fines=0.5, **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_upper : float, optional Water erodibility of the upper layer (:math:`K_{1}`). Default is 0.001. water_erodibility_lower : float, optional Water erodibility of the upper layer (:math:`K_{2}`). Default is 0.0001. contact_zone__width : float, optional Thickness of the contact zone (:math:`W_c`). Default is 1. regolith_transport_parameter : float, optional Regolith transport efficiency (:math:`D`). Default is 0.1. settling_velocity : float, optional Settling velocity of entrained sediment (:math:`V`). Default is 0.001. fraction_fines : float, optional Fraction of fine sediment that is permanently detached (:math:`F_f`). Default is 0.5. solver : str, optional Solver option to pass to the Landlab `ErosionDeposition <https://landlab.readthedocs.io/en/master/reference/components/erosion_deposition.html>`__ component. Default is "basic". **kwargs : Keyword arguments to pass to :py:class:`TwoLithologyErosionModel`. Importantly these arguments specify the precipitator and the runoff generator that control the generation of surface water discharge (:math:`Q`). Returns ------- BasicHyRt : model object Examples -------- This is a minimal example to demonstrate how to construct an instance of model **BasicHyRt**. For more detailed examples, including steady-state test examples, see the terrainbento tutorials. To begin, import the model class. >>> from landlab import RasterModelGrid >>> from landlab.values import random, constant >>> from terrainbento import Clock, BasicHyRt >>> clock = Clock(start=0, stop=100, step=1) >>> grid = RasterModelGrid((5,5)) >>> _ = random(grid, "topographic__elevation") >>> _ = constant(grid, "lithology_contact__elevation", value=-10.) Construct the model. >>> model = BasicHyRt(clock, grid) Running the model with ``model.run()`` would create output, so here we will just run it one step. >>> model.run_one_step(1.) >>> model.model_time 1.0 """ # If needed, issue warning on porosity if "sediment_porosity" in kwargs: msg = "sediment_porosity is no longer used by BasicHyRt." raise ValueError(msg) # Call ErosionModel"s init super().__init__(clock, grid, **kwargs) # verify correct fields are present. self._verify_fields(self._required_fields) # Save the threshold values for rock and till self.rock_thresh = 0.0 self.till_thresh = 0.0 # Set up rock-till boundary and associated grid fields. self._setup_rock_and_till_with_threshold() # Instantiate an ErosionDeposition ("hybrid") component self.eroder = ErosionDeposition( self.grid, K="substrate__erodibility", F_f=fraction_fines, v_s=settling_velocity, m_sp=self.m, n_sp=self.n, discharge_field="surface_water__discharge", solver=solver, ) # Instantiate a LinearDiffuser component self.diffuser = LinearDiffuser( self.grid, linear_diffusivity=self.regolith_transport_parameter) def run_one_step(self, step): """Advance model **BasicHyRt** for one time-step of duration step. The **run_one_step** method does the following: 1. Creates rain and runoff, then directs and accumulates flow. 2. Assesses the location, if any, of flooded nodes where erosion should not occur. 3. Assesses if a :py:mod:`PrecipChanger` is an active boundary handler and if so, uses it to modify the erodibility by water. 4. Updates the spatially variable erodibility value based on the relative distance between the topographic surface and the lithology contact. 5. Calculates detachment-limited erosion by water. 6. Calculates topographic change by linear diffusion. 7. Finalizes the step using the :py:mod:`ErosionModel` base class function **finalize__run_one_step**. This function updates all boundary handlers handlers by ``step`` and increments model time by ``step``. Parameters ---------- step : float Increment of time for which the model is run. """ # create and move water self.create_and_move_water(step) # Update the erodibility and threshold field self._update_erodibility_and_threshold_fields() # Do some erosion (but not on the flooded nodes) self.eroder.run_one_step(step) # Do some soil creep self.diffuser.run_one_step(step) # Finalize the run_one_step_method self.finalize__run_one_step(step)
class BasicDd(_ErosionModel): """ A BasicDd computes erosion using linear diffusion, stream power with a smoothed threshold that is proportional to depth, and Q~A. """ def __init__(self, input_file=None, params=None, BaselevelHandlerClass=None): """Initialize the BasicDd.""" # Call ErosionModel's init super(BasicDd, self).__init__(input_file=input_file, params=params, BaselevelHandlerClass=BaselevelHandlerClass) # Get Parameters and convert units if necessary: K_sp = self.get_parameter_from_exponent('K_sp', raise_error=False) K_ss = self.get_parameter_from_exponent('K_ss', raise_error=False) linear_diffusivity = ( self._length_factor**2.) * self.get_parameter_from_exponent( 'linear_diffusivity') # has units length^2/time # threshold has units of Length per Time which is what # StreamPowerSmoothThresholdEroder expects self.threshold_value = self._length_factor * self.get_parameter_from_exponent( 'erosion__threshold') # has units length/time # check that a stream power and a shear stress parameter have not both been given if K_sp != None and K_ss != None: raise ValueError('A parameter for both K_sp and K_ss has been' 'provided. Only one of these may be provided') elif K_sp != None or K_ss != None: if K_sp != None: self.K = K_sp else: self.K = (self._length_factor**( 1. / 3.)) * K_ss # K_ss has units Lengtg^(1/3) per Time else: raise ValueError('A value for K_sp or K_ss must be provided.') # Instantiate a FlowAccumulator with DepressionFinderAndRouter using D8 method self.flow_router = FlowAccumulator( self.grid, flow_director='D8', depression_finder=DepressionFinderAndRouter) # Create a field for the (initial) erosion threshold self.threshold = self.grid.add_zeros('node', 'erosion__threshold') self.threshold[:] = self.threshold_value # Instantiate a FastscapeEroder component self.eroder = StreamPowerSmoothThresholdEroder( self.grid, m_sp=self.params['m_sp'], n_sp=self.params['n_sp'], K_sp=self.K, threshold_sp=self.threshold) # Get the parameter for rate of threshold increase with erosion depth self.thresh_change_per_depth = self.params['thresh_change_per_depth'] # Instantiate a LinearDiffuser component self.diffuser = LinearDiffuser(self.grid, linear_diffusivity=linear_diffusivity) def update_erosion_threshold_values(self): """Updates the erosion threshold at each node based on cumulative erosion so far.""" # Set the erosion threshold. # # Note that a minus sign is used because cum ero depth is negative for # erosion, positive for deposition. # The second line handles the case where there is growth, in which case # we want the threshold to stay at its initial value rather than # getting smaller. cum_ero = self.grid.at_node['cumulative_erosion__depth'] cum_ero[:] = (self.z - self.grid.at_node['initial_topographic__elevation']) self.threshold[:] = (self.threshold_value - (self.thresh_change_per_depth * cum_ero)) self.threshold[self.threshold < self.threshold_value] = \ self.threshold_value def run_one_step(self, dt): """ Advance model for one time-step of duration dt. """ # Route flow self.flow_router.run_one_step() # Get IDs of flooded nodes, if any flooded = np.where( self.flow_router.depression_finder.flood_status == 3)[0] # Calculate the new threshold values given cumulative erosion self.update_erosion_threshold_values() # Do some erosion (but not on the flooded nodes) # (if we're varying K through time, update that first) if self.opt_var_precip: self.eroder.K = ( self.K * self.pc.get_erodibility_adjustment_factor(self.model_time)) self.eroder.run_one_step(dt, flooded_nodes=flooded) # Do some soil creep self.diffuser.run_one_step(dt) # calculate model time self.model_time += dt # Lower outlet self.update_outlet(dt) # Check walltime self.check_walltime()
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) <https://doi.org/10.5194/gmd-12-1267-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. To begin, import the model class. >>> 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") Construct the model. >>> model = BasicDdSt(clock, grid) Running the model with ``model.run()`` would create output, so here we will just run it one step. >>> model.run_one_step(1.) >>> model.model_time 1.0 """ # Call ErosionModel"s init super().__init__(clock, grid, **kwargs) # verify correct fields are present. self._verify_fields(self._required_fields) # Get Parameters: self.m = m_sp self.n = n_sp self.K = water_erodibility self.threshold_value = water_erosion_rule__threshold self.thresh_change_per_depth = ( water_erosion_rule__thresh_depth_derivative) self.infilt = infiltration_capacity if float(self.n) != 1.0: raise ValueError("Model only supports n equals 1.") # instantiate rain generator self.instantiate_rain_generator() # Run flow routing and lake filler self.flow_accumulator.run_one_step() # Create a field for the (initial) erosion threshold self.threshold = self.grid.add_zeros("node", "water_erosion_rule__threshold") self.threshold[:] = self.threshold_value # Instantiate a FastscapeEroder component self.eroder = StreamPowerSmoothThresholdEroder( self.grid, m_sp=self.m, n_sp=self.n, K_sp=self.K, discharge_field="surface_water__discharge", erode_flooded_nodes=self._erode_flooded_nodes, threshold_sp=self.threshold, ) # Instantiate a LinearDiffuser component self.diffuser = LinearDiffuser( self.grid, linear_diffusivity=regolith_transport_parameter) def update_threshold_field(self): """Update the threshold based on cumulative erosion depth.""" cum_ero = self.grid.at_node["cumulative_elevation_change"] cum_ero[:] = (self.z - self.grid.at_node["initial_topographic__elevation"]) self.threshold[:] = self.threshold_value - ( self.thresh_change_per_depth * cum_ero) self.threshold[ self.threshold < self.threshold_value] = self.threshold_value def _pre_water_erosion_steps(self): self.update_threshold_field() def run_one_step(self, step): """Advance model **BasicDdSt** for one time-step of duration step. The **run_one_step** method does the following: 1. Creates rain and runoff, then directs and accumulates flow. 2. Assesses the location, if any, of flooded nodes where erosion should not occur. 3. Assesses if a :py:mod:`PrecipChanger` is an active boundary handler and if so, uses it to modify the erodibility by water. 4. Calculates detachment-limited, threshold-modified erosion by water. 5. Calculates topographic change by linear diffusion. 6. Finalizes the step using the :py:mod:`ErosionModel` base class function **finalize__run_one_step**. This function updates all boundary handlers handlers by ``step`` and increments model time by ``step``. Parameters ---------- step : float Increment of time for which the model is run. """ # create and move water self.create_and_move_water(step) # Handle water erosion self.handle_water_erosion(step) # Do some soil creep self.diffuser.run_one_step(step) # Finalize the run_one_step_method self.finalize__run_one_step(step)
## First import what you need from landlab import HexModelGrid from landlab.components import LinearDiffuser from landlab.plot import imshow_grid from matplotlib import pyplot as plt ## Make a grid that is 50 by 50 with dx=dy=20. m, ## except that doesn't work for Hex! so make it 51 by 50 hmg1 = HexModelGrid(51, 50, 20.) ## Add elevation data to the grid. z1 = hmg1.add_ones('node', 'topographic__elevation') ## Instantiate linear diffusion object ld1 = LinearDiffuser(hmg1, linear_diffusivity=0.1) ## Set some variables rock_up_rate = 5e-4 #m/yr dt = 1000 # yr, time step rock_up_len = dt * rock_up_rate # m ## Time loop where the evolution happens. for i in range(1500): z1[hmg1.core_nodes] += rock_up_len #uplift only the core nodes ld1.run_one_step(dt) #diffusion happens ## Plot the topography to see what comes out. plt.figure(2) imshow_grid(hmg1, 'topographic__elevation') #need to run for about 2000 time steps, or 2,000,000 years to reach SSf
class BasicThRt(_ErosionModel): """ A BasicThRt computes erosion using linear diffusion, stream power with a smoothed threshold, Q~A, and two lithologies: rock and till. """ def __init__(self, input_file=None, params=None, BaselevelHandlerClass=None): """Initialize the BasicThRt.""" # Call ErosionModel's init super(BasicThRt, self).__init__(input_file=input_file, params=params, BaselevelHandlerClass=BaselevelHandlerClass) contact_zone__width = (self._length_factor)*self.params['contact_zone__width'] # has units length self.K_rock_sp = self.get_parameter_from_exponent('K_rock_sp') self.K_till_sp = self.get_parameter_from_exponent('K_till_sp') rock_erosion__threshold = self.get_parameter_from_exponent('rock_erosion__threshold') till_erosion__threshold = self.get_parameter_from_exponent('till_erosion__threshold') linear_diffusivity = (self._length_factor**2.)*self.get_parameter_from_exponent('linear_diffusivity') # Set up rock-till self.setup_rock_and_till(self.params['rock_till_file__name'], self.K_rock_sp, self.K_till_sp, rock_erosion__threshold, till_erosion__threshold, contact_zone__width) # Instantiate a FlowAccumulator with DepressionFinderAndRouter using D8 method self.flow_router = FlowAccumulator(self.grid, flow_director='D8', depression_finder = DepressionFinderAndRouter) # Instantiate a StreamPowerSmoothThresholdEroder component self.eroder = StreamPowerSmoothThresholdEroder(self.grid, K_sp=self.erody, threshold_sp=self.threshold, m_sp=self.params['m_sp'], n_sp=self.params['n_sp']) # Instantiate a LinearDiffuser component self.diffuser = LinearDiffuser(self.grid, linear_diffusivity = linear_diffusivity) def setup_rock_and_till(self, file_name, rock_erody, till_erody, rock_thresh, till_thresh, contact_width): """Set up lithology handling for two layers with different erodibility. Parameters ---------- file_name : string Name of arc-ascii format file containing elevation of contact position at each grid node (or NODATA) rock_erody : float Water erosion coefficient for bedrock till_erody : float Water erosion coefficient for till rock_thresh : float Water erosion threshold for bedrock till_thresh : float Water erosion threshold for till contact_width : float [L] Characteristic width of the interface zone between rock and till Read elevation of rock-till contact from an esri-ascii format file containing the basal elevation value at each node, create a field for erodibility. """ from landlab.io import read_esri_ascii # Read input data on rock-till contact elevation read_esri_ascii(file_name, grid=self.grid, name='rock_till_contact__elevation', halo=1) # Get a reference to the rock-till field self.rock_till_contact = self.grid.at_node['rock_till_contact__elevation'] # Create field for erodibility if 'substrate__erodibility' in self.grid.at_node: self.erody = self.grid.at_node['substrate__erodibility'] else: self.erody = self.grid.add_zeros('node', 'substrate__erodibility') # Create field for threshold values if 'erosion__threshold' in self.grid.at_node: self.threshold = self.grid.at_node['erosion__threshold'] else: self.threshold = self.grid.add_zeros('node', 'erosion__threshold') # Create array for erodibility weighting function self.erody_wt = np.zeros(self.grid.number_of_nodes) # Read the erodibility value of rock and till self.rock_erody = rock_erody self.till_erody = till_erody # Read the threshold values for rock and till self.rock_thresh = rock_thresh self.till_thresh = till_thresh # Read and remember the contact zone characteristic width self.contact_width = contact_width def update_erodibility_and_threshold_fields(self): """Update erodibility and threshold at each node based on elevation relative to contact elevation. To promote smoothness in the solution, the erodibility at a given point (x,y) is set as follows: 1. Take the difference between elevation, z(x,y), and contact elevation, b(x,y): D(x,y) = z(x,y) - b(x,y). This number could be positive (if land surface is above the contact), negative (if we're well within the rock), or zero (meaning the rock-till contact is right at the surface). 2. Define a smoothing function as: $F(D) = 1 / (1 + exp(-D/D*))$ This sigmoidal function has the property that F(0) = 0.5, F(D >> D*) = 1, and F(-D << -D*) = 0. Here, D* describes the characteristic width of the "contact zone", where the effective erodibility is a mixture of the two. If the surface is well above this contact zone, then F = 1. If it's well below the contact zone, then F = 0. 3. Set the erodibility using F: $K = F K_till + (1-F) K_rock$ So, as F => 1, K => K_till, and as F => 0, K => K_rock. In between, we have a weighted average. 4. Threshold values are set similarly. Translating these symbols into variable names: z = self.elev b = self.rock_till_contact D* = self.contact_width F = self.erody_wt K_till = self.till_erody K_rock = self.rock_erody """ # Update the erodibility weighting function (this is "F") self.erody_wt[self.data_nodes] = (1.0 / (1.0 + np.exp(-(self.z[self.data_nodes] - self.rock_till_contact[self.data_nodes]) / self.contact_width))) # (if we're varying K through time, update that first) if self.opt_var_precip: erode_factor = self.pc.get_erodibility_adjustment_factor(self.model_time) self.till_erody = self.K_till_sp * erode_factor self.rock_erody = self.K_rock_sp * erode_factor # Calculate the effective erodibilities using weighted averaging self.erody[:] = (self.erody_wt * self.till_erody + (1.0 - self.erody_wt) * self.rock_erody) # Calculate the effective thresholds using weighted averaging self.threshold[:] = (self.erody_wt * self.till_thresh + (1.0 - self.erody_wt) * self.rock_thresh) def run_one_step(self, dt): """ Advance model for one time-step of duration dt. """ # Route flow self.flow_router.run_one_step() # Get IDs of flooded nodes, if any flooded = np.where(self.flow_router.depression_finder.flood_status==3)[0] # Update the erodibility and threshold field self.update_erodibility_and_threshold_fields() # Do some erosion (but not on the flooded nodes) self.eroder.run_one_step(dt, flooded_nodes=flooded) # Do some soil creep self.diffuser.run_one_step(dt) # calculate model time self.model_time += dt # Lower outlet self.update_outlet(dt) # Check walltime self.check_walltime()
class BasicHy(ErosionModel): r"""**BasicHy** model program. **BasicHy** is a model program that evolves a topographic surface described by :math:`\eta` with the following governing equation: .. math:: \frac{\partial \eta}{\partial t} = \frac{V Q_s} {Q\left(1 - \phi \right)} - KQ^{m}S^{n} + D\nabla^2 \eta Q_s = \int_0^A \left((1-F_f)KQ(A)^{m}S^{n} - \frac{V Q_s}{Q(A)} \right) dA where :math:`Q` is the local stream discharge, :math:`A` is the local upstream drainage area,:math:`S` is the local slope, :math:`m` and :math:`n` are the discharge and slope exponent parameters, :math:`K` is the erodibility by water, :math:`V` is effective sediment settling velocity, :math:`Q_s` is volumetric sediment flux, :math:`r` is a runoff rate, :math:`\phi` is sediment porosity, and :math:`D` is the regolith transport efficiency. Refer to `Barnhart et al. (2019) <https://doi.org/10.5194/gmd-12-1267-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, settling_velocity=0.001, sediment_porosity=0.3, fraction_fines=0.5, solver="basic", **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. settling_velocity : float, optional Settling velocity of entrained sediment (:math:`V`). Default is 0.001. sediment_porosity : float, optional Sediment porosity (:math:`\phi`). Default is 0.3. fraction_fines : float, optional Fraction of fine sediment that is permanently detached (:math:`F_f`). Default is 0.5. solver : str, optional Solver option to pass to the Landlab `ErosionDeposition <https://landlab.readthedocs.io/en/latest/landlab.components.erosion_deposition.html>`__ component. Default is "basic". **kwargs : Keyword arguments to pass to :py:class:`ErosionModel`. Importantly these arguments specify the precipitator and the runoff generator that control the generation of surface water discharge (:math:`Q`). Returns ------- BasicHy : model object Examples -------- This is a minimal example to demonstrate how to construct an instance of model **BasicHy**. For more detailed examples, including steady-state test examples, see the terrainbento tutorials. To begin, import the model class. >>> from landlab import RasterModelGrid >>> from landlab.values import random >>> from terrainbento import Clock, BasicHy >>> clock = Clock(start=0, stop=100, step=1) >>> grid = RasterModelGrid((5,5)) >>> _ = random(grid, "topographic__elevation") Construct the model. >>> model = BasicHy(clock, grid) Running the model with ``model.run()`` would create output, so here we will just run it one step. >>> model.run_one_step(1.) >>> model.model_time 1.0 """ # Call ErosionModel"s init super(BasicHy, self).__init__(clock, grid, **kwargs) # verify correct fields are present. self._verify_fields(self._required_fields) # Get Parameters self.m = m_sp self.n = n_sp self.K = water_erodibility # Instantiate a Space component self.eroder = ErosionDeposition( self.grid, K=self.K, phi=sediment_porosity, F_f=fraction_fines, v_s=settling_velocity, m_sp=self.m, n_sp=self.n, discharge_field="surface_water__discharge", solver=solver, ) # Instantiate a LinearDiffuser component self.diffuser = LinearDiffuser( self.grid, linear_diffusivity=regolith_transport_parameter) def run_one_step(self, step): """Advance model **BasicHy** for one time-step of duration step. The **run_one_step** method does the following: 1. Creates rain and runoff, then directs and accumulates flow. 2. Assesses the location, if any, of flooded nodes where erosion should not occur. 3. Assesses if a :py:mod:`PrecipChanger` is an active boundary handler and if so, uses it to modify the erodibility by water. 4. Calculates erosion and deposition by water. 5. Calculates topographic change by linear diffusion. 6. Finalizes the step using the :py:mod:`ErosionModel` base class function **finalize__run_one_step**. This function updates all boundary handlers handlers by ``step`` and increments model time by ``step``. Parameters ---------- step : float Increment of time for which the model is run. """ # create and move water self.create_and_move_water(step) # Get IDs of flooded nodes, if any if self.flow_accumulator.depression_finder is None: flooded = [] else: flooded = np.where( self.flow_accumulator.depression_finder.flood_status == 3)[0] # Do some erosion (but not on the flooded nodes) # (if we're varying K through time, update that first) if "PrecipChanger" in self.boundary_handlers: self.eroder.K = (self.K * self.boundary_handlers["PrecipChanger"]. get_erodibility_adjustment_factor()) self.eroder.run_one_step( step, flooded_nodes=flooded, dynamic_dt=True, flow_director=self.flow_accumulator.flow_director, ) # Do some soil creep self.diffuser.run_one_step(step) # Finalize the run_one_step_method self.finalize__run_one_step(step)
class BasicHyVs(_ErosionModel): """ A BasicHyVs computes erosion using linear diffusion, hybrid alluvium fluvial erosion, and Q ~ A exp( -b S / A). "VSA" stands for "variable source area". """ def __init__(self, input_file=None, params=None, BaselevelHandlerClass=None): """Initialize the BasicHyVs.""" # Call ErosionModel's init super(BasicHyVs, self).__init__(input_file=input_file, params=params, BaselevelHandlerClass=BaselevelHandlerClass) self.K_sp = self.get_parameter_from_exponent('K_sp') linear_diffusivity = ( (self._length_factor**2) * self.get_parameter_from_exponent('linear_diffusivity') ) # has units length^2/time recharge_rate = (self._length_factor * self.params['recharge_rate'] ) # L/T soil_thickness = (self._length_factor * self.params['initial_soil_thickness']) # L K_hydraulic_conductivity = (self._length_factor * self.params['K_hydraulic_conductivity'] ) # has units length per time v_sc = self.get_parameter_from_exponent( 'v_sc') # normalized settling velocity. Unitless. # Instantiate a FlowAccumulator with DepressionFinderAndRouter using D8 method self.flow_router = FlowAccumulator( self.grid, flow_director='D8', depression_finder=DepressionFinderAndRouter) # set methods and fields. K's and sp_crits need to be field names method = 'simple_stream_power' discharge_method = 'drainage_area' area_field = 'effective_drainage_area' discharge_field = None # Add a field for effective drainage area if 'effective_drainage_area' in self.grid.at_node: self.eff_area = self.grid.at_node['effective_drainage_area'] else: self.eff_area = self.grid.add_zeros('node', 'effective_drainage_area') # Get the effective-area parameter self.sat_param = ( (K_hydraulic_conductivity * soil_thickness * self.grid.dx) / recharge_rate) # Handle solver option try: solver = self.params['solver'] except KeyError: solver = 'original' # Instantiate a SPACE component self.eroder = ErosionDeposition(self.grid, K=self.K_sp, F_f=self.params['F_f'], phi=self.params['phi'], v_s=v_sc, m_sp=self.params['m_sp'], n_sp=self.params['n_sp'], method=method, discharge_method=discharge_method, area_field=area_field, discharge_field=discharge_field, solver=solver) # Instantiate a LinearDiffuser component self.diffuser = LinearDiffuser(self.grid, linear_diffusivity=linear_diffusivity) def calc_effective_drainage_area(self): """Calculate and store effective drainage area. Effective drainage area is defined as: $A_{eff} = A \exp ( \alpha S / A) = A R_r$ where $S$ is downslope-positive steepest gradient, $A$ is drainage area, $R_r$ is the runoff ratio, and $\alpha$ is the saturation parameter. """ area = self.grid.at_node['drainage_area'] slope = self.grid.at_node['topographic__steepest_slope'] cores = self.grid.core_nodes self.eff_area[cores] = ( area[cores] * (np.exp(-self.sat_param * slope[cores] / area[cores]))) def run_one_step(self, dt): """ Advance model for one time-step of duration dt. """ # Route flow self.flow_router.run_one_step() # Update effective runoff ratio self.calc_effective_drainage_area() # Zero out effective area in flooded nodes self.eff_area[self.flow_router.depression_finder.flood_status == 3] = 0.0 # Do some erosion # (if we're varying K through time, update that first) if self.opt_var_precip: self.eroder.K = ( self.K_sp * self.pc.get_erodibility_adjustment_factor(self.model_time)) self.eroder.run_one_step(dt) # Do some soil creep self.diffuser.run_one_step(dt) # calculate model time self.model_time += dt # Lower outlet self.update_outlet(dt) # Check walltime self.check_walltime()
class BasicDdVs(_ErosionModel): """ A BasicDdVs computes erosion using linear diffusion, "smoothly thresholded" stream power in which the threshold increases with cumulative erosion depth, and Q ~ A exp( -b S / A). "VSA" stands for "variable source area". """ def __init__(self, input_file=None, params=None, BaselevelHandlerClass=None): """Initialize the VSADepthDepThresholdModel.""" # Call ErosionModel's init super(BasicDdVs, self).__init__(input_file=input_file, params=params, BaselevelHandlerClass=BaselevelHandlerClass) self.K_sp = self.get_parameter_from_exponent('K_sp') linear_diffusivity = (self._length_factor**2.)*self.get_parameter_from_exponent('linear_diffusivity') # has units length^2/time recharge_rate = (self._length_factor)*self.params['recharge_rate'] # has units length per time soil_thickness = (self._length_factor)*self.params['initial_soil_thickness'] # has units length K_hydraulic_conductivity = (self._length_factor)*self.params['K_hydraulic_conductivity'] # has units length per time self.threshold_value = self._length_factor*self.get_parameter_from_exponent('erosion__threshold') # has units length/time # Instantiate a FlowAccumulator with DepressionFinderAndRouter using D8 method self.flow_router = FlowAccumulator(self.grid, flow_director='D8', depression_finder = DepressionFinderAndRouter) # Add a field for effective drainage area if 'effective_drainage_area' in self.grid.at_node: self.eff_area = self.grid.at_node['effective_drainage_area'] else: self.eff_area = self.grid.add_zeros('node', 'effective_drainage_area') # Get the effective-area parameter self.sat_param = (K_hydraulic_conductivity*soil_thickness*self.grid.dx)/(recharge_rate) # Create a field for the (initial) erosion threshold self.threshold = self.grid.add_zeros('node', 'erosion__threshold') self.threshold[:] = self.threshold_value # Instantiate a FastscapeEroder component self.eroder = StreamPowerSmoothThresholdEroder(self.grid, use_Q=self.eff_area, K_sp=self.K_sp, m_sp=self.params['m_sp'], n_sp=self.params['n_sp'], threshold_sp=self.threshold) # Get the parameter for rate of threshold increase with erosion depth self.thresh_change_per_depth = self.params['thresh_change_per_depth'] # Instantiate a LinearDiffuser component self.diffuser = LinearDiffuser(self.grid, linear_diffusivity = linear_diffusivity) def calc_effective_drainage_area(self): """Calculate and store effective drainage area. Effective drainage area is defined as: $A_{eff} = A \exp ( \alpha S / A) = A R_r$ where $S$ is downslope-positive steepest gradient, $A$ is drainage area, $R_r$ is the runoff ratio, and $\alpha$ is the saturation parameter. """ area = self.grid.at_node['drainage_area'] slope = self.grid.at_node['topographic__steepest_slope'] cores = self.grid.core_nodes self.eff_area[cores] = (area[cores] * (np.exp(-self.sat_param * slope[cores] / area[cores]))) def run_one_step(self, dt): """ Advance model for one time-step of duration dt. """ # Route flow self.flow_router.run_one_step() # Update effective runoff ratio self.calc_effective_drainage_area() # Zero out effective area in flooded nodes self.eff_area[self.flow_router.depression_finder.flood_status==3] = 0.0 # Set the erosion threshold. # # Note that a minus sign is used because cum ero depth is negative for # erosion, positive for deposition. # The second line handles the case where there is growth, in which case # we want the threshold to stay at its initial value rather than # getting smaller. cum_ero = self.grid.at_node['cumulative_erosion__depth'] cum_ero[:] = (self.z - self.grid.at_node['initial_topographic__elevation']) self.threshold[:] = (self.threshold_value - (self.thresh_change_per_depth * cum_ero)) self.threshold[self.threshold < self.threshold_value] = \ self.threshold_value # Do some erosion (but not on the flooded nodes) # (if we're varying K through time, update that first) if self.opt_var_precip: self.eroder.K = (self.K_sp * self.pc.get_erodibility_adjustment_factor(self.model_time)) self.eroder.run_one_step(dt) # Do some soil creep self.diffuser.run_one_step(dt) # calculate model time self.model_time += dt # Lower outlet self.update_outlet(dt) # Check walltime self.check_walltime()
class BasicDdSt(_StochasticErosionModel): """ A BasicDdSt computes erosion using (1) unit stream power with a threshold, (2) linear nhillslope diffusion, and (3) generation of a random sequence of runoff events across a topographic surface. Examples -------- >>> from erosion_model import StochasticRainDepthDepThresholdModel >>> my_pars = {} >>> my_pars['dt'] = 1.0 >>> my_pars['run_duration'] = 1.0 >>> my_pars['infiltration_capacity'] = 1.0 >>> my_pars['K_sp'] = 1.0 >>> my_pars['threshold_sp'] = 1.0 >>> my_pars['linear_diffusivity'] = 0.01 >>> my_pars['mean_storm_duration'] = 0.002 >>> my_pars['mean_interstorm_duration'] = 0.008 >>> my_pars['mean_storm_depth'] = 0.025 >>> srt = StochasticRainDepthDepThresholdModel(params=my_pars) Warning: no DEM specified; creating 4x5 raster grid """ def __init__(self, input_file=None, params=None, BaselevelHandlerClass=None): """Initialize the BasicDdSt.""" # Call ErosionModel's init super(BasicDdSt, self).__init__(input_file=input_file, params=params, BaselevelHandlerClass=BaselevelHandlerClass) # Get Parameters: K_sp = self.get_parameter_from_exponent('K_stochastic_sp') linear_diffusivity = ( self._length_factor**2.) * self.get_parameter_from_exponent( 'linear_diffusivity') # has units length^2/time # threshold has units of Length per Time which is what # StreamPowerSmoothThresholdEroder expects self.threshold_value = self._length_factor * self.get_parameter_from_exponent( 'erosion__threshold') # has units length/time # Get the parameter for rate of threshold increase with erosion depth self.thresh_change_per_depth = self.params['thresh_change_per_depth'] # Instantiate a FlowAccumulator with DepressionFinderAndRouter using D8 method self.flow_router = FlowAccumulator( self.grid, flow_director='D8', depression_finder=DepressionFinderAndRouter) # instantiate rain generator self.instantiate_rain_generator() # Add a field for discharge if 'surface_water__discharge' not in self.grid.at_node: self.grid.add_zeros('node', 'surface_water__discharge') self.discharge = self.grid.at_node['surface_water__discharge'] # Get the infiltration-capacity parameter infiltration_capacity = (self._length_factor) * self.params[ 'infiltration_capacity'] # has units length per time self.infilt = infiltration_capacity # Keep a reference to drainage area self.area = self.grid.at_node['drainage_area'] # Run flow routing and lake filler self.flow_router.run_one_step() # Create a field for the (initial) erosion threshold self.threshold = self.grid.add_zeros('node', 'erosion__threshold') self.threshold[:] = self.threshold_value # Get the parameter for rate of threshold increase with erosion depth self.thresh_change_per_depth = self.params['thresh_change_per_depth'] # Instantiate a FastscapeEroder component self.eroder = StreamPowerSmoothThresholdEroder( self.grid, m_sp=self.params['m_sp'], n_sp=self.params['n_sp'], K_sp=K_sp, use_Q=self.discharge, threshold_sp=self.threshold) # Instantiate a LinearDiffuser component self.diffuser = LinearDiffuser(self.grid, linear_diffusivity=linear_diffusivity) def calc_runoff_and_discharge(self): """Calculate runoff rate and discharge; return runoff.""" if self.rain_rate > 0.0 and self.infilt > 0.0: runoff = self.rain_rate - ( self.infilt * (1.0 - np.exp(-self.rain_rate / self.infilt))) if runoff < 0: runoff = 0 else: runoff = self.rain_rate self.discharge[:] = runoff * self.area return runoff def update_threshold_field(self): """Update the threshold based on cumulative erosion depth.""" cum_ero = self.grid.at_node['cumulative_erosion__depth'] cum_ero[:] = (self.z - self.grid.at_node['initial_topographic__elevation']) self.threshold[:] = (self.threshold_value - (self.thresh_change_per_depth * cum_ero)) self.threshold[self.threshold < self.threshold_value] = \ self.threshold_value def run_one_step(self, dt): """ Advance model for one time-step of duration dt. """ # Route flow self.flow_router.run_one_step() # Get IDs of flooded nodes, if any flooded = np.where( self.flow_router.depression_finder.flood_status == 3)[0] # Handle water erosion self.handle_water_erosion_with_threshold(dt, flooded) # Do some soil creep self.diffuser.run_one_step(dt) # calculate model time self.model_time += dt # Lower outlet self.update_outlet(dt) # Check walltime self.check_walltime() def handle_water_erosion_with_threshold(self, dt, flooded): """Handle water erosion. This function takes the place of the _BaseSt function of the name handle_water_erosion_with_threshold in order to handle water erosion correctly for model BasicDdSt. """ # (if we're varying precipitation parameters through time, update them) if self.opt_var_precip: self.intermittency_factor, self.mean_storm__intensity = self.pc.get_current_precip_params( self.model_time) # If we're handling duration deterministically, as a set fraction of # time step duration, calculate a rainfall intensity. Otherwise, # assume it's already been calculated. if not self.opt_stochastic_duration: self.rain_rate = np.random.exponential(self.mean_storm__intensity) dt_water = dt * self.intermittency_factor else: dt_water = dt # Calculate discharge field area = self.grid.at_node['drainage_area'] if self.rain_rate > 0.0 and self.infilt > 0.0: runoff = self.rain_rate - ( self.infilt * (1.0 - np.exp(-self.rain_rate / self.infilt))) else: runoff = self.rain_rate self.discharge[:] = runoff * area # Handle water erosion: # # If we are running stochastic duration, then self.rain_rate will # have been calculated already. It might be zero, in which case we # are between storms, so we don't do water erosion. # # If we're NOT doing stochastic duration, then we'll run water # erosion for one or more sub-time steps, each with its own # randomly drawn precipitation intensity. # if self.opt_stochastic_duration and self.rain_rate > 0.0: self.update_threshold_field() runoff = self.calc_runoff_and_discharge() self.eroder.run_one_step(dt, flooded_nodes=flooded) elif not self.opt_stochastic_duration: dt_water = ((dt * self.intermittency_factor) / float(self.n_sub_steps)) for i in range(self.n_sub_steps): self.rain_rate = \ self.rain_generator.generate_from_stretched_exponential( self.scale_factor, self.shape_factor) self.update_threshold_field() runoff = self.calc_runoff_and_discharge() self.eroder.run_one_step(dt_water, flooded_nodes=flooded)
total_incision_depth += last_z - z total_incision_depth1 += last_z1 - z1 total_incision_depth5 += last_z5 - z5 total_incision_depth10 += last_z10 - z10 rmg['node']['topographic__elevation'][rmg.core_nodes] += (uplift_rate * uplift_dt) rmg1['node']['topographic__elevation'][rmg1.core_nodes] += (uplift_rate * uplift_dt) rmg5['node']['topographic__elevation'][rmg5.core_nodes] += (uplift_rate * uplift_dt) rmg10['node']['topographic__elevation'][rmg10.core_nodes] += (uplift_rate * uplift_dt) lin_diffuse.run_one_step(dt=uplift_dt) lin_diffuse1.run_one_step(dt=uplift_dt) lin_diffuse5.run_one_step(dt=uplift_dt) lin_diffuse10.run_one_step(dt=uplift_dt) peak_q.append(rmg.at_node['surface_water__discharge'][sample_das]) print("Storm #", i, " Duration: ", round(durations[i], 2), " Intensity: ", round(intensities[i], 2)) depth += (durations[i] * intensities[i]) # if i == 70 or 198 or 414 or 609 or 802 or 1149: # #these i values represent storms that hit 1 m, 2.5 m, 5 m, 7.5 m # # 10 m, 12.5 m and 15 m. # dictionary_data2 = (np.array([a, m, n, PD.mean_storm_depth,
from matplotlib import pyplot as plt ## Make a grid that is 100 by 100 with dx=dy=100. m rmg1 = RasterModelGrid((100, 100), 100.) ## Add elevation field to the grid. z1 = rmg1.add_ones('node', 'topographic__elevation') ## Instantiate process components ld1 = LinearDiffuser(rmg1, linear_diffusivity=0.1) fr1 = FlowRouter(rmg1, method='D8') fse1 = FastscapeEroder(rmg1, K_sp=1e-5, m_sp=0.5, n_sp=1.) ## Set some variables rock_up_rate = 1e-3 #m/yr dt = 1000 # yr rock_up_len = dt * rock_up_rate # m ## Time loop where evolution happens for i in range(500): z1[rmg1.core_nodes] += rock_up_len #uplift only the core nodes ld1.run_one_step(dt) #linear diffusion happens. fr1.run_one_step() #flow routing happens, time step not needed fse1.run_one_step(dt) #fluvial incision happens ## optional print statement print('i', i) ## Plotting the topography plt.figure(1) imshow_grid(rmg1, 'topographic__elevation') #need to run for about 4000 time steps, or 4,000,000 years to reach SS
sp = FastscapeEroder(mg, K_sp=0.00005, m_sp=0.5, n_sp=1.0, threshold_sp=0., rainfall_intensity=1.) k_d = 0.5 lin_diffuse = LinearDiffuser(mg, linear_diffusivity=k_d) # * The calculations are all done in the time loop below. for i in range(nt): fr.run_one_step() # route flow sp.run_one_step(dt) # fluvial incision lin_diffuse.run_one_step(dt) # linear diffusion mg.at_node['topographic__elevation'][ mg.core_nodes] += uplift_per_step # add the uplift if i % 20 == 0: print("Completed loop ", i, " out of ", nt) # ### Visualize the results. # * First we plot the topography after the time loop. # * Second we plot the slope-area relationship, which is often used to # identify hillslopes, channels, and quantify drainage density. plt.figure(1) imshow_grid(mg, 'topographic__elevation', grid_units=['m', 'm'],
# Storing the previous time-step's elevation values ele_1 = np.copy(mg.at_node['topographic__elevation']) erode_done = False while erode_done is False: try: # Updating elevation using the erosion term (calling DinfEroder function) fc = FlowAccumulator(mg, flow_director='FlowDirectorDINF') fc.run_one_step() mg.at_node['topographic__elevation'] = DinfEroder( mg, dt, K_sp, m_sp, n_sp) # Updating elevation using the uplift and diffusion terms mg.at_node['topographic__elevation'][mg.core_nodes] += U * dt fd.run_one_step(dt) erode_done = True except ValueError: print('Adjusting dt') mg.at_node['topographic__elevation'] = ele_1 dt = dt / 2. # Copying the updated elevation values after the time-step ele_2 = np.copy(mg.at_node['topographic__elevation']) t += dt # Calculating maximum change in elevation value at any node in the domain ele_diff = np.abs(ele_1 - ele_2).max() # Computing the change in the mean elevation value over the time-step
class Basic(ErosionModel): r"""**Basic** model program. This model program evolves a topographic surface, :math:`\eta`, with the following governing equation: .. math:: \frac{\partial \eta}{\partial t} = -K Q^{m}S^{n} + D\nabla^2 \eta where :math:`Q` is the local stream discharge, :math:`S` is the local slope, :math:`m` and :math:`n` are the discharge and slope exponent parameters, :math:`K` is the erodibility by water, and :math:`D` is the regolith transport efficiency. Refer to `Barnhart et al. (2019) <https://doi.org/10.5194/gmd-12-1267-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, **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. **kwargs : Keyword arguments to pass to :py:class:`ErosionModel`. Importantly these arguments specify the precipitator and the runoff generator that control the generation of surface water discharge (:math:`Q`). Returns ------- Basic : model object Examples -------- This is a minimal example to demonstrate how to construct an instance of model **Basic**. For more detailed examples, including steady-state test examples, see the terrainbento tutorials. To begin, import the model class. >>> from landlab import RasterModelGrid >>> from landlab.values import random >>> from terrainbento import Clock, Basic >>> clock = Clock(start=0, stop=100, step=1) >>> grid = RasterModelGrid((5,5)) >>> _ = random(grid, "topographic__elevation") Construct the model. >>> model = Basic(clock, grid) Running the model with ``model.run()`` would create output, so here we will just run it one step. >>> model.run_one_step(1.) >>> model.model_time 1.0 """ # Call ErosionModel"s init super().__init__(clock, grid, **kwargs) # verify correct fields are present. self._verify_fields(self._required_fields) # Get Parameters: self.m = m_sp self.n = n_sp self.K = water_erodibility self.regolith_transport_parameter = regolith_transport_parameter # Instantiate a FastscapeEroder component self.eroder = FastscapeEroder( self.grid, K_sp=self.K, m_sp=self.m, n_sp=self.n, discharge_field="surface_water__discharge", erode_flooded_nodes=self._erode_flooded_nodes, ) # Instantiate a LinearDiffuser component self.diffuser = LinearDiffuser( self.grid, linear_diffusivity=self.regolith_transport_parameter ) def run_one_step(self, step): """Advance model **Basic** for one time-step of duration step. The **run_one_step** method does the following: 1. Creates rain and runoff, then directs and accumulates flow. 2. Assesses the location, if any, of flooded nodes where erosion should not occur. 3. Assesses if a :py:mod:`PrecipChanger` is an active boundary handler and if so, uses it to modify the erodibility by water. 4. Calculates detachment-limited erosion by water. 5. Calculates topographic change by linear diffusion. 6. Finalizes the step using the :py:mod:`ErosionModel` base class function **finalize__run_one_step**. This function updates all boundary handlers handlers by ``step`` and increments model time by ``step``. Parameters ---------- step : float """ # create and move water self.create_and_move_water(step) # If a PrecipChanger is being used, update the eroder"s K value. if "PrecipChanger" in self.boundary_handlers: self.eroder.K = ( self.K * self.boundary_handlers[ "PrecipChanger" ].get_erodibility_adjustment_factor() ) # Do some water erosion (but not on the flooded nodes) self.eroder.run_one_step(step) # Do some soil creep self.diffuser.run_one_step(step) # Finalize the run_one_step_method self.finalize__run_one_step(step)
# instantiate the components: frr = FlowRouter(mg) # water__unit_flux_in gets automatically ingested spr = StreamPowerEroder(mg, K_sp=K_sp, m_sp=m_sp, n_sp=n_sp, threshold_sp=0, use_Q=None) lake = DepressionFinderAndRouter(mg) # Hillslopes dfn = LinearDiffuser(mg, linear_diffusivity=K_hs) zr_last = -9999 keep_running = np.mean(np.abs(zr - zr_last)) >= end_thresh ti = 0 while keep_running: zr_last = zr.copy() zr[mg.core_nodes] += uplift_rate*dt dfn.run_one_step(dt) # hillslopes always diffusive, even when dry frr.run_one_step() lake.map_depressions() spr.run_one_step(dt, flooded_nodes=lake.lake_at_node) keep_running = np.mean(np.abs(zr - zr_last)) >= end_thresh ti += dt print ti/1000., 'kyr elapsed; ', np.mean(zr-zr_last) / dt * 1E6, \ 'um/yr surface uplift' print "Convergence reached! Landscape is at steady state." A = mg.at_node['drainage_area']#[not_edge] A = A.reshape(ncells_side, ncells_side) S = mg.at_node['topographic__steepest_slope'] S = S.reshape(ncells_side, ncells_side) np.savetxt('Synthetic_data/z.txt', zr, fmt='%.2f')
class BasicSt(StochasticErosionModel): r"""**BasicSt** model program. This model program that evolves a topographic surface, :math:`\eta (x,y,t)`, with the following governing equation: .. math:: \frac{\partial \eta}{\partial t} = -K_{q}\hat{Q}^{m}S^{n} + 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), :math:`S` is the local slope gradient, :math:`m` and :math:`n` are the discharge and slope exponents, respectively, :math:`K` is the erodibility by water, and :math:`D` is the regolith transport parameter. Refer to `Barnhart et al. (2019) <https://doi.org/10.5194/gmd-12-1267-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, 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. 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 ------- BasicSt : model object Examples -------- This is a minimal example to demonstrate how to construct an instance of model **BasicSt**. For more detailed examples, including steady-state test examples, see the terrainbento tutorials. To begin, import the model class. >>> 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") Construct the model. >>> model = BasicSt(clock, grid) Running the model with ``model.run()`` would create output, so here we will just run it one step. >>> model.run_one_step(1.) >>> model.model_time 1.0 """ # Call ErosionModel"s init super(BasicSt, self).__init__(clock, grid, **kwargs) # verify correct fields are present. self._verify_fields(self._required_fields) # Get Parameters: self.m = m_sp self.n = n_sp self.K = water_erodibility self.infilt = infiltration_capacity # instantiate rain generator self.instantiate_rain_generator() # Run flow routing and lake filler self.flow_accumulator.run_one_step() # Instantiate a FastscapeEroder component self.eroder = FastscapeEroder( self.grid, K_sp=self.K, m_sp=self.m, n_sp=self.n, discharge_name="surface_water__discharge", ) # Instantiate a LinearDiffuser component self.diffuser = LinearDiffuser( self.grid, linear_diffusivity=regolith_transport_parameter ) def run_one_step(self, step): """Advance model ``Basic`` for one time-step of duration step. The **run_one_step** method does the following: 1. Creates rain and runoff, then directs and accumulates flow. 2. Assesses the location, if any, of flooded nodes where erosion should not occur. 3. Calculates precipitation, runoff, discharge, and detachment-limited erosion by water. 4. Calculates topographic change by linear diffusion. 5. Finalizes the step using the :py:mod:`ErosionModel` base class function **finalize__run_one_step**. This function updates all boundary handlers handlers by ``step`` and increments model time by ``step``. Parameters ---------- step : float Increment of time for which the model is run. """ # create and move water self.create_and_move_water(step) # Get IDs of flooded nodes, if any if self.flow_accumulator.depression_finder is None: flooded = [] else: flooded = np.where( self.flow_accumulator.depression_finder.flood_status == 3 )[0] # Handle water erosion self.handle_water_erosion(step, flooded) # Do some soil creep self.diffuser.run_one_step(step) # Finalize the run_one_step_method self.finalize__run_one_step(step)