Excesstopography

Excesstopography#

This example will showcase how the excesstopography function can be used.

[1]:
import topotoolbox as topo
dem = topo.gen_random()

There are two methods that can be used to calculate the new GridObject. ‘fsm2d’ and ‘fmm2d’, where ‘fsm2d’ is the default since it requires less memory and is generally faster. This function needs a threshold matrix to calculate the excess topography. If no value/matrix is provided by the user, a default matrix filled with the value 0.2 is used.

[2]:
excess_fsm = dem.excesstopography(threshold=0.5)
topo.show(dem, excess_fsm)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[2], line 2
      1 excess_fsm = dem.excesstopography(threshold=0.5)
----> 2 topo.show(dem, excess_fsm)

File ~/.local/lib/python3.10/site-packages/topotoolbox/utils.py:96, in show(dpi, cmap, *grid)
     94 for i, dem in enumerate(grid):
     95     ax = axes[i]
---> 96     im = ax.imshow(dem, cmap=cmap)
     97     ax.set_title(dem.name)
     98     fig.colorbar(im, ax=ax, orientation='vertical')

AttributeError: 'numpy.ndarray' object has no attribute 'imshow'
../_images/_temp_excesstopography_3_1.png
[3]:
excess_fmm = dem.excesstopography(method='fmm2d')
topo.show(dem, excess_fmm)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[3], line 2
      1 excess_fmm = dem.excesstopography(method='fmm2d')
----> 2 topo.show(dem, excess_fmm)

File ~/.local/lib/python3.10/site-packages/topotoolbox/utils.py:96, in show(dpi, cmap, *grid)
     94 for i, dem in enumerate(grid):
     95     ax = axes[i]
---> 96     im = ax.imshow(dem, cmap=cmap)
     97     ax.set_title(dem.name)
     98     fig.colorbar(im, ax=ax, orientation='vertical')

AttributeError: 'numpy.ndarray' object has no attribute 'imshow'
../_images/_temp_excesstopography_4_1.png

If some sections of the GridObject should be evaluated differently than others, use another GridObject or np.ndarray to add custom value for the threshold slopes. Make sure that the shape of your threshold matches the one of your GridObject.

[4]:
import numpy as np

# Generate custom matrix
custom_matrix = np.empty(dem.shape, order='F')
midpoint = dem.shape[0] // 2
custom_matrix[:midpoint, :] = 0.5
custom_matrix[midpoint:, :] = 0.2


excess_custom = dem.excesstopography(threshold=custom_matrix)
topo.show(dem, excess_custom)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[4], line 11
      7 custom_matrix[midpoint:, :] = 0.2
     10 excess_custom = dem.excesstopography(threshold=custom_matrix)
---> 11 topo.show(dem, excess_custom)

File ~/.local/lib/python3.10/site-packages/topotoolbox/utils.py:96, in show(dpi, cmap, *grid)
     94 for i, dem in enumerate(grid):
     95     ax = axes[i]
---> 96     im = ax.imshow(dem, cmap=cmap)
     97     ax.set_title(dem.name)
     98     fig.colorbar(im, ax=ax, orientation='vertical')

AttributeError: 'numpy.ndarray' object has no attribute 'imshow'
../_images/_temp_excesstopography_6_1.png