# Examples¶

This describes the validation and example datasets, along with sample `mesher`

inputs.

A zip containing all the example code and data can be found here.

## flat¶

Flat DEM, produces 2 triangles

```
#Example configuration file using the sample data
dem_filename = '../data/ideal_flat.tif'
max_area= 9999999999999999**2 #Effectively unlimited upper area -- allow tolerance check to refine it further
max_tolerance = 5 # 5m max RMSE between triangle and underlying elevation set to -1 to skip tolerance checks
min_area = 5**2 # triangle area below which we will no longer refine, regardless of max_tolerance
MPI_nworkers = 1
```

## flat_veg¶

Uses the EOSD dataset to mesh with a `mode=0.9`

threshold. This
captures most of the vegetation patches. ALthough it result in an
over-generation of triangles between patches, this is due to producing a
good gradation from small to larger triangles.

```
dem_filename = '../data/ideal_flat.tif'
max_area= 50000**2 #Effectively unlimited upper area -- allow tolerance check to refine it further
max_tolerance = 5 # 5 m max RMSE between triangle and underlying elevation set to -1 to skip tolerance checks
min_area = 30**2 # triangle area below which we will no longer refine, regardless of max_tolerance
parameter_files = {
'landcover': {'file': '../data/eosd.tif', # vegetation landcover
'method': 'mode',
'tolerance':.9}
}
MPI_nworkers = 1
```

## gaussian_hill¶

Using the generated gaussian hill dataset, produces a mesh for a guassian hill.

```
dem_filename = '../data/ideal_gaussianHill.tif'
max_area= 50000**2 #Effectively unlimited upper area -- allow tolerance check to refine it further
max_tolerance = 5 # 5 m maxe RMSE between triangle and underlying elevation set to -1 to skip tolerance checks
min_area = 30**2 #triangle area below which we will no longer refine, regardless of max_tolerance
MPI_nworkers = 1
```

## ideal_ridge¶

An idealized ridge line

```
dem_filename = '../data/ideal_ridge.tif'
max_area= 50000**2 #Effectively unlimited upper area -- allow tolerance check to refine it further
max_tolerance = 5 #5m maxe RMSE between triangle and underlying elevation set to -1 to skip tolerance checks
min_area = 30**2 #triangle area below which we will no longer refine, regardless of max_tolerance
MPI_nworkers = 1
```

## ideal_ridge_low_tol¶

Same as the ideal_ridge, but with a tighter tolerance. Produces more triangles along the rige to better capture it.

```
dem_filename = '../data/ideal_ridge.tif'
max_area= 50000**2 #Effectively unlimited upper area -- allow tolerance check to refine it further
max_tolerance = 1 #1m maxe RMSE between triangle and underlying elevation set to -1 to skip tolerance checks
min_area = 30**2 #triangle area below which we will no longer refine, regardless of max_tolerance
MPI_nworkers = 1
```

## uniform¶

Produces a uniform mesh with area = 100 m x 100 m.

```
dem_filename = '../data/ideal_flat.tif'
max_area= 9999999999999999**2 #Effectively unlimited upper area -- allow tolerance check to refine it further
max_tolerance = -1 # -1 to skip tolerance checks
min_area = 100**2 #triangle area below which we will no longer refine, regardless of max_tolerance
MPI_nworkers = 1
```

## lloyd¶

Demonstrates the impact of 100 lloyd optimization iterations on the above uniform domain. Compare to the uniform case

```
dem_filename = '../data/ideal_flat.tif'
max_area= 9999999999999999**2 #Effectively unlimited upper area -- allow tolerance check to refine it further
max_tolerance = -1 #1 -1 to skip tolerance checks
min_area = 100**2 #triangle area below which we will no longer refine, regardless of max_tolerance
lloyd_itr=100
MPI_nworkers = 1
```

## flat_stream¶

The flat DEM has been constrained to a stream network input as a shape file. This shows the greater number of triangles near the stream. Simplified stream networks produce fewer triangles along the river constraint.

```
dem_filename = '../data/ideal_flat.tif'
max_area= 9999999999999999**2 #Effectively unlimited upper area -- allow tolerance check to refine it further
max_tolerance = 5 # 5m max RMSE between triangle and underlying elevation set to -1 to skip tolerance checks
min_area = 5**2 #triangle area below which we will no longer refine, regardless of max_tolerance
constraints = { 'river_network' :
{
'file': '../data/Stream.shp',
'simplify':1 # will be in original projection units
}
}
MPI_nworkers = 1
```

## stream_dem¶

Same as above, but including the the Granger subset DEM.

