Getting started with TopoToolbox

Getting started with TopoToolbox#

This tutorial will guide you through the first steps of getting started with TopoToolbox in Python. For further examples refer to the provided examples.

Installation#

Make sure to have TopoToolbox installed as per the installation guide. If you want to follow along in this notebook, you will also need to download this notebook, install Jupyter Notebook using pip install notebook and launch Jupyter Notebook using jupyter notebook.

Load a DEM and display it#

Before you can actually use the topotoolbox package, it has to be imported. Since we want to plot the DEMs we will also import matplotlib.pyplot.

[1]:
import topotoolbox as tt3
import matplotlib.pyplot as plt

TopoToolbox includes several examples of digital elevation models. To find out which examples are available, use get_dem_names().

[2]:
print(tt3.get_dem_names())
['kedarnath', 'kunashiri', 'perfectworld', 'taalvolcano', 'taiwan', 'tibet']

Load one of the example files by calling load_dem with the example’s name. TopoToolbox will download the DEM and load it as a GridObject. After the DEM has been created, you can view its attributes by using the info method.

[3]:
dem = tt3.load_dem('tibet')
dem.info()
name: tibet
path: /home/runner/.cache/topotoolbox/tibet.tif
rows: 1259
cols: 1793
cellsize: 90.0
bounds: BoundingBox(left=195227.9710814309, bottom=3387873.2920478885, right=356597.9710814309, top=3501183.2920478885)
transform: | 90.00, 0.00, 195227.97|
| 0.00,-90.00, 3501183.29|
| 0.00, 0.00, 1.00|
crs: EPSG:32645

The DEM can be visualized using the show method on the GridObject.

[4]:
dem.show()
../_images/tutorial_tutorial_7_0.png

If you have a DEM stored on your computer, you can use the function read_tif to load the data by calling it with the path to the file

tt3.read_tif("/path/to/DEM.tif")

If you have used load_dem to download the example DEMs and would like to remove the examples from your disk, you can use clear_cache to deleted the stored data.

tt3.clear_cache()