1. Forewords

This guide aims to explain our Python bindings for LSDTopoTools algorithms (as many as possible). In this guide, we will go through:

  • The reasons of developping such a tool

  • How to quickly install and use it on Windows, linux (and probably Mac)

  • (Ongoing work) How the code works and how to run the different routines

  • (TO DO) Our set of automated plotting routines and how to build yours

  • (TO DO) And finally a development guide for the lower-level interfaces

These tools are still in early development and might be quite unstable.

2. Introduction

LSDTopoTools is an open-source research software proving a large set of algorithms to quantitatively describe the morphology of landscapes. It covers a wide range of geomorphological applications with preprocessing routines (e.g., depression filling or carving, filtering), flow routines (Flow direction, accumulation, node ordering, …​), channel network extraction and advanced channel head location (TODO::references), blabla TODO::List application with references before uploading that online
The core of he code is written in cpp, a fast and compiled low level language. Its main advantages is its speed, its flexibility (fine grained management of memory and cpu) and its wide community. Our algorithms are widely tested and developped in cpp and direct access is available through source code and docker containers (TODO:: ink to other doc pages).

2.1. Why a Python Version

This section is just about how and why we developped that version. If you just want to use it, you can skip that part.

python has many advantages:

  • Free and open-source, making it a research-friendly language, as research should be accessible to anyone without the need of expensive proprietary software (not all universities, research institutes or individuals have access to MATLAB, ArcGIS or ERDAS for example).

  • Popular, it has a HUGE (I cannot make that bolder) community ready to help if you have a question (e.g., stackoverflow, issue system on github).

  • python is easy-to-read and has several level of difficulties: it can only be used as a scripting language (= just telling few instruction to the computer, basically as easy as talking to a child) if needed but can be way further if needed.

  • Packaged-based: you can install bit of codes other people made really easily and use it. No need to reinvent the wheel if it is already fast enough.

  • Finally, it is simple to install and universal: you can use it on Windows, Linux, Mac, …​ ++

Of course python also has some drawbacks. It simplicity comes with a cost of performances:

  • Large numerical operations in pure python can quickly become slow and you need to find the package that has been optimising the specific routine you want and has binded it to python. This is the case for most of the "common" routines (e.g., see scipy and numpy for an impressive collection of fast and fully coded numerical routines), but everything is not coded yet.

  • Python can become a bit confusing as there are many different ways and packages to do a tasks.

    These are the reasons we are still coding in cpp and providing access to these fast and optimised routines from python: It combines the simplicity, portability and software-catalog of python with the raw powerfullness of cpp. The only remaining drawback is that it requires some gymnastics behind the scene to transfer data between the two and to make easy installer, but you won’t care about that because we are doing it for you.

2.2. How

Some wonderful tools have make this binding possible and deserve credits: - xtensors, a cpp data structure with (inter alia) in-built linkage with the universally used python numpy ndarrays. This is developped by Quantstack, I recommend having a look on the tools they develop for research, they are truly amazing

  • pybind11, a complete toolbox to bind cpp data structure to python objects. This low-level interface, lsdtt_xtensor_python, is the backbone of the bindings: it communicates directly with cpp and deal with internal memory ownership and this kind of questions.

Using these tools, we provide two packages to use our code from python:

  • lsdtt_xtensor_python, a low level interface. You may be interested by using directly this backend only if you want python access to the cpp code with minimum dependencies: if already built in pip, it only requires pybinds and numpy to run but requires minimum knowledge on LSDTopoTools code structure.

  • lsdtopytools, built on the top of lsdtt_xtensor_python, it provides a user friendly interface to the code with straighforward functions and lot of automations. It also provides additional routine to loads most of the raster types (e.g., tif, bil, ASCII grids), easy I/O operations, visualisations, and can easily be linked with any other packages.

  • A command line interface (Undocumented so far): it allows you to quickly use lsdtt without writting code in a text file. For example creating a slope map, or extracting the sources, or creating automatic figures. Easier and quicker to use, they are however less customisable.

