Hillslope diffusion in Python

Last modified by Xwiki VePa on 2024/02/07 07:37

The introductory Python tutorials are available here: Introduction to Python and NumPy I - Introduction to Python and NumPy II

Purpose

In this exercise you will apply the diffusion equation to make plots of hillslope profiles, assuming diffusion is the dominant geomorphic process on the slopes. It is based on a MATLAB exercise provided by Prof. Todd Ehlers at the University of Tübingen, Germany.

Overview


The objective of this set of exercises is to compute steady-state hillslope profiles assuming hillslope evolution is a diffusive process. The hillslope diffusion model is based on the principal of conservation of mass, which states that the changes in surface elevation are proportional to the sediment flux along the hillslope.

Calculating hillslope profiles using Python


For this exercise, you will need the Python script hillslope_profile_ex1.py. Download a copy and place it in a new directory (e.g., QG-Lab3) on the Desktop. The script will calculate the hillslope geometry and provide all of the information needed to answer the questions in this exercise. The version you can download is not functional, so you will need to make some changes in order to get the code working.

Formatting character strings in Python

You are asked below to add calculated values to your plots using the text() function. The text function can display character strings, integers and floating point values, but there are a few challenges to using the text() function. The print() function behaves very similar to the text() function, displaying text in the interpreter window rather than on a plot, so we will explore a few examples using the print() function rather than text(). You can apply these same ideas to your plots with the text() function.

First, numerical values must be converted to character strings before they can be displayed as part of some text. For example, typing the text below will produce an type error.

>>> print("I have "+4+" tacos")
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-13c2c5bb89fe> in <module>()
----> 1 print("I have "+4+" tacos")
TypeError: cannot concatenate 'str' and 'int' objects

The message states that we cannot add together character and integer values in a single print statement. We can fix this by converting the integer value to a character string using the str() function.

>>> print("I have "+str(4)+" tacos")
I have 4 tacos

The same idea can be applied to floating point numbers.

>>> print("The value of pi is approximately "+str(355.0/113.0))
The value of pi is approximately 3.14159292035

This example raises another issue. The approximation of pi above is only accurate to 7 decimal places, so it would be best to only display that number of decimal values. We can do this using a format string.

>>> print("The value of pi is approximately "+str("{0:.7f}".format(355.0/113.0)))
The value of pi is approximately 3.1415929

So, what happened? We replaced the text 355.0/113.0 in the str() function with "{0:.7f}".format(355.0/113.0)), but what does that mean? With the format method we can specify how we would like text displayed, in our case the number of decimal places in our floating point value. The general syntax for the format method is

{<key>:<format options>}.format(<value>)

where <key> refers to the position of an item in the list of values to be formatted (0 if there is only one value), <format options> are the specifications for how to display the text, and <value> is the value you want to display. In our case, we specify we want the first floating point value (0) to be displayed with seven decimal places {0:.7f}. In this case, the number after the period is the number of decimal places to show and the "f" will display the text as a typical floating point number. We could alternatively display the approximate value of pi in scientific notation by replacing the "f" with an "e".

>>> print("The value of pi is approximately "+str("{0:.7e}".format(355.0/113.0)))
The value of pi is approximately 3.1415929e+00

As you might imagine, there is a great deal of formatting that can be done with the format method, but you're likely to only need to change the number of decimal places for floating point values in the exercises today. More information about the format method is available on the Python documentation page.

Exercise 1 - Steady-state diffusive hillslope profiles

File(s) for this exercise

In this exercise, you will be plotting a diffusive hillslope profile and exploring the effect of various parameters on the hillslope geometry. After copying the hillslope_profile_ex1.py file into your own directory for this week's exercises, open a terminal window and launch ipython. You can then open the hillslope_profile_ex1.py file in a text editor such as gedit or the editor in Canopy.

  1. Modify the file (which is currently not functional) to include a for loop that calculates the surface elevation of the hillslope (variable h) as a function of horizontal distance (variable x). Your x-values should be in one-meter increments and the x-value range should be large enough to include one complete interfluve (ridge) from valley to valley. The equation for calculating the elevation as a function of horizontal distance (x) was presented in lecture and is already in the Python script. Your job is to make it calculate the elevation at each x-value.
  2. Two channels are located 100 m apart and incise into a landscape being uplifted at a rate of 0.5 mm/a producing an interfluve with two symmetrical hillslopes. Calculate the profile of the hillslope system, assuming the erosion is a diffusive process with a diffusion coefficient of 50 × 10-3 m2/a. Using the Python script you just modified, you should do this calculation using the solution for the diffusion equation, which is parabolic in form.
  3. At what value of x (distance from the divide) is the maximum hillslope gradient? Add lines of code to the bottom of the Python program to calculate the maximum hillslope gradient and add it to the plot with the text() function (see help(plt.text) for help using this function). Where is the maximum slope angle in relation to the crest of the interfluve and the river channel? What is the maximum slope? What is the maximum slope in degrees? The equations for this calculation were presented in lecture.

  4. The maximum relief of the hillslope between the hillcrest and the bounding valley bottom is the value of h at x = 0 minus the value of h at x = L. Add lines of code to the bottom of the Python program to calculate the maximum relief and add it to the plot with the text() function. What is the maximum relief?
  5. Diffusive problems have a characteristic timescale τ. What does a characteristic timescale mean? The equation for this was presented in lecture. Add lines of code to the bottom of the Python program to calculate the characteristic timescale and add this information to the plot with the text() function. What is the value for the characteristic timescale? Does it seem reasonable? Why or why not?

    This is a good point to stop and save a copy of your plot with the answers to questions 2-5 displayed as text on the plot.

  6. Explore the effect of different parameters on the hillslope geometry. Starting with the initial plot you made for Exercise 1.2, make an additional plot for each of the four variations to the following parameters. In each case be sure you only vary a single parameter from the original values in Exercise 1.2
    1. Change L to 100 m
    2. Double the uplift rate
    3. Double the diffusivity
    4. Reduce the diffusivity by half

