## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", fig.width = 7, fig.height = 4)

## ----setup, message = FALSE---------------------------------------------------
library(blueterra)
library(terra)

## ----data---------------------------------------------------------------------
bathy <- read_bathy(blueterra_example("hitw"))
prepared <- prepare_bathy(bathy, depth_range = c(-220, -25), smooth = TRUE)

## ----orientation--------------------------------------------------------------
orientation <- derive_metric_stack(
  prepared,
  metrics = c("slope", "aspect", "northness", "eastness")
)
names(orientation)
terra::global(orientation[["slope_deg"]], c("min", "mean", "max"), na.rm = TRUE)

## ----orientation-map, eval=requireNamespace("ggplot2", quietly = TRUE), fig.alt="Slope over hillshaded bathymetry."----
plot_metric(
  orientation,
  "slope_deg",
  bathy = prepared,
  contours = TRUE,
  contour_interval = 25,
  title = "Slope Over Hillshade"
)

## ----structure----------------------------------------------------------------
structure_metrics <- derive_metric_stack(
  prepared,
  metrics = c("roughness", "tri", "rugosity", "surface_area_ratio")
)
names(structure_metrics)
terra::global(structure_metrics[["tri"]], c("min", "mean", "max"), na.rm = TRUE)
terra::global(structure_metrics[["surface_area_ratio"]], c("min", "mean", "max"), na.rm = TRUE)

## ----structure-map, eval=requireNamespace("ggplot2", quietly = TRUE), fig.alt="Rugosity over hillshaded bathymetry."----
plot_metric(
  structure_metrics,
  "rugosity_vrm_3x3",
  bathy = prepared,
  contours = TRUE,
  contour_interval = 25,
  title = "Rugosity Over Hillshade"
)

## ----surface-area-map, eval=requireNamespace("ggplot2", quietly = TRUE), fig.alt="Surface-area ratio over hillshaded bathymetry."----
plot_metric(
  structure_metrics,
  "surface_area_ratio",
  bathy = prepared,
  contours = TRUE,
  contour_interval = 25,
  title = "Surface-Area Ratio Over Hillshade"
)

## ----bpi----------------------------------------------------------------------
fine_bpi <- derive_bpi(prepared, window = 3)
broad_bpi <- derive_bpi(prepared, window = 11)
tpi <- derive_tpi(prepared)
multi_bpi <- derive_multiscale_bpi(prepared, windows = c(3, 7, 11))

names(multi_bpi)
terra::global(fine_bpi, c("min", "mean", "max"), na.rm = TRUE)
terra::global(broad_bpi, c("min", "mean", "max"), na.rm = TRUE)
terra::global(tpi, c("min", "mean", "max"), na.rm = TRUE)

## ----bpi-map, eval=requireNamespace("ggplot2", quietly = TRUE), fig.alt="BPI over hillshaded bathymetry."----
plot_metric(
  fine_bpi,
  bathy = prepared,
  contours = TRUE,
  contour_interval = 25,
  title = "Fine-Scale BPI Over Hillshade"
)

## ----curvature----------------------------------------------------------------
curvature <- derive_curvature(prepared)
terra::global(curvature, c("min", "mean", "max"), na.rm = TRUE)

## ----curvature-map, eval=requireNamespace("ggplot2", quietly = TRUE), fig.alt="Curvature over hillshaded bathymetry."----
plot_metric(
  curvature,
  bathy = prepared,
  contours = TRUE,
  contour_interval = 25,
  title = "Local Curvature Over Hillshade"
)