3. Before Installing

This section has been written as a clarification following many emails expressing confusion between the command prompt, python and python/computing environments. These can be confusing for user not used to programming without graphic interaction (ie clicking on stuff) so here is a plain language explanation with potentially questionable analogies. If you already know basics about command prompts and python, jump to Installation.

Programming involve using tools that are similar enough to be confusing if you are not use to it. Therefore, before installing and using lsdtopytools, clarifications seem to be required about the differences between python, computing environment and command-line interfaces (terminal/prompt) and how it actually works. This explanation is in plain language and aim to gently introduce some concepts before actually learning the commands.

3.1. Command-line interface: what and why?

The every-day way of using a computer is a graphical interface: you tell the computer to run a program by clicking on it. For example if you want to open a specific image, you just navigate to its folder in the file explorer by clicking on the different folder names and then on the image to open it. The computer knows how to open the image file thanks to its extension. If you want to modify it, you right click on it and use "open with" and select paint, gimp or whatever program you want.

Command-line interfaces (or console, terminal, prompt) are simply another way to tell the computer the same procedure (and actually the original way). Let’s stick to the aforementioned image analogy. Rather than clicking on folders to navigate to the one containing the image, you just write your way through it with commands. For example moving inside a folder called "image" is "cd image" and is the direct equivalent of clicking on the folder. Then, you have to command the computer to open the image with the right program: preview name_of_image.png (equivalent of double-clicking on it to visualise it with the default preview software) or "gimp name_of_image.png" (equivalent of right click and open with gimp).

Alright now why are we self-inflicting this "more complex" way. There are many reasons to that:

  • Speed. Open ArcGIS and enjoy waiting the software to start, then load and display your rasters before even starting thinking about which analysis you’d like to run. Any graphic interface consumes significant resources from your computer and therefore time, whether you need to visualise it or not before running the analysis.

  • Reproducibility. You can make ArcGIS (or QGIS) reproducible but it is not straightforward: you’d have to detail any click you have made and write any parameter you gave to any toolbox you used. Then the user has to reproduce each steps exactly by entering itself the parameters, increasing the risk of typos and errors. With command line, everything is written and multiple commands can be re-executed if written in a text file (ie script). You want to re-run EXACTLY the same analysis on a different raster? Just change the name of the raster in the text file and that’s it.

  • Flexibility. This one concerns any person that want to automate or develop their own routines and new tools with our framework. Developing graphical interface takes a loooooooooooooot of time, constrain the program and kill any automation possibility: you can write multiple commands in a text file to be automated, you cannot click in advance, this is as simple.

These are the reasons we are using the command line to help installing, using and developing our framework.

3.2. Python interpreter vs commands

You will quickly realise (and send us email to ask why) writing python code in the command prompt won’t work and writing command lines in the python scripts will trigger error messages. These two are different things that can be easily confusing. python is a software (exactly like ArcGIS or MATLAB). It’s aim is to interpret the python language into machine language to run numerical operations. It is therefore made to understand python codes, usually written in scripts (ie text files containing text following a python syntax). Command prompt don’t understand syntax written for python, python does. python does not understand if you talk to it like a computer, the command prompt does.

We use the command prompt to run our python scripts by writing python name_of_script.py which means "computer, please use python to understand the text I have written in the file name_of_script.py". We have written a python version of our tools, therefore your text (code) detailing which way you need to use lsdtopytools will go in that script.

We also have written some programs that directly run from the command prompt if you need out of the box and without the need of writing python syntax. These will be installed with the tools but have different names, for example the following command lsdtt-basic-tools file=mydem.tif slope means "computer, please use the program called lsdtt-basic-tools on the file mydem.tif (hopefully you are naming your file better than me) with the analysis slope.

The python syntax allows you to customise your set of routines and even combine it with others written in python whereas our command line tools are prewritten, less customisable, easier routines to use.

3.3. Computing environment, or the answer to the relentless "Why is python so hard to install" question

