<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 CHILD Landscape Evolution Model
Link to this notebook
Step1:  Run CHILD in PyMT
We'll now do the same thing but this time with the Child model. Notice that the commands will be the same. If you know how to run one PyMT component, you know how to run them all.
Step2:  You can now see the help information for Child. This time, have a look under the Parameters section (you may have to scroll down - it's the section after the citations). The Parameters section describes optional keywords that you can pass the the setup method. In the previous example we just used defaults. Below we'll see how to set input file parameters programmatically through keywords.
Step3:  We can change input file paramters through setup keywords. The help description above gives a brief description of each of these. For this example we'll change the grid spacing, the size of the domain, and the duration of the simulation.
Step4:  The setup folder now only contains the child input file.
Step5:  Again, initialize and run the model for 10 time steps.
Step6:  This time around it's now quite as clear what the units of time are. We can check in the same way as before.
Step7:  Update until some time in the future. Notice that, in this case, we update to a partial time step. Child is fine with this however some other models may not be. For models that can not update to times that are not full time steps, PyMT will advance to the next time step and interpolate values to the requested time.
Step8:  Child offers different output variables but we get them in the same way as before.
Step9:  We can query each input and output variable. PyMT attaches a dictionary to each component called var that provides information about each variable. For instance we can see that "land_surface__elevation" has units of meters, is an input and output variable, and is defined on the nodes of grid with id 0.
Step10:  If we plot this variable, we can visually see the unsructured triangular grid that Child has decomposed its grid into.
Step11:  As with the var attribute, PyMT adds a dictionary, called grid, to components that provides a description of each of the model's grids. Here we can see how the x and y positions of each grid node, and how nodes connect to one another to form faces (the triangles in this case). Grids are described using the ugrid conventions.
Step12:  Child initializes it's elevations with random noise centered around 0. We would like instead to give it elevations that have some land and some sea. First we'll get the x and y coordinates for each node along with their elevations.
Step13:  All nodes above y=y_shore will be land, and all nodes below y=y_shore will be sea.
Step14:  Just to verify we set things up correctly, we'll create a plot.
Step15:  To get things going, we'll run the model for 5000 years and see what things look like.
Step16:  We'll have some fun now by adding a simple uplift component. We'll run the component for another 5000 years but this time uplifting a corner of the grid by dz_dt.
Step17:  A portion of the grid was uplifted and channels have begun eroding into it.
Step18:  We now stop the uplift and run it for an additional 5000 years.
<ASSISTANT_TASK:>
Python Code:
# Some magic to make plots appear within the notebook
%matplotlib inline
import numpy as np # In case we need to use numpy
Explanation: CHILD Landscape Evolution Model
Link to this notebook: https://github.com/csdms/pymt/blob/master/notebooks/child.ipynb
Install command: $ conda install notebook pymt_child
Import the Sedflux3D component from pymt. All of the components available to pymt are located in pymt.components. Here I've renamed the component to be Model to show that you could run these same commands with other models as well. For instance, you could instead import Child with from pymt.components import Child as Model and repeat this exercise with Child instead.
End of explanation
import pymt.models
model = pymt.models.Child()
Explanation: Run CHILD in PyMT
We'll now do the same thing but this time with the Child model. Notice that the commands will be the same. If you know how to run one PyMT component, you know how to run them all.
End of explanation
help(model)
rm -rf _model # Clean up for the next step
Explanation: You can now see the help information for Child. This time, have a look under the Parameters section (you may have to scroll down - it's the section after the citations). The Parameters section describes optional keywords that you can pass the the setup method. In the previous example we just used defaults. Below we'll see how to set input file parameters programmatically through keywords.
End of explanation
config_file, initdir = model.setup('_model',
                                   grid_node_spacing=750.,
                                   grid_x_size=20000.,
                                   grid_y_size=40000.,
                                   run_duration=1e6)
Explanation: We can change input file paramters through setup keywords. The help description above gives a brief description of each of these. For this example we'll change the grid spacing, the size of the domain, and the duration of the simulation.
End of explanation
ls _model
Explanation: The setup folder now only contains the child input file.
End of explanation
model.initialize(config_file, initdir)
for t in range(10):
    model.update()
    print(model.time)
Explanation: Again, initialize and run the model for 10 time steps.
End of explanation
model.time_units
Explanation: This time around it's now quite as clear what the units of time are. We can check in the same way as before.
End of explanation
model.update_until(201.5, units='year')
print(model.time)
Explanation: Update until some time in the future. Notice that, in this case, we update to a partial time step. Child is fine with this however some other models may not be. For models that can not update to times that are not full time steps, PyMT will advance to the next time step and interpolate values to the requested time.
End of explanation
model.output_var_names
model.get_value('land_surface__elevation')
Explanation: Child offers different output variables but we get them in the same way as before.
End of explanation
model.var['land_surface__elevation']
Explanation: We can query each input and output variable. PyMT attaches a dictionary to each component called var that provides information about each variable. For instance we can see that "land_surface__elevation" has units of meters, is an input and output variable, and is defined on the nodes of grid with id 0.
End of explanation
model.quick_plot('land_surface__elevation', edgecolors='k', vmin=-200, vmax=200, cmap='BrBG_r')
Explanation: If we plot this variable, we can visually see the unsructured triangular grid that Child has decomposed its grid into.
End of explanation
model.grid[0]
Explanation: As with the var attribute, PyMT adds a dictionary, called grid, to components that provides a description of each of the model's grids. Here we can see how the x and y positions of each grid node, and how nodes connect to one another to form faces (the triangles in this case). Grids are described using the ugrid conventions.
End of explanation
x, y = model.get_grid_x(0), model.get_grid_y(0)
z = model.get_value('land_surface__elevation')
Explanation: Child initializes it's elevations with random noise centered around 0. We would like instead to give it elevations that have some land and some sea. First we'll get the x and y coordinates for each node along with their elevations.
End of explanation
y_shore = 15000.
z[y < y_shore] -= 100
z[y >= y_shore] += 100
model.set_value('land_surface__elevation', z)
Explanation: All nodes above y=y_shore will be land, and all nodes below y=y_shore will be sea.
End of explanation
model.quick_plot('land_surface__elevation', edgecolors='k', vmin=-200, vmax=200, cmap='BrBG_r')
Explanation: Just to verify we set things up correctly, we'll create a plot.
End of explanation
model.update_until(5000.)
model.quick_plot('land_surface__elevation', edgecolors='k', vmin=-200, vmax=200, cmap='BrBG_r')
Explanation: To get things going, we'll run the model for 5000 years and see what things look like.
End of explanation
dz_dt = .02
now = model.time
times, dt = np.linspace(now, now + 5000., 50, retstep=True)
for time in times:
    model.update_until(time)
    z = model.get_value('land_surface__elevation')
    z[(y > 15000.) & (x > 10000.)] += dz_dt * dt
    model.set_value('land_surface__elevation', z)
Explanation: We'll have some fun now by adding a simple uplift component. We'll run the component for another 5000 years but this time uplifting a corner of the grid by dz_dt.
End of explanation
model.quick_plot('land_surface__elevation', edgecolors='k', vmin=-200, vmax=200, cmap='BrBG_r')
Explanation: A portion of the grid was uplifted and channels have begun eroding into it.
End of explanation
model.update_until(model.time + 5000.)
model.quick_plot('land_surface__elevation', edgecolors='k', vmin=-200, vmax=200, cmap='BrBG_r')
model.get_value('channel_water_sediment~bedload__mass_flow_rate')
Explanation: We now stop the uplift and run it for an additional 5000 years.
End of explanation
<END_TASK>