Preface by Simon M Mudd

Welcome to a series of tutorials about LSDTopoTools, that serve both as a basis of a short course as well as practical exercises for a course at Edinburgh called Eroding Landscapes. Hopefully by following these tutorials you will be able perform some simple analyses using LSDTopoTools and will be encouraged to explore its full functionality.

1. Getting Started

Welcome to this short course on LSDTopoTools. There are three collections of people who might be taking this course:

  1. Research students and staff at the University of Edinburgh.

  2. Students taking Eroding Landscapes and other taught students (BSc, MSc, MEarthSci) at the University of Edinburgh.

  3. People from outside of Edinburgh who want to learn how to use LSDTopoTools.

The main difference between these groups is that if you are at Edinburgh you can use our Linux servers. If you are working outside Edinburgh’s network you will either need to:

  • use your own Linux server or computer, in which case you can set up everything with a python script called LSDTopoToolsSetup.py.

OR

  • set up your own Linux server on your desktop computer or laptop using a clever bit of software called Vagrant. Don’t worry if that sounds a bit complex, we have instructions to walk you through the process, which works on any operating system (e.g., Windows, Linux, or MacOS) and is all based on open-source software.

The only substantive difference between taught students and research students at Edinburgh is the amount of disk storage you are allocated on our servers. If you are a taught student and are going to be using large datasets you should either install LSDTopoTools on your own computer or talk to the GeoSciences IT team about getting more storage.

1.1. Starting up at Edinburgh

If you are at Edinburgh, most of the software you need for LSDTopoTools is already installed on our servers. So the main task you will have to get started is getting on to our servers.

If you are on a desktop, you will need the program NX. Using this program you can log in to our ssh portal. The instructions are here: http://www.ed.ac.uk/geosciences/intranet/it/working-remotely

Once you get into NX, you should open TWO terminal windows. To open a terminal window in nx just right click and select "terminal".

Open a terminal
Figure 1. Open a terminal window in NX

1.1.1. If NX is not working

Sometimes NX misbehaves, so you can also use a secure shell client. Our lab computers have something called either SSH client or SSH Secure Shell: select the client on the start menu and then begin a new session. You will need to use the address ssh.geos.ed.ac.uk, and then your username, and click on password control. You will then need to enter your EASE password at the prompt. You should start TWO sessions. These windows are the equivalent of a terminal window in NX.

1.2. Move onto a decent server

When you start up in either NX or an SSH client, you get dumped onto an old, slow server. To switch to a new, faster one, you need to use the ssh command:

$ ssh achray.geos.ed.ac.uk

You might need to enter your EASE password again here.

1.3. Starting up outside Edinburgh

If you are not in the School of GeoSciences at the University of Edinburgh, you will need to set up your own Linux environment. Quick instructions are below, but if you like reading installation notes and all the excruciating details, the full instructions can be found at this website: http://lsdtopotools.github.io/LSDTT_book/#_installing_lsdtopotools_using_virtualbox_and_vagrant

1.4. Starting up on your own Linux machine

If you work on a Linux operating system we have a python script for installing everything. You will need to be connected to the internet, and have python installed. You can skip ahead to the section Setting up directories the easy way.

1.5. Starting up on a non-Linux operating system (Windows, MacOS)

Below are quick instructions. If you have trouble, follow the link above and then go through the complete instructions.

Quick Instructions for using Vagrant for LSDTopoTools
  1. Download and install virtualbox.

  2. Download and install vagrant. You might have to restart your computer after this.

  3. If you are on Windows, download putty.exe. If you are on Linux or MacOS you can skip this (they have built-in equivalents).

  4. Make a folder for your vagrant box. We tend to put ours in a directory called VagrantBoxes.

  5. Inside that directory make two new directories: LSDTopoTools and Ubuntu_vagrant. The second directory’s name doesn’t matter, it is just for holding a vagrant file (see below). However you MUST have the LSDTopoTools directory. The directory name is case sensitive!

  6. Download one of our vagrantfiles: https://github.com/LSDtopotools/LSDTT_vagrantfiles into the Ubuntu_vagrant directory (again, the name of the directory doesn’t matter).

  7. Rename the vagrantfile from the repo (either Vagrantfile_32bit_FFTW or Vagrantfile_64bit_FFTW) simply vagrantfile. Your operating system is almost certainly 64 bit, but on most computers you need to select 32 bit because the default setting is to disable 64 bit guest operating systems. This can be changed but only by expert users.

  8. Open a terminal or powershell window and navigate to the directory with the vagrantfile.

  9. Run vagrant up from the command line.

    If you are running vagrant up for the first time it can take some time to download the base box. They are several hundred Mb each!
  10. Run vagrant provision after the box has started.

  11. If on Windows, you should now be able to use putty.exe to ssh into your LSDTopoTools server. The host name is almost always 127.0.0.1 and the port is almost always 2222.

  12. On Windows, you will need to give a username and password after connecting using putty.exe. The machine is running locally on your computer so nothing is being sent over the internet. The username is always vagrant and the password is also vagrant.

  13. If you are on MacOS or Linux you do not need putty.exe; all you need to do is type vagrant ssh into the command line. See the vagrant instructions.

1.6. Troubleshooting a vagrant server

There are a few common problems people have when running a vagrant server.

  • If you are on an old computer, sometimes vagrant times out before the virtual machine boots. This most frequently happens the first time you boot a vagrant machine. The most effective way to fix this is with the canonical IT solution: turning it off and on again. TO do that run vagrant halt and vagrant up in succesion.

  • If your files are not synching across your host and vagrant machine, it is probably because there is some misspelling in your LSDTopoTools folder on the host machine. Make sure that folder is in the correct place and is spelled correctly (remember it should be case sensitive!!).

1.6.1. After you have set up a vagrant server

Once you have a vagrant server set up, you should start TWO ssh sessions into the Linux server.

1.7. Setting up directories

LSDTopoTools expects your data to be organised in a certain way. You can either do this yourself by hand (we will call this the "hard way") or use a python script we have prepared ("easy way"). If you follow directions to set up the easy way you don’t need to follow instructions for the hard way.