Alright, if you open a command prompt now and write lsdtt-basic-tools or python name_of_script.py, your computer will tell you something like "I don’t recognise what your command" or "python did not manage to import lsdtopytools" which basically just means that you haven’t install the tools yet: the computer cannot guess what you want to run and we do not have a contract with computer manufacturer to pre-install our tools on all the computers in the world (yet). Although python might be recognised as extremely common software, it is just an interpreter, it still requires our tools to be included in it.

Actually, python works the following way: it creates a computing environment and stores a bunch of packages that contains other codes. It calls these different codes together for you so you do not have to recode all the algorithm of the world. It also simplify a lot of programming aspects if you do not wish to use it (data type, memory management, etc.). python therefore is just a "glue" that gather multiple codes together. Short story long you just have to add our bunch of code (lsdtopytools) to your computing environment and then you can use python syntax to call it. python in our case acts as a glue between pieces of other codes that read geolocalised rasters, pieces of our codes that run the analysis, pieces of codes that plot it, etc. .

Most of the difficulty in using python lies in the complex connectivity between the bunch of codes you need: some glues are incompatible with others. python is open-source and free so anyone can write code for it making it impressively suitable for science but also increases the risk of having buggy packages and incompatible glues. Which is the reason why we use an environment manager called conda (detailed later). It allows us to tell the computer "Alright, I know you sometimes struggle gluing complex python packages together, so here is a tool that will store separate boxes that only contain compatible glues. I will just create a lsdtopytools box, putting all my compatible DEM analysis glues in that box and let you know when I want to use python inside that box OK?" (the computer won’t actually answer you). This guide will just show you how to create and use that box. Therefore the common sentence "I tried python once and did not manage to install it so I gave up. Have you tried MATLAB ? It is so easier" does not make sense. You just tried to use a specific python glue and struggled because you did not use one of these isolated box, or the code is badly managed (anyone can create python packages, there is no quality check). MATLAB is proprietary, it provides a closed unaccessible black box that comes already built for anyone that pays for it. Our tools are written in c++, and we use python glue to make it easier to use and install (python backbone is written in c so we can easily link the two), and comparing it with MATLAB does not make sense as it would be very difficult to bind it inside the closed box. Here is the price to use MATLAB (not every institution, company or university has access to it) and here is the price of using python: 30 minutes of your time to learn how to install it and manage the boxes. If you wish to use MATLAB for topographic analysis, the excellent TopoToolBox is a tool that has been developed within MATLAB framework and is adapted for it. It provides a different set of analysis than our tools.

4. Installation

Soon, a conda receipe will be available, making the installation extremely straightforward. But before that, it still requires few simple manipulations as I am still working on the best way to do it.

If you know how python works

Quick instruction if you are used to python environments:
lsdtt_xtensor_python (required for any use)
So far there are two cases: either we have already built binaries for your OS/cpu:
pip install lsdtt_xtensor will be extremely fast and easy, we have wheels for windows for sure at the moment (linux is somehow tricky, and I don’t have a mac).
Otherwise you have to build it on your own machine (soon to be sorted with the conda reicepe):
conda install -c conda-forge pybind11 xtensor xtensor_python numpy
Then you need a cpp14 ready default compiler (again, this is temporary). If you reach this stage, you are probably on linux so install a gcc>=5 and you shall be alright. pip install lsdtt_xtensor will now take a while but will work (it is directly compiling the code on your machine).
lsdtopytools and command-line (for the simple interface)
Relatively easy: Install the dependencies and then the package.
conda install -c conda-forge numpy scipy pandas numba matplotlib gdal rasterio h5py
pip install lsdtopytools

The following guide gives you a step-by-step installation guide. It assumes no particular knowledge in computers/coding and will point to external tutorials when potentially needed. It will also explain the different steps, you don’t have to read it if you are in a hurry, but te more you understand what is happenning in the computer, the easier it is to debug it (and indirectly, less complaining emails for us as well).

4.1. A python environment

If you already are confortable with python and already have your own environment, you can skip that part.

4.1.1. What is a python environment and why