```
dem_filename = '../data/granger1m.tif'
max_area= 99999999**2 #Effectively unlimited upper area -- allow tolerance check to refine it further
max_tolerance = 5 #5 m RMSE
min_area = 25**2 #triangle area below which we will no longer refine, regardless of max_tolerance
constraints = { 'river_network' :
{
'file': '../data/Stream.shp'
# 'simplify':5 # will be in original projection units
}
}
lloyd_itr=1
MPI_nworkers = 1
```

## granger¶

The Granger subset is used, deriving a mesh from only the elevation map.

```
dem_filename = '../data/granger1m.tif'
max_area= 99999999**2 #Effectively unlimited upper area -- allow tolerance check to refine it further
max_tolerance = 1 #1 m RMSE
min_area = 5**2 #triangle area below which we will no longer refine, regardless of max_tolerance
lloyd_itr=1
simplify=True
MPI_nworkers = 1
```

## granger_low_veg_weight¶

The granger subset is used with a low elevation tolerance plus low weights on the vegetation map, showing mesher mostly ignoring the vegetation constraints.

```
dem_filename = '../data/granger1m.tif'
max_area= 50000**2 #Effectively unlimited upper area -- allow tolerance check to refine it further
max_tolerance = 5 #5m maxe RMSE between triangle and underlying elevation set to -1 to skip tolerance checks
min_area = 30**2 #triangle area below which we will no longer refine, regardless of max_tolerance
use_weights = True
topo_weight=0.8
weight_threshold = 0.8
parameter_files = {
'landcover': {'file': '../data/eosd.tif',
'method': 'mode',
'weight':0.2,
'tolerance':.9}
}
lloyd_itr=1
simplify=True
```

## granger_high_veg_weight¶

Same as above but with high weight on the vegetation map, showing the algorithm refining triangles to capture the vegetation patches.

```
dem_filename = '../data/granger1m.tif'
max_area= 50000**2 #Effectively unlimited upper area -- allow tolerance check to refine it further
max_tolerance = 5 # 5m maxe RMSE between triangle and underlying elevation set to -1 to skip tolerance checks
min_area = 30**2 #triangle area below which we will no longer refine, regardless of max_tolerance
use_weights = True
topo_weight=0.2
weight_threshold = 0.8
parameter_files = {
'landcover': {'file': '../data/eosd.tif',
'method': 'mode',
'weight':0.8,
'tolerance':.9}
}
lloyd_itr=1
simplify=True
MPI_nworkers = 1
```

## flow_accumulation¶

This domain shows large-extent meshing with a mountain domain for the
Bow Valley region near Canmore, Alberta, Canada. This mesh uses a
DEM-derived flow accumulation via
RichDEM
to ensure the mesh captures the high-accumulation locations. The flow
accumulation input is generated with the `flow.py`

script in `data`

folder. This requires the RichDEM Python package to be
installed.

```
dem_filename='../data/chro_extent_lowRes.tif'
max_area=5000**2
max_tolerance=50
min_area=200**2
use_input_prj=False
lloyd_itr=100
simplify=True
simplify_tol=100
simplify_buffer=-50
parameter_files = {
'flow_accumulation':{
'file':'../data/flow_accumulation.tif',
'method':'mean',
'tolerance':50
}
}
MPI_nworkers = 1
```

## flow_accumulation_granger¶

Flow accumulation for the smaller Granger subbasin.

```
dem_filename='../data/granger1m.tif'
max_area=5000**2
max_tolerance=10
min_area=5**2
lloyd_itr=100
simplify=True
simplify_tol=100
simplify_buffer=-50
parameter_files = {
'flow_accumulation':{
'file':'../data/flow_accumulation_granger.tif',
'method':'mean',
'tolerance':500
}
}
MPI_nworkers = 1
```

## dem_smoothing¶

A small subset of the above Bow Valley domain is extracted to show the
impact of smoothing on the output mesh. If the `min_area`

is
approximately equal to the cell size of the raster and tolerance
parameter ensures triangles of this size are being produced, then in
complex terrain the stair stepping of the raster (due to non-continous
first derivative; i.e., slope) impacts the mesh quality as shown below.

mesher has an option to smooth the input DEM to lessen this impact. This is enabled via

```
do_smoothing = True
max_smooth_iter = 1
smoothing_scaling_factor = 1
```

Each iteration the smoothing magnitude increases by
`iteration * smoothing_scaling_factor`

. This is the result of 1
smoothing iteration.

Subsequent iterations, or increases in `smoothing_scaling_factor`

can
reduce the stair-stepping further at the cost of increased smoothing of
complex terrain.

```
do_smoothing = True
max_smooth_iter = 2
smoothing_scaling_factor = 1
```

```
dem_filename='../data/chro_small.tif'
max_area=5000**2
max_tolerance=10
min_area=30**2
lloyd_itr = 1
use_input_prj=False
do_smoothing = True
max_smooth_iter = 2
smoothing_scaling_factor = 1
MPI_nworkers = 1
```