1.7.1. Setting up directories the easy way

If you just plan on using our tools this section describes the best way to set up LSDTopoTools. You only need to read the sections about doing things the hard way if you are going to develop our software, or are going to be using new releases of our research code.
Easy setup quick start

If you just want to get started with the standard setup without any details, do the following:

  1. Go into a Linux terminal. If you are on your own computer and it is not Linux, you will need to start a Vagrant session. You will need python but this is now standard on most Linux distributions so we will assume you have it.

  2. Get the python setup tool:

    $ wget https://raw.githubusercontent.com/LSDtopotools/LSDAutomation/master/LSDTopoToolsSetup.py
  3. Run the setup tool:

    $ python LSDTopoToolsSetup.py -id 0
  4. You are ready to go!!

    For native Linux users: The -id flag tells LSDTopoToolsSetup.py where to put the files. In vagrant it always starts in the root directory (this is for file syncing purposes). However, if your native operating system is Linux, then you can either install in your home directory (-id 0) or in the directory where you called LSDTopoToolsSetup.py (-id 1).
  1. The first thing you need to do is get our python program LSDTopoToolsSetUp.py. It lives here: https://github.com/LSDtopotools/LSDAutomation/blob/master/LSDTopoToolsSetup.py

    You will need to run this file in your Linux environment, so in a terminal window type:

    $ wget https://raw.githubusercontent.com/LSDtopotools/LSDAutomation/master/LSDTopoToolsSetup.py
    If wget doesn’t work, you can follow the link: https://raw.githubusercontent.com/LSDtopotools/LSDAutomation/master/LSDTopoToolsSetup.py
    Copy the text, paste it into a text editor and save it as LSDTopoToolsSetup.py.
  2. Now, in your terminal window run this script. It has some options:

    1. For the most basic setup, type:

      $ python LSDTopoToolsSetup.py -id 0

      In our Vagrant setup, this will install everything in the root directory (you can got there with $ cd /), which is the default setup generated by our Vagrantfile. If you are not in vagrant the LSDTopoTools directories will be in your home directory (you can get there with $ cd ~).

    2. If you don’t want LSDTopoTools in your home directory, you can install it in your current directory with:

      $ python LSDTopoToolsSetup.py -id 1
  3. It turns out the LSDTopoToolsSetup.py tool has a number of options but we will explain these later. If you want a preview of what it does, you can call its help options:

    $ python LSDTopoToolsSetup.py -h

1.7.2. Setting up directories the hard way

Our script LSDTopoToolsSetup.py automates creation of the correct directories and installing the LSDTopoTools programs. If you have used that script you don’t really need to read this, but if you are unfamiliar with Linux at some point you will need to come to terms with the way our directories are structured, how to move between directories, finding things in directories, etc., so you might consider reading this section when you have the chance.

Understanding where your files are is ESSENTIAL. If you don’t know where your files are it will lead to extreme frustration! You will need to work with files and directories in Linux. There is an entire section in our book about this.

The crucial thing is that we will have separate directories for DATA and PROGRAMS. So you will need to make directories for these.

For the purposes of this workshop, we will use a standardised directory structure. If you NOT at Edinburgh and using our vagrant setup, then this structure already exists!! If you are at Edinburgh you will need to make this structure. This is automated by the script LSDTopoToolsSetup.py but these instructions are here in case you want to do it by hand.

In Linux, to find out your current directory type the command pwd.
How directories are organised and how to move around in them

Inside your computer are files organised into directories (in Windows these are called folders, but the concept is the same). These can be nested, so a directory can contain other directories.

One way of thinking about this is like the root system of a tree. Directories inside other directories are like branching roots. If you start at the tip of the system and keep going up you get to the biggest root. In Linux the top directory is called root: it contains all the other directories. So when we say you are going "down" is means you are getting into smaller and smaller directories, and if you are going "up" it means you are getting closer to the root, where there are directories that connect to more stuff (i.e., they connect to more "branches".)

  • To go "up" you type the command cd .. The cd stands for "change directory".

  • To go "down" you need to choose one of the branches: cd A_directory_name where A_directory_name can be the name of any directory within your current directory.

  • To see what is in a directory use ls. If you want lots of details type ls -l.

  • To see what directory you are in type pwd

1.7.3. Directories the hard way if you are at Edinburgh

  1. If you have just started an ssh or terminal window, you can find out where you are, it will look something like this:

    $ pwd
    $ /home/MyUserName/

    In this case MyUserName will be replaced by your own EASE name (e.g., smudd)

  2. Make a directory called LSDTopoTools using the mkdir command and then go into it with the cd command:

    $ mkdir LSDTopoTools
    $ cd LSDTopoTools
    $ pwd
    $ /home/MyUserName/LSDTopoTools/
    Linux is case sensitive so LSDTopoTools and lsdtopotools and LSDtopotools are three different directories!! Make sure you keep track of this!
    DO NOT use spaces in your file or directory names, EVER.
  3. Now make two new directories in the LSDTopoTools directory, called Git_projects and Topographic_projects. The only reason for these names is that the rest of the documentation uses these directory names.

    $ pwd
    $ /home/MyUserName/LSDTopoTools/
    $ mkdir Git_projects
    $ mkdir Topographic_projects
  4. We are going to clone some data into the Topographic_projects directory. Even if you are going to use your own DEM this is handy because the cloned data folder also includes all the parameter files that we will use in this workshop:

    $ cd Topographic_projects
    $ git clone https://github.com/LSDtopotools/LSDTT_workshop_data.git
  5. This will make a folder LSDTT_workshop_data into which you can place your own data. It also contains two test DEMs from Scotland that we will use in the Eroding Landscapes course.

  6. Now go back into your Git_projects directory. If you have followed the above directions you will be sitting in the Topographic_projects directory so go up a level and then down into the Git_projects directory:

    $ cd ..
    $ cd Git_projects
  7. Now you need to clone some other repositories that have our code:

    $ git clone https://github.com/LSDtopotools/LSDTopoTools_AnalysisDriver.git
    $ git clone https://github.com/LSDtopotools/LSDTopoTools_CRNBasinwide.git
    $ git clone https://github.com/LSDtopotools/LSDTopoTools_ChannelExtraction.git
    $ git clone https://github.com/LSDtopotools/LSDTopoTools_ChiMudd2014.git
  8. Great! Now you have everything you need for the workshop.