The first step is to create a python environment. As stated before, python is a "packaged" language: all the code take advantage of other bit of codes made by the community called packages. The (really) good thing with it is that a lot of algorithms are already coded and you can integrate it in your python environment easily.
The backside is that many packages relies on specific version of other packages and there can be some conflict when the environment becomes massif, the same way ArcGIS extentions are only compatible with some versions of the main software, or MATLAB scripts that absolutely require the specific version 2015rc4267-21f-march2016v2.5 to run.
On the bright side, python is free and open-source, you can therefore install as many versions of python and its packges as you want. We strongly advice to use miniconda (or anaconda) as environment manager: you can create and activate different environments with their own packages. Even better, we can provide templates of environments to make it easy-to-install.
A practical example: you can have one environment with lsdtopytools installed to run topographic analysis, a separate one with landlab to deals with modelling or even play with the packages to mix both tools in the same environment and run it together.

4.1.2. Installing ana/miniconda

You can download miniconda from this website, and install it. It does not matter whether you have miniconda or anaconda: these are just light and full versions of the same tool. We advice miniconda to only install what you need and we advice python 3.6 or 3.7: we only tested our code on these versions. The code is theoretically compatible with 3.5, 3.4 and 2.7 but I would imagine that if you need such a specific version of python, you’ll know how to deal with custum installation. Also, you need to know if your computer is 32 (if old) or 64 bits (most of post 2010 computer).
You do not need admin right to install conda on your machine in case you are using institutions servers or computers.

4.1.3. Terminal, cmd or conda prompt

As many (scientific) tools, the scripts need to be ran in a console/terminal/command prompt/whichever name you want. Many reasons for that: easier to manage, control and automate; quicker; actually easy to use. The only bad side is that it looks less attractive than a nice graphic interface. Basically, rather than double clic on a folder, you need to write cd name_of_the_folder to chagne the current directory for instance.

On Windows

After installing conda on windows, you can open a conda prompt from your start menu. Then you will be sure to be inside your conda environment and ready to navigate through your file tree to run programs. Here is a random tutorial found online to learn to basics. There are many, you don’t need advanced knowledge, basically jsut how to navigate through folders, list the files in the folder and stuff like that.

On linux

Depending on your python uses, you can either (i) add it to your PATH and make it your default python environment (it can make other program using default python unhappy, it is rare but it can happen); (ii) Follow these instructions. I assume you know how to deal with a terminal if you are using linux.

On Mac

Who knows, it should be similar to linux anyway.

4.1.4. Creating environment

You are now within a conda environment that includes python. Let’s have a clean install, cleaner computing is easier to debug. The following command creates a ("sub")environment in you conda installation, where we will install the packages we need. To run the command, just copy-paste it in the terminal and hit enter.

conda create -n lsdtopytools

Once created, the environment just need to be activate each time a new terminal is opened! You just have to run the following command:

conda activate lsdtopytools

You’ll know it is activated if (lsdtopytools) is displayed in your terminal. If you have an old version of conda, you may face a message error. You just have to use this command instead:

source activate lsdtopytools

We’re basically done with environment stuff. You can create as many (or as few) environments as you need for your different programs (e.g., landlab, opencv).

4.1.5. Installing the packages (Soon to be automated):

let’s now install the required tools to run lsdtt_xtensor_python (the cpp-python mediator): we take advantage of carefully selected bits of other codes to help us.
The following command installs package. install means (surprise) install, and -c conda-forge means from the channel (= repository) "conda-forge" which is in plain language a big pile of easy-to-install python packages. + The following keywords are the name of the packages: (i) pip, it makes easier python packages installation, (ii) numpy, an EXTREMELY used and powerful tools for arrays and matrix calculations. It is written in fortran and c, therefore its built-in functions (e.g., sum, median, reordering, and millions of common tools) are fast. (iii) pybinds, requires to link cpp to python.

conda install -c conda-forge pip numpy pybind11 xtensor xtensor-python

You environment is ready for lsdtt_xtensor_python:

