<jupyter_start><jupyter_text>Simulation of morphologic evolution of a scarp profileThis notebook creates and runs a little simulation model of morphologic evolution of an initial scarp.(<NAME>, University of Colorado Boulder; last update November 2021)<jupyter_code>import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from matplotlib import rc
from matplotlib.animation import FuncAnimation
from IPython.display import HTML<jupyter_output><empty_output><jupyter_text>The block below defines the code for the model:<jupyter_code>class ScarpEvolver(object):
    
    def __init__(self,
                 creep_coefficient=0.001,
                 scarp_length=100,
                 num_nodes=100,
                 scarp_height=10.0,
                 initial_angle=35.0,
                 diffusion_number=0.2,
                ):
        """Initialize the ScarpEvolver.

        Parameters
        ----------
        creep_coefficient: float
            soil creep coefficient, m2/yr
        scarp_length: float
            length of domain, m
        num_nodes: int
            number of nodes
        scarp_height: float
            initial height of scarp, m
        initial_angle: float
            initial angle of scarp, degrees
        diffusion_number: float
            diffusion number
        """
        self.scarp_length = scarp_length
        self.alpha = diffusion_number  # must be <= 1/2 for numerical stability
        self.dx = scarp_length / (num_nodes - 1)
        self.timestep_duration = self.alpha * self.dx * self.dx / creep_coefficient
        self.elev = np.zeros(num_nodes)
        
        m = np.tan(np.radians(initial_angle))
        b = 0.5 * (scarp_height - m * scarp_length)
        self.x = np.linspace(0, scarp_length, num_nodes)
        self.elev[:] = m * self.x + b
        self.elev[self.elev < 0.0] = 0.0
        self.elev[self.elev > scarp_height] = scarp_height

    def run_one_step(self):
        """Advance for one time step"""
        self.elev[1:-1] += self.alpha * (self.elev[2:] - 2 * self.elev[1:-1] + self.elev[:-2])
        
    def run_n_steps(self, n):
        for i in range(n):
            self.run_one_step()<jupyter_output><empty_output><jupyter_text>In the next block, we creat an *instance* of the model. This initializes it but does not actually run it.<jupyter_code>scarp_length = 100.0
scarp_height = 10.0
md = ScarpEvolver(scarp_length=scarp_length, scarp_height=scarp_height)<jupyter_output><empty_output><jupyter_text>Let's check what the time-step size is:<jupyter_code>print('Time step size is ' + str(md.timestep_duration) + ' years.')<jupyter_output><empty_output><jupyter_text>Set some parameters that will control our run and the capturing of output:<jupyter_code>nsteps = 100
save_every = 2<jupyter_output><empty_output><jupyter_text>The next few cells set up the animation<jupyter_code># First, set up a blank figure
fig, ax = plt.subplots()

# And placeholder lists for data
xdata = []
ydata = []
obj = ax.plot([], [], color = 'k')
# Then, set up an initialization function
def init():
    ax.set_xlim(0, scarp_length)
    ax.set_ylim(0, scarp_height)
    ax.set_xlabel('Distance (m)')
    ax.set_ylabel('Elevation (m)')
    return(obj)
# Next, define the update function
def update(i):
    ax.cla()
    md.run_n_steps(save_every)
    xdata = md.x
    ydata = md.elev
    ax.set_xlabel('Distance (m)')
    ax.set_ylabel('Elevation (m)')
    obj = ax.plot(xdata, ydata, color = 'k')
    return(obj)<jupyter_output><empty_output><jupyter_text>Now, use FuncAnimation to run the model.<jupyter_code># Run the animation!
anim = FuncAnimation(fig, update, 100, init_func = init, blit = True)
plt.show()
# Convert the animation to HTML
vid = HTML(anim.to_jshtml())
vid<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1029917924278528, 'fraction_numerical': 0.014826581943341277, 'mean_word_length': 3.010615711252654, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '586235', 'license': 'MIT', 'n_tokens_mistral': 1282, 'n_tokens_neox': 1244, 'n_words': 315, 'path': 'scarp_diffusion.ipynb', 'repo_name': 'gregtucker/learning-with-1d-models', 'size': '3782'}