1.7.4. Directories the hard way if you are outside Edinburgh (or using your home computer)

If you have set up using our vagrantfiles, the correct directory structure is already in place. However you will need to clone the data for this workshop:

$ cd /LSDTopoTools/Topographic_projects
$ git clone https://github.com/LSDtopotools/LSDTT_workshop_data.git

1.7.5. Directory structure

If you did this the easy way, you will have directories that look like this:

/LSDTopoTools
  |--Git_projects
  |----LSDTopoTools_AnalysisDriver
  |----LSDTopoTools_ChiMudd2014
  |--Topographic_projects
  |----LSDTT_workshop_data
  |----Test_data

If you are in vagrant, the /LSDTopoTools directory will be in the root directory, whereas if you are in another system it will be in your home directory (which you can get to with cd ~), unless you told the setup tool to install in your current directory.

If you setup the hard way, you will have a few extra things (which the setup tool gets with some optional instructions):

/LSDTopoTools
  |--Git_projects
  |----LSDTopoTools_AnalysisDriver
  |----LSDTopoTools_CRNBasinwide
  |----LSDTopoTools_ChannelExtraction
  |----LSDTopoTools_ChiMudd2014
  |--Topographic_projects
  |----LSDTT_workshop_data
  |----Test_data

1.8. Summary

At the end of this section you will have the directories and files you need to move on to the next stage of the workshop.

2. Simple surface metrics

In this section we will use the LSDTopoTools analysis driver program to calculate some new rasters. The analysis driver is good for doing simple calculations and routine analyses.

2.1. Making the analysis driver program

LSDTopoTools is distributed as source code in C++, so you have to turn it into a program using a compiler and a program called make.

If you used LSDTopoToolsSetup.py, all of that make stuff will have just happened automatically. You can skip past this section!

2.1.1. If you didn’t use LSDTopoToolsSetup.py

If you didn’t use LSDTopoToolsSetup.py, you need to use make yourself. If you have some familiarity with Linux then this should be rather painless.

It is easier to keep track of things if you have one terminal window for the directories with the source code (these are all in the Git_projects directory) and another terminal window inside directories where you keep your data (these are in the Topographic_projects directory).
  1. Navigate into the LSDTopoTools_AnalyisDriver directory, and then into the subdirectory Analysis_driver.

    $ cd /path/to/LSDTopoTools/
    $ cd Git_projects/LSDTopoTools_AnalysisDriver/Analysis_driver

    The /path/to/ bit can be replaced by your own path (in my case it is /home/smudd/). In vagrant this is simply / since our vagrant setup puts the LSDTopoTools directory within the root directory.

  2. Then use make to compile the programs. You will get lots of warnings that can be ignored.

    $ make -f Drive_analysis_from_paramfile.make
  3. Once you have done this, you should see a file called LSDTT_analysis_from_paramfile.out in this directory. That is the program we will use to make some new topographic data!

2.2. Running your first analysis

It is now time to do some number crunching of your DEM using LSDTopoTools. In this part we will get slope, curvature and hillshade rasters.

2.2.1. Looking at the example data

  1. At this stage you should have a terminal window or secure shell window open in the Analysis_driver directory.

  2. Use the SECOND terminal window to go to the data folder (if you’ve not got another window, or secure shell, open one now).

  3. Use this second window to go to the LSDTT_workshop_data directory:

    $ cd /path/to/LSDTopoTools/Topographic_projects/LSDTT_workshop_data/
  4. We have provided an example parameter file in this directory. You can see all the stuff in the LSDTT_workshop_data directory by using the ls command:

    $ ls
    README.asc  WAWater.bil                       Workshop_ChiTool.driver
    WA.bil      WAWater.hdr
    WA.hdr      Workshop_AD_example.LSDTT_driver
  5. The file you want is Workshop_AD_example.LSDTT_driver. If you are using our Vagrant setup then this doesn’t need to be edited. But if you are running on an Edinburgh server or are using your own data, this file will need to be modified.

2.2.2. Modifying the LSDTT_driver file

Editing text files

We have parameter files (sometimes called driver files) that tell LSDTopoTools what data to look for, what analyses to do, etc. You will need to modify these files. You need a text editor to do this. You CANNOT use a word processor (like Word or Wordpad) since it inserts a load of formatting. You just need something that changes plain text without any fuss.

You can edit text in Linux using emacs or vim, but these are not great for people uncomfortable in Linux.

However, you don’t need to be in Linux to edit these files!

  • At Edinburgh, you can map your network drives so you can see files on our Linux servers and in your Windows or MacOS desktop. So edit your files there.

  • Outside Edinburgh, you should be using our Vagrant setup, and in that case files are synced between your Linux server and your native operating system so you can use a local text editor.