pip install lsdtt_xtensor_python
This was the trickest part, if the terminal throw a lot of error messages, it means that I did not manage yet to precompile the code for your platform. I am working on it but so far you need to build the package by yourself: it should be temporary. On linux: you need to install a recent compiler gcc/gXX>=5 or any recent clang and to make sure it is your default compiler. Then you jsut need to install two other dependencies: conda install -c conda-forge xtensor xtensor-python and if you rerun the above pip command it will run for approximatively 10 minutes and install the package. On Windows: compiling on windows is fxxxxxg pain, I fought long long (long) hours to generate a wheel (compiled python package) theoretically compatible with any 64bits windows to avoid this issue, contact me if my wheel failed for you. On Mac: see linux.

lsdtt_xtensor_python is required for any use of the python tools, but only provide minimal interface with the cpp code and require knowledge of its structure. You probably now need lsdtopytools, the full, user-friendly interface that also provide (will provide actually as it is work in progress) easy raster loading/saving, ergonomic data management and visualisation routines. This however requires a bunch of other packages to be install: the simplest a program is, the bigger the amount of code behind is.
lsdtopytools, even if you won’t inteact with most of these, basically requires the following packages:

  • gdal: a package, mostly in C that can deals with all the geodesy: projection, transformation, raster downsampling, WGS to UTM and billions of other tasks you don’t want to face manually. More Information.

  • rasterio: provides a nice interface to gdal, because I also want to simplify my coding when possible. More Information.

  • scipy: alongside with numpy, it provides quick and useful stats, filters, modelling, math, etc routines for pre/post-processing. More Information.

  • pandas: provides table-like data analysis tools. Very useful to manage dataframes of thousands/millions of river points for examples. More Information.

  • matplotlib: paper-quality plots, unbeatable in this domains even if a bit frustrating sometimes. More Information.

  • numba: I will get rid of that dependency at some point, it provides speed-up on some internal part of older code I used. Not really needed now I can send stuff to cpp directly with numpy, but I’ll need time to recode these few routines, sns. More information.

  • h5py: is (will be, may be, idk yet) used to save file to the disk: fast and well structured, it is theoretically a better alternative to csv files. Outputs with csv will still be available to link with Arc/QGIS if needed. More Information.

    To install, simply run:

conda install -c conda-forge gdal=2.2 rasterio scipy pandas matplotlib numba h5py pytables numpy

It shall run for few minuts to install these dependencies, and finally you are ready for the last bit:

pip install lsdtopytools

This one should be universal (i.e., Compatible with with any OS as pure python stuffs).

And we are done with the installation!

4.1.6. Troubleshoot

There will be some, no worries.

5. Getting started with lsdtopytools

This chapter will explain the basics and general uses of lsdtopytools. The best way to learn is to practice: we therefore provide this code documentation for the details about each routines, but also an (hopefully at some point) example folder on the github page with practical cases you can just copy and adapt to your needs.

5.1. Code structure and philosophy

5.1.1. Python

python is a nice high-level programming language. It is part of the interpreted languages, meaning that each line of code is interpreted one by one by a software (here python), other well-know free examples are perl, R, Julia or the somehow popular not free and not open source MATLAB. These languages are useful to take abstraction of complex machine interaction such as memory management and control other more complex underlying code. There is no need to have advanced python or coding knowledge to use our tools, python is easy to write and read. Code academy offers a nice tutorial to get the basis (not mandatory but can be useful).
To run a custom python script: simply navigate to the right directory within your conda terminal (see installation instructions) and run python name_of_my_script.py.
If you don’t want to learn this useful tool, use the command-line interface.

5.1.2. lsdtopytools coding style