For questions 2-5 of this exercise, you should submit a Word document or PDF with

  1. One plot with the answers to questions 2-5 displayed as text on the plot
  2. A figure caption beneath the plot explaining what it shows as if it was in a scientific publication
  3. A copy of your modified code, either as an separate submission or pasted into the document as an appendix

For question 6 of this exercise, you should add to your document

  1. A copy of each of the four plots for the different variables
  2. A figure caption for each plot describing what the plot shows as if the figure was in a scientific publication
Exercise 2 - Mountain hillslope profiles

File(s) for this exercise

Active mountain ranges typically have poorly developed soils and abundant exposed bedrock.

  1. For this question, you can use your modified Python script from Exercise 1. Assuming an interfluve width of 20 km, an uplift rate of 0.5 mm/a, and an appropriate diffusivity for rock of 10 m2/a, calculate a hillslope profile. Again calculate the maximum hill slope and its value in degrees, the maximum relief, and the characteristic timescale just as you did in Exercise 1. Include a copy of this plot with the 4 calculated values displayed on it and a figure caption as if the figure was in a scientific publication. Also include a 1 paragraph discussion of the implications these results have for mountain hillslopes in your write-up. What do the various values you have calculated imply for natural systems?
  2. Incision history of the western Sierra Nevada mountains, California, USA
    For this section, we will apply our model equation to a real landscape, the western Sierra Nevada mountains in California, USA. We will use a topographic profile extracted across an interfluve between two streams draining into the Yuba River and change the landscape uplift rate in the equation until we get a reasonable match to the observed profile from our equation.
    1. Location of the topographic profile
      Before we load anything, it is important that you know the location of the topographic profile.
      Sierras_profile_map.pngFigure 1. Shaded relief digital elevation model of the western Sierra Nevada Mountains in California, USA. The line A-A´ is the location of a topographic profile used in Exercise 2.2. Click to enlarge.
    2. Calculating river incision rates based on hillslope geometry
      • Now that you know where the profile is located, you should download a copy of the sierras_profile.txtsierras_profile.txt data file and save it in your directory for this week's exercises. You will also need to download a copy of the Python script hillslope_profile_ex2.2.pyhillslope_profile_ex2.2.py and save it to your directory for this week's exercises. This Python script will take care of loading the data file containing distances from the drainage divide and elevations for the topographic profile A-A´. Those values will be loaded as arrays data_x[] and data_h[]. As in Exercise 1, part of this script is not currently working, and you will need to add the for loop for calculating the hillslope elevations exactly like you did in Exercise 1.
      • Once you have modified the program to add the for loop, you will want to change some of the variables that go into the equation for hillslope diffusion. You will be exploring a range of landscape uplift rates (U), but the values for the other variables should not change. Set the diffusion coefficient kappa to 1.8 m2/a and the half-width of the hillslope L should be half of the distance between the channels, which can be measured off the topographic profile in Figure 2 below. Your x-values should range across the entire interfluve with distance increments of 100 m.
      • Lastly, you will want to plot the observed topographic profile along with the model prediction to try and fit the observation by varying the uplift rate until you get a similar profile. Add a line in the program to plot the observed data using the plot() function. Be sure to use a different line color or pattern so that it is clear which line is the model and which is the data profile. Once you’ve determined your best-fit uplift rate, add text to the plot to display that rate using the text() function. Also, you will want to shift the model profile up about 750 m since the channels in the observed profile are at ~750 m elevation.
        sierras_profile.pngFigure 2. Topographic profile across an interfluve between 2 streams draining into the Yuba River, Sierra Nevada mountains, California, USA.

For Exercise 2 you should add the following to your document

  1. A Python plot comparing the observed and predicted topographic profiles with the landscape uplift rate added as text on the figure
  2. A figure caption explaining what is plotted as if it were in a scientific publication