So what text editor to use?

  • If you have administrator permission on your computer, I recommend brackets for text editing. It works on Windows, MacOS and Linux.

  • If you are in an Edinburgh computer lab, you should have PSPad installed so you can use that.

  1. Hopefully you know what a text editor is (if not read the box above!). Open Workshop_AD_example.LSDTT_driver in a text editor. It looks like this

    # This is a driver file for LSDTopoTools
    # Any lines with the # symbol in the first row will be ignored
    
    # File information
    # IMPORTANT: you will need to modify the file path to reflect your directory structure
    # NOTE: If you want to use a smaller test DEM use WA instead of WAWater
    dem read extension: bil
    dem write extension: bil
    read path: /LSDTopoTools/Topographic_projects/LSDTT_workshop_data/
    write path: /LSDTopoTools/Topographic_projects/LSDTT_workshop_data/
    read fname: WAWater
    write fname: WAWater
    
    # Parameters for various topographic analysis
    min_slope_for_fill: 0.0001
    
    # Parameters for polyfit and slope calculations
    polyfit_window_radius: 19
    slope_method: polyfit
    
    # The different analyses to be run
    write hillshade: true
    write slope: true
    write curvature: true
  2. Whoa! What is all this stuff? There are instructions to our program telling the computer what to do. Most of this you can ignore (for now), but for us the important lines are:

    read path: /LSDTopoTools/Topographic_projects/LSDTT_workshop_data/
    write path: /LSDTopoTools/Topographic_projects/LSDTT_workshop_data/
    read fname: WAWater
    write fname: WAWater
  3. The two lines with path tell the program where to read and write the data.

  4. The read fname is the name of the file on which you will perform analysis. The read fname is the PREFIX of the DEM you will use. So if your DEM is called WA.bil then read fname: will be WA.

  5. To see where your data is, type pwd in the LSDTT_workshop_data:

    $ pwd
    homes/smudd/LSDTopoTools/Topographic_projects/LSDTT_workshop_data/
  6. YOUR directory will be different! Copy your directory into the file:

    read path: /my/directory/LSDTopoTools/Topographic_projects/LSDTT_workshop_data/
    write path: /my/directory/LSDTopoTools/Topographic_projects/LSDTT_workshop_data/
    If you are using vagrant the directories will work without any modification.
  7. You can also change the name of the data file. It can be your own data, or it can be the much smaller DEM WA.bil.

2.2.3. Checking filenames using LSDTopoToolsSetup.py

The python script LSDTopoToolsSetup.py, which you can read about here, allows you to check the directories of your files:

$ python LSDTopoToolsSetup.py -id 0 -cp True

If you called this script with -id 1 the first time you will need to do that again. Calling it with -cp True will go through all of the directories in the \LSDTopoTools\TopoTgraphic_projects folder modifying any files with extension .driver or .LSDTT_driver, updating the read path: and write_path entries with the correct path names.

2.2.4. Using your own data

If you use your own data you need to make sure it is in the correct format. You can read all about that in our main documentation. But the main points are:

  • Data MUST be in a projected coordinate system. We prefer UTM. To convert to UTM from anything else use GDAL.

  • Data MUST be in one of 3 formats, but I am only going to tell you about one since it is by far the best: ENVI bil. THIS IS NOT THE SAME AS ESRI BIL!!!. To convert from other formats to ENVI bil use GDAL.

2.2.5. Running the analysis

  1. Okay, at this point you should have modified the Workshop_AD_example.LSDTT_driver file so that it reflects the directory of your data and the name of your data. Don’t touch anything else.

  2. Go back to the terminal window where you ran the make command (remember, use two terminal or SSH windows: it makes things easer).

  3. In that window make sure you have the program: type

    $ ls LSDTT_analysis_from_paramfile.out

    If it says no such file or directory it means you are either in the wrong directory or have not compiled the program. If that is the case use pwd to figure out where you are and try to get back to the folder with the .out file.

  4. If you have that file, type

    $ ./LSDTT_analysis_from_paramfile.out /my/directory/LSDTopoTools/Topographic_projects/LSDTT_workshop_data/ Workshop_AD_example.LSDTT_driver
    You will need to update the path to reflect where your data is. The easiest way to do this is to type pwd in the terminal window with your data and copy it into the window with the program.
  5. When you run this command, the program will work for a little while and then spit out several rasters that will sit in your data folder. The raster that it prints are determined by these lines in the LSDTT_driver:

    # The different analyses to be run
    write hillshade: true
    write slope: true
    write curvature: true

    So hopefully it is obvious that you will get slope, curvature and hillshade rasters.

    $ ls
    README.asc   Workshop_AD_example_curvature.bil  Workshop_AD_example_slope.bil
    WA.bil       Workshop_AD_example_curvature.hdr  Workshop_AD_example_slope.hdr
    WA.hdr       Workshop_AD_example_hs.bil         Workshop_ChiTool.driver
    WAWater.bil  Workshop_AD_example_hs.hdr
    WAWater.hdr  Workshop_AD_example.LSDTT_driver
  6. The rasters have filenames that reflect what they are (HS, for example, denotes a hillshade raster). Okay, we can now move on to looking at the data!

2.3. Looking at the first analysis in QGIS