lsdtopytools is coded in an object oriented logic: we have some precoded routines absed on a common template that you just need to construct with your custom parameters. Basically all our routines are based on an original DEM that you load first. Then each routines depends on others and the code deals internally on how to call these interaction. This sound probably fuzzy so let’s illustrate with an example:
Let’s imagine you have a geotif DEM of your area and you want to extract channel steepness. You need many information to do so: the code needs to know the flow direction of your DEM cells, it needs to know the drainage area, which pixels is a river and many different bits of data you probably don’t have yet. Thanks to the object orientation you just have to call the ksn extraction routine and the code will know what it needs to calculate beforehand, tells you what it is defaulting and what you could add to cusomise each steps and finally run the wanted routine.

5.2. Getting started

Your data needs to be in UTM projection to work correctly. Geographic system (e.g., WGS84) are not in metres, therefore the metrics are not straightforward to understand.

5.2.1. Load your data into the system

The first step of each routines is to load the base raster: your dem from which the metrics will be calculated. You simply need to import the code (as any python code) and load the dem as follow:

from lsdtopytools import LSDDEM # LSDEM is the object template abovementioned

my_dem = LSDDEM(file_name = "name+of_my_dem.tif")

+ THis is the simplest way to load a dem. It however implies that your dem is in the same folder than your python script. You can load a de with the following options:

, path = "./", file_name = "test.tif", already_preprocessed = False, verbose = True)

  • path: the path to your file. On windows it can be "C:\Users\s1675537\Desktop\", on linux "/home/s1675537/Data/". If you don’t give this option, the default value is "./": it means current folder.

  • file_name: the file name with the extension. lsdtopytools relies on rasterio and gdal to load raster. It can (theoretically) understand these formats. The most common are working (e.g., .tif, .bil or ASCII grids).

  • already_preprocessed (boolean): False if your DEM needs preprocessing (see Raster preprocessing) and True if already preprocessed externally.

  • verbose (boolean): The code can talk: it details what it is doing and tells you where there are some important warnings. Activated by default, you can turn it off with verbose = False if you want less outputs.

    We are basically done with the initialisation, all the different metrics generated from DEM require this line of code at the beginning of a script. The next parts will describe the different routines.

5.2.2. Running a routine: general case

Before explaining each routines, all of them are build following the same pattern around the LSDDEM object. You call the routine ON the object the following way:

...

my_dem.routine_name(routine_param1 = 54, routine_param2 = "auto")

+

It either process and store internally new result, return a dataset to you or generate a figure depending on the routine called. In a single script, if a routine has already been ran, the results are usually stored internally.

5.2.3. Save and load

Not available yet. But some routines can take a certain amount of time to run (even in c++), I am therefore implementing a save-load system based on h5py package. The aim is to load and save only what you need behind the scene to save memory and processing time. It will take a wee time to do properly, please bear with me. An easy solution would be to use pickle, but by experience it crashes and uses a LOT of memory when dealing with large dataset (e.g, a raster).

5.3. Raster preprocessing

5.3.1. Principle

Most of the routines uses flow information to generates metrics, the most striking example being river extraction: the program obviously needs to know where the water will flow to calculate rivers. Preprocessing in our case means making sure that all our cells are draining to another one or to an edge. This is essential as DEM are inherantly noisy: this noise will produce artificial pits and depressions. Although minor in the digital topography, these will be fatal to a program as the program will end any flow into these pit therefore biasing drainage area, flow direction, basin outlet or many other routines.
The solution is to carve (sometimes refered as breaching) or to fill these depressions. Respectively, it either "dig" a way out of the depression to the nearest outreach or fill the depression until water can (numerically, there no real water involved) drain to another cell. Carving usually modify less cells than filling but is more computationnaly expensive, and filling is usually required after carving to ensure minimum slope on flat surfaces.

5.3.2. Use in lsdtopytools

In the program, you can either feed the code with a dem externaly preprocessed, see Load your data into the system, or use one of our filing and carving algorithm:

...

my_dem.PreProcessing(filling = True, carving = True, minimum_slope_for_filling = 0.0001)

It preprocesses your base raster and save it into the associated LSDDEM object. The options are the following:

  • carving (boolean): Enables the carving algorithm: Lindsay (2016), DOI: 10.1002/hyp.10648.

  • filling (boolean): Enables the filling algorithm: Wang and Liu (2006), DOI: https://doi.org/10.1080/13658810500433453.

  • minimum_slope_for_filling: imposes a minimum slope while filling. Keep it low to avoid over filling flat areas.

    After being preprocessed, the raster is ready to generate flow metrics.

5.3.3. Plotting and preprocessing caveats

This guide does not aim to discuss the filling and carving algorithm performances, relevant literature does that. So short story long, one might want to check the preprocessing result because (i) filling can generate "overfilled" areas, where for example a bridge or a dam creates an artificial obstacle; (ii) carving and filling alters the original data and therefore can generate unwanted artifact that one need to be aware to avoid misinterpretations.

Topographic map

We provide some plotting routines to plot the topography and preprocessing results. The first routine generates a nice, publication-ready topographic map. It calculates an hillshade of your topography (simulation of natural light to enhance relief) and drape it on a topographic map, any metrics you want to plot need to be calculated beforehand.

Our plotting routines depend on other sub-modules that you need to import first: from lsdtopytools import quickplot will do the trick for this one.
...

from lsdtopytools import quickplot

quickplot.plot_nice_topography(my_dem, figure_width = 4, figure_width_units = "inches", cmap = "gist_earth", hillshade = True,  alpha_hillshade = 0.45, color_min = None, color_max = None, dpi = 300, output = "save", format_figure = "png")

+

quickplot.plot_nice_topography(my_dem) would work with default parameters, but the following customisations are available:

  • figure_width: the real width of the final figure. A matplotlib figure contains the plot, its axis, labels, padding, etc.

  • figure_width_units: Can be inches, which unfortunately is the default in matplotlib or "centimetre", a real unit.

  • cmap: the name of the colormap to use. For example "jet" or our default "gist_earth". Exhaustive list on `matplotlib’s website.

  • hillshade: True by default, you can switch it to False to disable the transparent hillshade draped on top of the topography.

  • alpha_hillshade: Transparency of the hillshade: 0 is fully transparent and 1 fully opaque (would hide the toography).

  • color_min: minimum elevation that will correspond to the minimum color on the colormap. For example if my landscape ranges from 50 to 2000 and if I set this value to 500, all value between 50 and 500 will have the same color. If you don’t customise it, it will be the minimum value.

  • color_max: same principle with the maximum color. If you don’t customise it, it will be the maximum value.

  • dpi: quality of the bitmap if saved. 300 is an acceptable quality, 900 would be really fine, for a large poster for example. Increasing the dpi obviously increases the size of the file.

  • output: Can be "save" to save a figure in the same folder than the raster you loaded; "show" triggers plt.show() and "return" which returns fig,ax if you need to customise your figure in python using matplotlib.

  • format_figure: If output is "save", you can use "png" (good quality, medium size), "svg" (vector image, can be edited with illustrator (Proprietary), coreldraw (proprietary) or inkscape (free and open-source)) or any other maplotlib-supported format (It can depend on extra dependencies, see this help page from matplotlib documentation).

    It will produce the following result:

example topo
Figure 1. Example topographic plot. Script available in the example folder on the github repository (TODO: Add link to the public repo)
Preprocessing check

We also provide a quick plotting routine to check the preprocessing results and if any artifact has appeared. Use it as follow.

...
quickplot.plot_preprocessing_diff(my_dem)

The following customisations are available:

  • figure_width: the real width of the final figure. A matplotlib figure contains the plot, its axis, labels, padding, etc.

  • figure_width_units: Can be inches, which unfortunately is the default in matplotlib or "centimetre", a real unit.

  • cmap: the name of the colormap to use. For example "jet" or our default "gist_earth". Exhaustive list on `matplotlib’s website.

  • color_min: minimum elevation that will correspond to the minimum color on the colormap. For example if my landscape ranges from 50 to 2000 and if I set this value to 500, all value between 50 and 500 will have the same color. If you don’t customise it, it will be the minimum value.

  • color_max: same principle with the maximum color. If you don’t customise it, it will be the maximum value.

  • dpi: quality of the bitmap if saved. 300 is an acceptable quality, 900 would be really fine, for a large poster for example. Increasing the dpi obviously increases the size of the file.

  • output: Can be "save" to save a figure in the same folder than the raster you loaded; "show" triggers plt.show() and "return" which returns fig,ax if you need to customise your figure in python using matplotlib.

  • format_figure: If output is "save", you can use "png" (good quality, medium size), "svg" (vector image, can be edited with illustrator (Proprietary), coreldraw (proprietary) or inkscape (free and open-source)) or any other maplotlib-supported format (It can depend on extra dependencies, see this help page from matplotlib documentation).

  • n_dec_lab (int): precision of the colorbar tick labels.