We are going to look at some of the resulting rasters in QGIS. The main reason for using QGIS and not ArcMap is that QGIS is open source and you can download it onto your home computer. ArcMap needs an expensive license. However, if you want to use ArcMap the steps are similar (the buttons are just in slightly different places).

  1. In QGIS the add data button looks like this:

    Add data
    Figure 2. Open raster data in QGIS
  2. Find the DEM (in the example WAWater.bil) and add it.

  3. Once you add data you will see it in the layers toolbar:

    QGIS layers
    Figure 3. QGIS layers

    You should see something like this:

    Whiteadder_Water
    Figure 4. DEM of the Whiteadder Water, Scotland
  4. If you want to change the colours right click on the layers and select properties:

    Raster properties
    Figure 5. Selecting the properties of a raster
  5. Then go into the Style menu and select Singleband pseudocolor

    Select pseudo colour
    Figure 6. Selecting the display of colours
  6. If you go to the "new color map" pull down you can select from a range of colormaps, and download yet even more by selecting "new color ramp" at the bottom. For topography the wiki-schwartzwald` gradient is nice. You can choose whichever one you want.

    New colour ramp
    Figure 7. Selecting a colour ramp (including loading new ones)
  7. To get this to work you then need to click on the classify button. Then click apply. You will get something like this:

    New coloured DEM
    Figure 8. Whiteadder Water DEM in colour
  8. Following a similar procedure you can load the hillshade, slope and curvature maps, for example:

    Hillshade
    Figure 9. Whiteadder Water hillshade
  9. If you want to make layers transparent, right click on the raster layer, select properties, and select the transparency tab.

2.4. Making a curvature mask

In this next step we will use the curvature data to make a masked plot. Curvature is a metric that tells us about where there are fluvial vs hillslope processes happening in a landscape, and has been used to infer erosion rates.

For this, we will use the LSDTopoTools_AnalysisDriver once again.

Sadly, the WAWater.bil raster is produced from data that is not amenable to a good curvature map. It is produced by the Ordinance Survey using a TIN and so the landscape is made up of triangular facets that have anomalous curvature values at the intersections and no curvature on the faces.

  1. You will need to run curvature on the WA.bil DEM instead. So make a copy of the driver file:

    $ cp Workshop_AD_example.LSDTT_driver Workshop_WA_example.LSDTT_driver
  2. Now you just need to adjust a few parameters:

    # This is a driver file for LSDTopoTools
    # Any lines with the # symbol in the first row will be ignored
    
    # File information
    # IMPORTANT: you will need to modify the file path to reflect your directory structure
    # NOTE: If you want to use a smaller test DEM use WA instead of WAWater
    dem read extension: bil
    dem write extension: bil
    read path: /LSDTopoTools/Topographic_projects/LSDTT_workshop_data/
    write path: /LSDTopoTools/Topographic_projects/LSDTT_workshop_data/
    read fname: WA
    write fname: WA
    
    # Parameters for various topographic analysis
    min_slope_for_fill: 0.0001
    
    # Parameters for polyfit and slope calculations
    polyfit_window_radius: 19
    slope_method: polyfit
    
    # The different analyses to be run
    write hillshade: true
    write slope: true
    write curvature: true
  3. Now run this file:

    $ ./LSDTT_analysis_from_paramfile.out /LSDTopoTools/Topographic_projects/LSDTT_workshop_data/ Workshop_WA_example.LSDTT_driver
  4. Once you’ve done this you should have a DEM called WA_curvature

2.4.1. Run the mask

  1. First, go into your data directory and make a another copy of the driver file:

    $ cp Workshop_AD_example.LSDTT_driver Mask_example.LSDTT_driver
  2. Now you just need to adjust a few parameters:

    # This is a driver file for LSDTopoTools
    # Any lines with the # symbol in the first row will be ignored
    
    # File information
    # IMPORTANT: you will need to modify the file path to reflect your directory structure
    # NOTE: If you want to use a smaller test DEM use WA instead of WAWater
    dem read extension: bil
    dem write extension: bil
    read path: /LSDTopoTools/Topographic_projects/LSDTT_workshop_data/
    write path: /LSDTopoTools/Topographic_projects/LSDTT_workshop_data/
    read fname: WA_curvature
    write fname: WA_curvature
    
    # Parameters for masking
    mask_threshold: 0
    mask_nodataisbelowthreshold: 0
    
    # The different analyses to be run
    write mask threshold: true
  3. The differences here are that you are using the WA_curvature raster instead of the DEM, that you are trying to write a mask threshold, and you are going to turn anything that is over the threshold value of 0 into a nodata (that is, you tell the computer it doesn’t have any data there).

  4. You can change this around a bit: if you run mask_nodataisbelowthreshold: 1 it means anything below the threshold is masked, and you can change the threshold value by changing mask_threshold:.

  5. Once you have done this try loading into QGIS and looking at this data over the hillshade using transparency (in the properties menu: right-click on the layer).

2.5. Summary

By the end of this chapter you should have created slope, curvature and hillshade rasters, and you should also have created a masked curvature raster.

3. Chi mapping

In this section we will use the LSDTopoTools chi tool program to calculate a map of chi (a Greek letter pronounced "kai") and chi slope. Chi slope is an indicator of how steep the channel is normalised for drainage area, and the chi coordinate by itself can be used to infer drainage capture and divide migration.

3.1. Making the chi tools

If you have jumped directly here, LSDTopoTools is distributed as source code in C++, so you have to turn it into a program using a compiler and a program called make. There is an easy way to do this, using a python script called LSDTopoToolsSetup.py, or you can do it one step at a time using make.

3.1.1. Making chi tools using LSDTopoToolsSetup

  1. If you followed the directions on setting up directories the easy way, you will already have the chi tools set up!

  2. If you haven’t already set things up with this file, download it and run EITHER:

    $ python LSDTopoToolsSetup.py -id 0

    OR

    $ python LSDTopoToolsSetup.py -id 1
  3. Doing this will set up LSDTopoTools in the root directory (in Vagrant). If you are not in vagrant, running it with -id 0 it put LSDTopoTools in your root directory (in any other Linux system), whereas -id 1 will put it in the directory from which you called LSDTopoToolsSetup.py. In vagrant, to get to the root just type:

    $ cd /

    To get to your home directory just type:

    $ cd ~

3.1.2. Making chi tools using make

The python script LSDTopoToolsSetup.py automates compilation of our source code, but in some cases you might want to compile things on your own (particularly if you start making changes to the source code).

  1. Navigate into the LSDTopoTools_ChiMudd2014 directory, and then into the subdirectory driver_functions_MuddChi2014.

    $ cd /path/to/LSDTopoTools/
    $ cd Git_projects/LSDTopoTools_ChiMudd2014/driver_functions_MuddChi2014

    The /path/to/ bit can be replaced by your own path (in my case it is /home/smudd/). In vagrant this is simply / since our vagrant setup puts the LSDTopoTools directory within the root directory.

  2. Then use make to compile the programs. You will get lots of warnings that can be ignored.

    $ make -f chi_mapping_tool.make
  3. Once you have done this, you should see a file called LSDTT_analysis_from_paramfile.out in this directory. That is the program we will use to make some new topographic data!

3.2. Running a chi analysis

Like the Analysis Driver from the previous chapter, the chi tool is run using a parameter file. We tend to put the parameter file in the same directory as the data. We find that it is much simpler to work with one terminal window open in the directory with the source code (/path/to/LSDTopoTools/Git_projects/LSDTopoTools_ChiMudd2014/driver_functions_MuddChi2014/) and another terminal window open in the directory with the data (/path/to/LSDTopoTools/Topographic_projects/LSDTT_workshop_data/).

3.2.1. Looking at parameter file

The parameter file for the chi tool is called Workshop_ChiTool.driver. It is set up to run on the small WA.bil raster. If you want to run on the larger WAWater.bil raster you just need to change the filename in the parameter file.

The parameter file looks like this:

# Parameters for performing chi analysis
# Comments are preceeded by the hash symbol
# Documentation can be found here:
# http://lsdtopotools.github.io/LSDTT_book/#_chi_analysis_part_3_getting_chi_gradients_for_the_entire_landscape

# These are parameters for the file i/o
# IMPORTANT: You MUST make the write directory: the code will not work if it doens't exist.
read path: /LSDTopoTools/Topographic_projects/LSDTT_workshop_data/
write path: /LSDTopoTools/Topographic_projects/LSDTT_workshop_data/
read fname: WAWater
channel heads fname: NULL

# Parameter for filling the DEM
min_slope_for_fill: 0.0001

# Parameters for selecting channels and basins

threshold_contributing_pixels: 2000
minimum_basin_size_pixels: 500
test_drainage_boundaries: false

# Parameters for chi analysis
A_0: 1
m_over_n: 0.45
threshold_pixels_for_chi: 2000

n_iterations: 10
target_nodes: 80
minimum_segment_length: 10
sigma: 10.0
skip: 2

# The data that you want printed to file
only_check_parameters: false
print_stream_order_raster: true
print_DrainageArea_raster: true
print_segmented_M_chi_map_to_csv: true
print_simple_chi_map_to_csv: true

There is a whole bunch of stuff in here, which you should mostly ignore. Here are the relevant lines:

  1. The lines that control the location of the files to read and write are here:

    read path: /LSDTopoTools/Topographic_projects/LSDTT_workshop_data/
    write path: /LSDTopoTools/Topographic_projects/LSDTT_workshop_data/
    read fname: WA

    You need to update these lines with your own directory structures. The read name: gives the prefix of the DEM. If you want the bigger dem, replace WA with WAWater.

    Updating your parameter files the easy way

    You can update the read and write paths to reflect your own directory structure by running EITHER

    python LSDTopoToolsSetup.py -id 0 -cp True

    OR

    python LSDTopoToolsSetup.py -id 1 -cp True

    You should use the same -id flag you used when you first set up LSDTopoTools.

  2. These lines control how dense the channel network will be when you run the code:

    threshold_contributing_pixels: 2000
    minimum_basin_size_pixels: 500
    test_drainage_boundaries: false
    
    # Parameters for chi analysis
    A_0: 1
    m_over_n: 0.45
    threshold_pixels_for_chi: 2000

    The threshold_pixels_for_chi parameter should not be larger than the threshold_contributing_pixels parameter. If these parameters are small you will get many channels, if they are large you will get fewer channels. minimum_basin_size_pixels should not be larger than threshold_contributing_pixels.

    If you keep A_0 equal to 1, then the chi slope will be the same as the channel steepness index, k_sn.

    # The data that you want printed to file
    only_check_parameters: false
    print_stream_order_raster: true
    print_DrainageArea_raster: true
    print_segmented_M_chi_map_to_csv: true
    print_simple_chi_map_to_csv: true
    1. The only_check_parameters is for bug testing: if true it will make sure your parameters will not immediately lead to a crash.

    2. The print_stream_order_raster will print a raster showing where the stream network is.

    3. The print_DrainageArea_raster will print a raster showing the drainage area.

    4. The two csv parameters are to print files that can both be read by either a GIS or by excel. The segmented is more complete, it has all the information of the simple_chi_map and more; the simple_chi_map only has the chi coordinate and location of the channels.

3.2.2. Some extra chi mapping parameters

The default of the chi mapping program is to only extract the chi values and slopes from the biggest basin. You can get the chi slopes and values for all basins by adding the following line to the parameter file:

only_take_largest_basin: false

You can print the chi values to a raster (rather than csv) with the line:

print_chi_coordinate_raster: true

3.2.3. Running the analysis with the parameter file

  1. If you’ve done the analysis driver exercise, this should be familiar.

  2. Go into the directory where you compiled the chi tool and run:

    $ ./chi_mapping_tool.exe /path/to/LSDTopoTools/Topographic_projects/LSDTT_workshop_data/ Workshop_ChiTool.driver
  3. The program should spit out a bunch of text, and afterwards you will be left with some new files, which we will look at in QGIS in the next section.

3.3. Looking at the chi map in QGIS

One we run the analysis, we can have a look at the results in QGIS. The steps will be similar in ArcMap, but we show QGIS here since it is open source.

  1. In QGIS the add data button looks like this:

    Add data
    Figure 10. Open raster data in QGIS
  2. Find the data rasters and add them:

    1. WA_DArea.bil

    2. WA_SO.bil

  3. To change the styling of these, see the section Looking at the first analysis in QGIS.

  4. Here is a coloured version of the stream order raster:

    stream order
    Figure 11. Stream orders over the elevation raster of the Killmade Burn, Scotland

3.3.1. Adding csv data

  1. It is a bit more difficult to add csv data (csv stands for comma separated values). In QGIS, you need to click on the layer menu and then scroll to the add text delimeted layer button:

    Add csv
    Figure 12. Add csv data
  2. We will add the WA_MChiSegmented.csv layer. Once you select that file (using browse) you will see something like this:

    Create layer
    Figure 13. Create layer menu
  3. Hit okay. You will then be asked what coordinate system you want. All csv data from LSDTopoTools is in the WGS84 coordinate system! Your rasters are typically in a local coordinate system but we convert point data to WGS84 so that they can be loaded onto web mapping platforms (i.e., Google Earth). The upshot is that you need to use WGS84 for the coordinate system.

  4. All coordinate systems have a code, called an EPSG code, and the EPSG code for WGS84 is 4326: search for this (in the Filter form) and select it:

    EPSG:4325
    Figure 14. Choose WGS 84 coordinate system with EPSG:4325
  5. You should get something that looks like this:

    Chi point data
    Figure 15. Point data
    Sometimes you need to click in the little symbol that looks like a globe in the bottom right corner of QGIS an enable on the fly CRS transformation.
  6. Okay, this doesn’t look so great, right click on properties of the layer, choose graduated symbols, select the m_chi column (this is chi slope) pick a nice colour ramp, and then click on classify:

    Chi map
    Figure 16. Chi map coloured by chi steepness

3.4. Summary

By the end of this chapter you should have created a map of chi and chi slope, and loaded these data into QGIS for inspection.

Appendix A: Using the LSDTopoToolsSetup.py script

To help you set up LSDTopoTools, we have written a series of modules in python that automate the creation of our standard directory structure, downloading of the source code and compiling the source code into programs. The script is called LSDTopoToolsSetup.py.

A.1. Getting the LSDTopoTools setup script

LSDTopoTools works in all popular operating systems (Windows, MacOS, Linux) by using Vagrant to create a Linux server within your host operating system: if you are not in a native Linux environment you should start a Vagrant server by following these directions.

Once you have done that, you should be able to ssh into a Linux session using putty.exe on Windows or the vagrant ssh command in MacOS and Linux.

Once you are in a Linux operating system, the easiest way to get the script is to use the utility wget:

$ wget https://raw.githubusercontent.com/LSDtopotools/LSDAutomation/master/LSDTopoToolsSetup.py

A.1.1. Alternatives to wget

You can also get the script by cloning the LSDAutomation repository:

$ git clone https://github.com/LSDtopotools/LSDAutomation.git

or you can got to the raw text of the file, then copy the text and paste into your favourite text editor (i.e. Brackets). You should save the file as LSDTopoToolsSetup.py.

A.2. Running the LSDTopoTools setup script

The setup script is a python script so you need python to run it. It should be run in Linux, so if you do not have a native Linux operating system the script should be run in your Vagrant server. Almost all flavours of Linux come with python installed as default (the Ubuntu system installed by our vagrantfiles is one example) so we will assume you have python.

The script requires parameters; if you run the script with no parameters, it will give you a message telling you what to do:

$ python LSDTopoToolsSetup.py

=======================================================================
Hello there, I am the going to help you set up LSDTopoTools!
You will need to tell me what to do.
If you are in vagrant, LSDTopoTools will always be installed in the root directory (\).
If you are not in vagrant,
LSDTopoTools will be installed in your home directory if you run this with:
   python LSDTopoToolsSetup.py -id 0

Or your current directory.
(i.e., the directory from which you called this program)

if you run with this:
   python LSDTopoToolsSetup.py -id 1

For help type:
   python LSDTopoToolsSetup.py -h

=======================================================================

A.2.1. Looking at all the LSDTopoToolsSetup options

You can call help for the LSDTopoToolsSetup.py script with:

$ python LSDTopoToolsSetup.py -h

A.2.2. A default setup

In fact, there is no default setup, since you have to tell the tool where to install LSDTopoTools. You do this by using the -id flag.

  • If you select 0, LSDTopoTools will be installed in your home directory, which you can get to with the command cd ~.

  • If you select 1, LSDTopoTools will be installed in the current directory (i.e. the directory where the script is located).

  • If you are running a vagrant machine, these instructions will be ignored and LSDTopoTools will be installed in the root directory (you can get there with the command cd \).

This will install a directory LSDTopoTools with subdirectories Git_projects and Topographic_projects. Each of these folders will clone subfolders from our github pages, and will compile the Analysis_driver as well as the chi_tool.

The directories will look like this:

/LSDTopoTools
  |--Git_projects
  |----LSDTopoTools_AnalysisDriver
  |----LSDTopoTools_ChiMudd2014
  |--Topographic_projects
  |----LSDTT_workshop_data
  |----Test_data

A.2.3. Other setup options

There are a number of other options on LSDTopoToolsSetup.py, which we will list here, as well as in the table below.

  • -CE True Clone and compile the channel extraction programs used in Clubb et al, WRR, 2014.

  • -MChi True Clone and compile the tools for performing the chi analysis of Mudd et al., JGR-ES, 2014.

  • -CRN True Clone and compile the tools for calculating basinwide denudation rates from the cosmogenic nuclides 10Be and 26Al Mudd et al., ESURF, 2016.

  • -cp True Check the path names in all the subfolders in Topographic_projects to reflect your own directory structure.

A.2.4. If you are running on native Linux

If your native operating system is Linux, you should be able to get LSDTopoTools working very quickly using LSDTopoToolsSetup.py without having to use vagrant. However, you do need to ensure that you have the utilities make, the gnu Pass:[C++] compiler installed, and also you need FFTW installed. If you are in Ubuntu installing FFTW is as easy as: sudo apt-get install -y libfftw3-dev. If you are in another flavour of Linux you will need to follow the full setup, which is described on the FFTW website. Once you have that stuff working, you can use LSDTopoToolsSetup.py to get everything working in a jiffy.

A.3. Table of LSDTopoToolsSetup.py options

Table 1. Installation directory options
Flag Input type Description

-id

Integer, either 0 or 1

0 == home directory, 1 == current directory. If you are in vagrant it will ignore this option and install in the root directory.

-CRN

Boolean (either True or False)

If this is True, installs the CAIRN CRN package for calculating basinwide denudation rates from the cosmogenic nuclides 10Be and 26Al Mudd et al., ESURF, 2016.

-CE

Boolean (either True or False)

If this is True, installs the channel extraction programs used in Clubb et al, WRR, 2014.

-MChi

Boolean (either True or False)

If this is True, installs the tools for performing the chi analysis of Mudd et al., JGR-ES, 2014.

-cp

Boolean (either True or False)

If this is True, checks the pathnames of the parameter files .driver and .LSDTT_driver in all the subfolders of Topographic_projects and corrects them so they reflect the user’s directory structure.

Appendix B: Making directories for Vagrant

This appendix walks you through making the correct directories in you host operating system. This could be windows or MacOS. If you are working in Linux, it makes no sense to use Vagrant. Instead, you should use our script LSDTopoToolsSetup.py.

B.1. Creating directories for Vagrant in Windows.

You could do all of the following steps using windows explorer, but the rationale here for doing it in a powershell is that you can copy and paste from these instructions to make sure the directory names are correct.

  1. Open a powershell window. You can do this by clicking on the start button and typing "powershell".

  2. Now go to the C:\ directory:

    PS > cd c:\
  3. Now make a directory called VagrantBoxes:

    PS C:\> mkdir VagrantBoxes
  4. Go into this directory and then make two additional directories (the names are below):

    PS C:\> cd VagrantBoxes
    PS C:\VagrantBoxes> mkdir Ubuntu
    PS C:\VagrantBoxes> mkdir LSDTopoTools
    You could call the "Ubuntu" folder anything you like (sometimes I call them Ubuntu64 or Ubuntu32) but the name of the LSDTopoTools folder is ESSENTIAL": it has to be spelled exactly like that and is case sensitive (i.e., lsdtopotools or LSDtopotools will not work, it has to be *LSDTopoTools).
  5. Now go into the Ubuntu folder (or whatever you called it) and get one of our vagrantfiles using wget. You will need to be online to do this! Then rename the file:

    PS C:\VagrantBoxes> cd Ubuntu
    PS C:\VagrantBoxes\Ubuntu> wget https://raw.githubusercontent.com/LSDtopotools/LSDVagrantFiles/master/Vagrantfile_32bit_FFTW
    PS C:\VagrantBoxes\Ubuntu> mv Vagrantfile_32bit_FFTW vagrantfile
    This will only work with Windows 10. Windows 7 has an old powershell version that doesn’t have wget. I don’t know about windows 8 but nobody has that anyway. If you have an older version of Windows you need to save the vagrantfile as vagrantfile (NO EXTENSION!!) in your Ubuntu directory.

B.2. Creating directories for Vagrant in MacOS.

The author of this section does not use MacOS so these are actually educated guesses. In the future I hope to sit down with a Mac user and make sure it works but for now there is a possibility this won’t work.
  1. Open a terminal window. I guess you use finder to do that. I wouldn’t know since I don’t use MacOS.

  2. Once you have a terminal window open, we are in Linux world since MacOS is written on top of Linux! Yay! It is so nice to be in a familiar operating system (for me, at least.)

    We are going to put stuff into your "home" directory. Go there by typing this:

    $ cd ~
  3. Now make a directory called VagrantBoxes:

    $ mkdir VagrantBoxes
  4. Go into this directory and then make two additional directories (the names are below):

    $ cd VagrantBoxes
    $ mkdir Ubuntu
    $ mkdir LSDTopoTools
    You could call the "Ubuntu" folder anything you like (sometimes I call them Ubuntu64 or Ubuntu32) but the name of the LSDTopoTools folder is ESSENTIAL": it has to be spelled exactly like that and is case sensitive (i.e., lsdtopotools or LSDtopotools will not work, it has to be *LSDTopoTools).
  5. Now go into the Ubuntu folder (or whatever you called it) and get one of our vagrantfiles using wget. You will need to be online to do this! Then rename the file:

    $ cd Ubuntu
    $ wget https://raw.githubusercontent.com/LSDtopotools/LSDVagrantFiles/master/Vagrantfile_64bit_FFTW
    $ mv Vagrantfile_64bit_FFTW vagrantfile
    Some MacOS machines have 64 bit guest operating systems disabled so you might have to use the 32 bit version (just change the 64 to 32 above).

Appendix C: Plotting LSDTopoTools output with Python

Much more effort has been put into DEM analysis with LSDTopoTools than visualisation since outputs are readable by GIS software such as QGIS and ArcGIS. However we do have some python scripts that are aimed at creating perfectly reproducible figures. This appendix will give some of the basics of using our visualisation scripts.

This component of LSDTopoTools is under constant development and is therefore quite buggy. The basic functions should be accessible to new user but it will help if you know some python. You might try to learn via codeacademy.

C.1. Setting up Python

This is a quick guide. There are a lot of options for setting up python but this is our preferred setup.

Do not set up python in a vagrant server. Instead do it in your host operating system. The vagrant server is a stripped down version of Linux that cannot generate windows so you can have only limited functionality of these tools in a vagrant server.
  1. The best way to install python is miniconda. We will use Python 2.7, so use the Python 2.7 installer.

  2. Once you have installed that, you can go into a powershell (windows) or terminal (MacOS and Linux) and get the other stuff you need:

      PS> conda install scipy
      PS> conda install matplotlib
      PS> conda install pandas
      PS> conda install gdal
      PS> conda install spyder
  3. To run spyder you just type spyder at the command line.

    Spyder needs an older version of a package called PyQt. If spyder doesn’t start correctly, run conda install pyqt=4.10 -f

C.2. LSDTopoTools python plotting functions

I am afraid this is a bit disorganised, since it has developed organically and we haven’t had time to clean everything up.

You should get our plotting and mapping tools from our github repositories. Here is the next irritation: if you are using a vagrant server, the tool git is installed on your Linux server. But we suggest you run python in your host operating system (e.g., Windows). Meaning you should install git on your host operating system.

C.2.1. Getting git

  • Linux: git is probably already on your system but if not you can install with any package manager (e.g., sudo apt-get install git).

  • Windows: Download and install git for Windows.

  • MacOS: Download and install git for MacOS.

C.2.2. Getting our plotting tools

  1. Make a directory to hold the plotting tools. I usually call the directory for git projects "Git_projects".

  2. In Windows, right click on this directory and select "Git bash here". For this to work you will have needed to have installed git for Windows first.

  3. In Linux or MacOS, open a terminal and go to this folder.

  4. Clone our plotting repositories from github (this grabs the files from github):

  5. Getting files from github. In MacOS and linux the prompt will be $, in powershell it will be PS>.

    $ git clone https://github.com/LSDtopotools/LSDMappingTools.git
    $ git clone https://github.com/LSDtopotools/LSDAutomation.git
    $ git clone https://github.com/LSDtopotools/LSDPlotting.git
  6. You should have all the python files you need now.