It will produce the following results: an example with only filling and another one with carving and filling. Note that filling affect the raw data a bit more. A lot of changes happen only on few pixels and are hard to distinct. The significantly filled area correspond to a dam.

example PP delta
Figure 2. Result after filling.
example PP both
Figure 3. Result after carving and fillings.

6. Drainage Network Extraction

This chapter describes how to calculate common flow routines that are required for most of the analysis. All of the routines calculating flows or river-related metrics require the calculation of flow accumulation, direction, drainage area or the actual position of rivers.

6.1. Common Flow Routines

Before locating the actual channel, the software needs to know few information in order to organise the cells and their connections. This is very straightforward:

...
my_dem.CommonFlowRoutines()

So far, this is it. It calculates behind the scene a number of node ordering, flow direction, flow accumulation, drainage area. Node ordering is similar to Braun and Willett, 2013 (fastscape). Drainage area is based on a D8 method from O’Callaghan and Mark, 1988.

We are still building the python bindings, other methods will be implemented (e.g., Dinf for drainage area calculations), let us know if you need it soon.

6.2. Channel Network Extraction

LSDTopoTools extracts rivers by detecting the channel head locations and then building the network following flow direction. Several algorithms are available depending on (i) how important sources location is each case; (ii) your dem resolution (Grieve et al., 2016 for relevant discussion); (iii) landscape characteristics. The generic python function is the following:

...
my_dem.ExtractRiverNetwork(method = "name of the method", corresponding_argument_1 = ...)

where each methods has several arguments to customise the extraction.

method = "area_threshold" is the most basic one. It is suitable when your DEM resolution is coarser than about 10m (e.g., SRTM or ASTER) or if source location is not important. Extremely straightforward and efficient, it initiates a channel when a certain number of other cells are draining into a single one. It only has one parameters:

  • area_threshold_min: the number of cells required to initiate a channel.

We are implementing the other methods now: DREICHT, Pelletier and a geometric method based on Weiner filtering.

6.3. Watershed labelling

We are still refining these methods. In few cases they can be buggy and requires to play a bit with the parameters to obtain wanted results.

Some routines, for example river concavity analysis, knickpoint extraction or \(k_{sn}\) extraction requires watershed labelling to focus on certain drainage networks. It also ensures that the area you are studying is actually complete: you don’t want to extract \(\chi\) with biased drainage area for example.
The extraction is made through the following function, customisable with several methods:

...
my_dem.DefineCatchment(method="name_of_method", param_for_method = ...)

The available methods are the following:

"min_area_pixels" extracts all catchments containing more than a certain amount of pixels. Basic but efficient. It can be customise with the following arguments:

  • test_edges: If True, will test if te basin is complete or draining into no data. It will also ignore your basin if there is internal no data.

  • min_area_pixels: The number of pixel to select a watershed.

Very soon, I will implement other methods. The most efficient method will be selection by coordinates.

6.4. Visualisation and data I/O

6.4.1. Plotting routines:

TO DO. I will incorporate routines to plot basin outlines, channel network and source location

6.4.2. Getting and Saving Data

Data will be very soon accessible via pandas dataframes within python (therefore directly savable into csv files). I/O operations for saving processing time will be done via h5py, a htf5 python interface. (htf5 is a very efficient file format for complex storing).