| Title: | Process-Oriented Geomorphometry for Submerged Terrain |
|---|---|
| Description: | Derives, organizes, summarizes, and visualizes terrain metrics from bathymetric and elevation rasters for submerged-terrain geomorphometry. Tools support terra-based raster preparation, slope and aspect decomposition, terrain position, rugosity, a four-neighbor Laplacian-style index, depth-band summaries, transect extraction, isobath-corridor analysis, table preparation, visualization, and aligned user-defined metric layers. Methodological context for geomorphometric terrain analysis is provided by Lindsay (2016) <doi:10.1016/j.cageo.2016.07.003>. |
| Authors: | Elvin Cordero [aut, cre], SeaMount Geospatial Labs [cph] |
| Maintainer: | Elvin Cordero <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.0 |
| Built: | 2026-07-20 08:35:51 UTC |
| Source: | https://github.com/el-cordero/blueterra |
Combines precomputed metric rasters with an existing metric stack after checking grid geometry.
add_metric_layers( metrics, ..., names = NULL, overwrite = FALSE, check_geometry = TRUE )add_metric_layers( metrics, ..., names = NULL, overwrite = FALSE, check_geometry = TRUE )
metrics |
A |
... |
One or more |
names |
Optional names for the added layers. |
overwrite |
Logical. Allow added layers to replace layers with matching
names in |
check_geometry |
Logical. Require matching CRS, extent, resolution, dimensions, and origin. |
Custom metrics must be on the same raster grid as the stack they extend. Geometry checks are enabled by default because summaries, PCA tables, and process-group assignments assume cell-aligned layers.
A combined terra::SpatRaster.
derive_custom_metric(), create_metric_catalog()
bathy <- read_bathy(blueterra_example("bathy")) metrics <- derive_terrain(bathy, metrics = c("slope", "tri")) index <- derive_custom_metric(metrics, "slope_tri_index", expression = quote(slope_deg * tri)) add_metric_layers(metrics, index)bathy <- read_bathy(blueterra_example("bathy")) metrics <- derive_terrain(bathy, metrics = c("slope", "tri")) index <- derive_custom_metric(metrics, "slope_tri_index", expression = quote(slope_deg * tri)) add_metric_layers(metrics, index)
Accepts a terra::SpatRaster or a local raster file path and returns a
terra::SpatRaster.
as_bathy(x, ..., check = TRUE)as_bathy(x, ..., check = TRUE)
x |
A |
... |
Additional arguments passed to |
check |
Logical. If |
as_bathy() preserves raster values and metadata when possible. It does not
flip signs, project CRS, or filter depths unless another function explicitly
requests that behavior.
A terra::SpatRaster.
read_bathy(), validate_bathy()
as_bathy(blueterra_example("bathy"))as_bathy(blueterra_example("bathy"))
Matches raster layer names or character metric names to the metric catalog.
assign_process_groups( x, catalog = metric_catalog(), groups = NULL, unmatched = "unassigned" )assign_process_groups( x, catalog = metric_catalog(), groups = NULL, unmatched = "unassigned" )
x |
A |
catalog |
Optional catalog table. Defaults to |
groups |
Optional named character vector mapping metric names to process groups. Supplied mappings override catalog matches for those metrics. |
unmatched |
Character value assigned to unmatched metrics. |
Matching uses standardized lower-case metric names. Unmatched metrics are
returned with process_group = unmatched so users can inspect custom layers.
A tibble with one row per supplied metric.
metric_catalog(), summarize_process_groups()
terrain <- derive_terrain(read_bathy(blueterra_example("bathy"))) assign_process_groups(terrain)terrain <- derive_terrain(read_bathy(blueterra_example("bathy"))) assign_process_groups(terrain)
Down-samples or samples with replacement so each group has the same number of rows.
balance_samples(data, group, n = NULL, replace = FALSE, seed = NULL)balance_samples(data, group, n = NULL, replace = FALSE, seed = NULL)
data |
A data frame. |
group |
Character name of the grouping column. |
n |
Optional number of rows per group. Defaults to the smallest group
size when |
replace |
Logical. Sample with replacement. |
seed |
Optional random seed. |
A tibble.
df <- data.frame(group = rep(c("a", "b"), c(2, 5)), value = seq_len(7)) balance_samples(df, group = "group")df <- data.frame(group = rep(c("a", "b"), c(2, 5)), value = seq_len(7)) balance_samples(df, group = "group")
Returns a compact table describing raster dimensions, extent, CRS, resolution, layer names, and value range.
bathy_info(x)bathy_info(x)
x |
A raster-like object accepted by |
A tibble with one row per raster layer.
validate_bathy(), check_bathy_crs()
bathy_info(blueterra_example("bathy"))bathy_info(blueterra_example("bathy"))
Returns the path to a small file installed with blueterra.
blueterra_example( name = c("hitw", "hoyo", "slope", "sampling_rectangles", "bathy", "zones", "sites", "synthetic_bathy", "synthetic_zones") ) blueterra_examples() blueterra_extdata(file = NULL)blueterra_example( name = c("hitw", "hoyo", "slope", "sampling_rectangles", "bathy", "zones", "sites", "synthetic_bathy", "synthetic_zones") ) blueterra_examples() blueterra_extdata(file = NULL)
name |
Example name. Use |
file |
File name under |
The primary examples are reduced analysis rasters and sampling rectangles from the southwest Puerto Rico shelf margin near La Parguera. The synthetic files are retained for numerical tests where a simple known surface is useful.
A normalized local file path.
blueterra_examples() returns a tibble describing installed example
files.
hitw <- blueterra_example("hitw") rectangles <- blueterra_example("sampling_rectangles") file.exists(c(hitw, rectangles)) blueterra_examples()hitw <- blueterra_example("hitw") rectangles <- blueterra_example("sampling_rectangles") file.exists(c(hitw, rectangles)) blueterra_examples()
Returns or sets package options used by examples and helper functions.
blueterra_options(...)blueterra_options(...)
... |
Named option values. Currently supported options are
|
Options affect only local package behavior and do not write outside paths provided by the user.
A named list with current option values, invisibly when setting.
blueterra_options() old <- blueterra_options(blueterra.progress = FALSE) blueterra_options(blueterra.progress = old$blueterra.progress)blueterra_options() old <- blueterra_options(blueterra.progress = FALSE) blueterra_options(blueterra.progress = old$blueterra.progress)
Reports whether a bathymetric or elevation raster has a CRS and whether that CRS appears to be geographic longitude/latitude.
check_bathy_crs(x, require_projected = FALSE, warn_lonlat = TRUE)check_bathy_crs(x, require_projected = FALSE, warn_lonlat = TRUE)
x |
A raster-like object accepted by |
require_projected |
Logical. If |
warn_lonlat |
Logical. If |
Many terrain metrics can be calculated on any numeric grid, but metric interpretation is usually strongest in projected coordinate systems with linear units. Buffers, distances, slope, surface-area ratios, and focal windows are all scale-sensitive.
A tibble with CRS status fields.
prepare_bathy(), project_bathy()
bathy <- read_bathy(blueterra_example("bathy")) check_bathy_crs(bathy)bathy <- read_bathy(blueterra_example("bathy")) check_bathy_crs(bathy)
Summarizes raster value ranges and records the intended depth convention when supplied by the user.
check_bathy_units(x, units = NULL, positive_depth = NULL)check_bathy_units(x, units = NULL, positive_depth = NULL)
x |
A raster-like object accepted by |
units |
Optional character label for vertical units, such as |
positive_depth |
Optional logical. Use |
This function does not infer or alter scientific meaning. It reports the observed range and the user-supplied convention so downstream workflows can be explicit.
A tibble with value range and convention fields.
set_depth_positive(), set_depth_negative()
check_bathy_units(blueterra_example("bathy"), units = "m", positive_depth = FALSE)check_bathy_units(blueterra_example("bathy"), units = "m", positive_depth = FALSE)
Builds catalog rows for custom metrics and checks that metric catalogs follow
the schema used by metric_catalog().
create_metric_catalog( metric, label = metric, process_group, description = NA_character_, units = NA_character_, source_function = NA_character_, requires_optional_dependency = FALSE, scale_sensitive = TRUE, interpretation_notes = NA_character_ ) extend_metric_catalog(catalog = metric_catalog(), ...) validate_metric_catalog(catalog)create_metric_catalog( metric, label = metric, process_group, description = NA_character_, units = NA_character_, source_function = NA_character_, requires_optional_dependency = FALSE, scale_sensitive = TRUE, interpretation_notes = NA_character_ ) extend_metric_catalog(catalog = metric_catalog(), ...) validate_metric_catalog(catalog)
metric |
Metric layer name. |
label |
Human-readable metric label. |
process_group |
Process-group label. |
description |
Metric description. |
units |
Metric units. |
source_function |
Function or workflow that produced the metric. |
requires_optional_dependency |
Logical. Whether the metric requires an optional package. |
scale_sensitive |
Logical. Whether the metric is sensitive to grid resolution or focal scale. |
interpretation_notes |
Notes on interpretation. |
catalog |
Existing metric catalog. |
... |
One or more catalog rows or tibbles to append. |
Custom process groups are user-defined terrain-form categories. The catalog records how custom layers should be grouped and interpreted without changing raster values.
A tibble with the same columns as metric_catalog().
assign_process_groups(), summarize_process_groups()
row <- create_metric_catalog( metric = "slope_tri_index", process_group = "custom_relief", description = "Product of local slope and terrain ruggedness index." ) validate_metric_catalog(row) extend_metric_catalog(metric_catalog(), row)row <- create_metric_catalog( metric = "slope_tri_index", process_group = "custom_relief", description = "Product of local slope and terrain ruggedness index." ) validate_metric_catalog(row) extend_metric_catalog(metric_catalog(), row)
Small wrappers around terra raster-preparation operations with bathymetry
input validation.
crop_bathy(x, extent, filename = "", overwrite = FALSE) mask_bathy(x, mask, filename = "", overwrite = FALSE) resample_bathy(x, y, method = "bilinear", filename = "", overwrite = FALSE) project_bathy(x, crs, method = "bilinear", filename = "", overwrite = FALSE)crop_bathy(x, extent, filename = "", overwrite = FALSE) mask_bathy(x, mask, filename = "", overwrite = FALSE) resample_bathy(x, y, method = "bilinear", filename = "", overwrite = FALSE) project_bathy(x, crs, method = "bilinear", filename = "", overwrite = FALSE)
x |
A raster-like object accepted by |
extent |
Crop extent. |
filename |
Optional output raster path. |
overwrite |
Logical. Allow overwriting |
mask |
Polygon/vector mask. |
y |
Template raster used for resampling. |
method |
Interpolation method passed to |
crs |
Target CRS. |
These helpers preserve depth sign and raster values except for interpolation effects introduced by resampling or projection.
A terra::SpatRaster.
bathy <- read_bathy(blueterra_example("bathy")) zones <- terra::vect(blueterra_example("zones")) crop_bathy(bathy, terra::ext(zones[zones$site_id == "slope", ]))bathy <- read_bathy(blueterra_example("bathy")) zones <- terra::vect(blueterra_example("zones")) crop_bathy(bathy, terra::ext(zones[zones$site_id == "slope", ]))
Keeps raster values within a depth or elevation range, or explicitly changes sign convention.
depth_filter( x, depth_range, positive_depth = NULL, filename = "", overwrite = FALSE ) invert_depth(x, filename = "", overwrite = FALSE) set_depth_positive(x, filename = "", overwrite = FALSE) set_depth_negative(x, filename = "", overwrite = FALSE)depth_filter( x, depth_range, positive_depth = NULL, filename = "", overwrite = FALSE ) invert_depth(x, filename = "", overwrite = FALSE) set_depth_positive(x, filename = "", overwrite = FALSE) set_depth_negative(x, filename = "", overwrite = FALSE)
x |
A raster-like object accepted by |
depth_range |
Numeric length-two retained range. |
positive_depth |
Optional logical. If |
filename |
Optional output raster path. |
overwrite |
Logical. Allow overwriting |
depth_filter() does not flip signs. Use set_depth_positive(),
set_depth_negative(), or invert_depth() for explicit sign changes.
A terra::SpatRaster.
bathy <- read_bathy(blueterra_example("bathy")) depth_filter(bathy, c(-80, -30)) set_depth_positive(bathy)bathy <- read_bathy(blueterra_example("bathy")) depth_filter(bathy, c(-80, -30)) set_depth_positive(bathy)
Computes a local bathymetric position index from the difference between each cell and its focal-neighborhood mean.
derive_bpi( x, inner_radius = NULL, outer_radius = NULL, window = NULL, scale = c("fine", "broad", "custom"), normalize = FALSE, filename = "", overwrite = FALSE, ... ) derive_multiscale_bpi( x, windows = c(3, 11), normalize = FALSE, filename = "", overwrite = FALSE, ... )derive_bpi( x, inner_radius = NULL, outer_radius = NULL, window = NULL, scale = c("fine", "broad", "custom"), normalize = FALSE, filename = "", overwrite = FALSE, ... ) derive_multiscale_bpi( x, windows = c(3, 11), normalize = FALSE, filename = "", overwrite = FALSE, ... )
x |
A raster-like object accepted by |
inner_radius |
Optional inner radius for an annulus window in map units. |
outer_radius |
Optional outer radius for an annulus window in map units. |
window |
Optional odd integer square window size in cells. |
scale |
Preset scale when |
normalize |
Logical. If |
filename |
Optional output raster path. |
overwrite |
Logical. Allow overwriting |
... |
Reserved for future extensions. |
windows |
Integer vector of odd square window sizes. |
The calculation is cell value - focal mean. Positive values therefore mean
higher-than-neighborhood values when the raster is elevation-like. For
positive-depth rasters, interpretation is reversed unless users convert the
sign convention first. Square windows are measured in cells and include the
focal cell. Annular windows are measured in map units, require a projected
CRS with linear units, and use separate x- and y-cell resolutions when cells
are not square. At raster edges and next to missing cells, BPI uses the
available cells in its partial focal support; a missing focal value remains
missing.
A single-layer terra::SpatRaster.
derive_multiscale_bpi(), derive_tpi()
bathy <- read_bathy(blueterra_example("bathy")) derive_bpi(bathy, window = 5)bathy <- read_bathy(blueterra_example("bathy")) derive_bpi(bathy, window = 5)
Creates a single custom metric layer from an expression or a user-supplied R function.
derive_custom_metric( metrics, name, expression = NULL, fun = NULL, ..., overwrite = FALSE )derive_custom_metric( metrics, name, expression = NULL, fun = NULL, ..., overwrite = FALSE )
metrics |
A |
name |
Output layer name. |
expression |
Optional quoted R expression evaluated with raster layers available by name. |
fun |
Optional function called as |
... |
Additional arguments passed to |
overwrite |
Logical. Allow |
Expressions must be quoted, for example
quote(slope_deg * rugosity_vrm_3x3). Character strings are not evaluated.
This keeps the workflow explicit and avoids treating text as code.
A single-layer terra::SpatRaster named name.
bathy <- read_bathy(blueterra_example("bathy")) metrics <- derive_terrain(bathy, metrics = c("slope", "tri", "bpi")) derive_custom_metric(metrics, "slope_tri_index", expression = quote(slope_deg * tri)) relief <- derive_custom_metric(metrics, "relief_index", fun = function(r) { out <- r[["tri"]] + abs(r[["bpi_3x3"]]) names(out) <- "relief_index" out }) reliefbathy <- read_bathy(blueterra_example("bathy")) metrics <- derive_terrain(bathy, metrics = c("slope", "tri", "bpi")) derive_custom_metric(metrics, "slope_tri_index", expression = quote(slope_deg * tri)) relief <- derive_custom_metric(metrics, "relief_index", fun = function(r) { out <- r[["tri"]] + abs(r[["bpi_3x3"]]) names(out) <- "relief_index" out }) relief
Computes selected metrics and returns them as a named raster stack.
derive_metric_stack( x, metrics = "default", scales = NULL, units = c("degrees", "radians"), neighbors = 8, positive_depth = NULL, filename = "", overwrite = FALSE, progress = TRUE )derive_metric_stack( x, metrics = "default", scales = NULL, units = c("degrees", "radians"), neighbors = 8, positive_depth = NULL, filename = "", overwrite = FALSE, progress = TRUE )
x |
A raster-like object accepted by |
metrics |
Character vector of metrics, or |
scales |
Optional BPI/TPI window sizes used when multiscale BPI is requested. |
units |
Slope and aspect units, |
neighbors |
Neighborhood passed to |
positive_depth |
Optional logical documenting the input sign convention. Metric values are not sign-flipped unless a specific function says so. |
filename |
Optional output raster path. |
overwrite |
Logical. Allow overwriting |
progress |
Logical. Reserved for long-running workflows. |
"default" currently expands to bathymetry, slope, aspect, northness,
eastness, hillshade, roughness, TRI, TPI, fine BPI, broad BPI, curvature, and
surface-area ratio. All metrics are derived locally from the supplied raster.
A terra::SpatRaster.
bathy <- read_bathy(blueterra_example("bathy")) derive_metric_stack(bathy, metrics = "default")bathy <- read_bathy(blueterra_example("bathy")) derive_metric_stack(bathy, metrics = "default")
Convenience wrappers around terra terrain functions and lightweight
geomorphometry formulas.
derive_slope( x, units = c("degrees", "radians"), neighbors = 8, filename = "", overwrite = FALSE ) derive_aspect( x, units = c("degrees", "radians"), neighbors = 8, filename = "", overwrite = FALSE ) derive_northness(x, neighbors = 8, filename = "", overwrite = FALSE) derive_eastness(x, neighbors = 8, filename = "", overwrite = FALSE) derive_hillshade( x, angle = 45, direction = 315, neighbors = 8, filename = "", overwrite = FALSE ) derive_roughness(x, filename = "", overwrite = FALSE) derive_tri(x, filename = "", overwrite = FALSE) derive_tpi(x, filename = "", overwrite = FALSE) derive_rugosity(x, window = 3, neighbors = 8, filename = "", overwrite = FALSE) derive_curvature(x, filename = "", overwrite = FALSE) derive_surface_area_ratio(x, neighbors = 8, filename = "", overwrite = FALSE)derive_slope( x, units = c("degrees", "radians"), neighbors = 8, filename = "", overwrite = FALSE ) derive_aspect( x, units = c("degrees", "radians"), neighbors = 8, filename = "", overwrite = FALSE ) derive_northness(x, neighbors = 8, filename = "", overwrite = FALSE) derive_eastness(x, neighbors = 8, filename = "", overwrite = FALSE) derive_hillshade( x, angle = 45, direction = 315, neighbors = 8, filename = "", overwrite = FALSE ) derive_roughness(x, filename = "", overwrite = FALSE) derive_tri(x, filename = "", overwrite = FALSE) derive_tpi(x, filename = "", overwrite = FALSE) derive_rugosity(x, window = 3, neighbors = 8, filename = "", overwrite = FALSE) derive_curvature(x, filename = "", overwrite = FALSE) derive_surface_area_ratio(x, neighbors = 8, filename = "", overwrite = FALSE)
x |
A raster-like object accepted by |
units |
Units for slope or aspect: |
neighbors |
Neighborhood size passed to |
filename |
Optional output raster path. |
overwrite |
Logical. Allow overwriting |
angle |
Illumination angle for hillshade. |
direction |
Illumination direction for hillshade. |
window |
Odd integer focal-window size for local metrics. |
Functions preserve the input raster sign. For example, slope depends on the magnitude of local gradients, while BPI/TPI interpretation depends on whether the raster stores elevation-like values or positive depth.
derive_rugosity() computes a vector-ruggedness-measure-style index from
local slope and aspect vectors. Its focal means use available derivative
cells, including partial focal support adjacent to a derivative boundary or
missing data, but the outermost cells can remain missing because slope and
aspect themselves require neighbouring elevation values.
derive_curvature() computes a four-neighbor Laplacian-style index. It is
not plan, profile, mean, or Gaussian curvature, is not scaled by cell
dimensions, and is consequently strongly resolution-dependent.
derive_surface_area_ratio() is a slope-secant approximation, 1 / cos(slope),
rather than a triangulated or directly measured benthic surface area. It
clamps near-zero cosine values to avoid pathological ratios at extreme slopes.
A single-layer terra::SpatRaster, except where documented
otherwise.
derive_terrain(), derive_bpi()
bathy <- read_bathy(blueterra_example("bathy")) derive_slope(bathy) derive_northness(bathy)bathy <- read_bathy(blueterra_example("bathy")) derive_slope(bathy) derive_northness(bathy)
Computes one or more terrain metrics from a user-supplied bathymetric or elevation raster.
derive_terrain( x, metrics = "default", scales = NULL, units = c("degrees", "radians"), neighbors = 8, positive_depth = NULL, filename = "", overwrite = FALSE, progress = TRUE )derive_terrain( x, metrics = "default", scales = NULL, units = c("degrees", "radians"), neighbors = 8, positive_depth = NULL, filename = "", overwrite = FALSE, progress = TRUE )
x |
A raster-like object accepted by |
metrics |
Character vector of metrics, or |
scales |
Optional BPI/TPI window sizes used when multiscale BPI is requested. |
units |
Slope and aspect units, |
neighbors |
Neighborhood passed to |
positive_depth |
Optional logical documenting the input sign convention. Metric values are not sign-flipped unless a specific function says so. |
filename |
Optional output raster path. |
overwrite |
Logical. Allow overwriting |
progress |
Logical. Reserved for long-running workflows. |
Terrain metrics are scale-sensitive. Slope, curvature, rugosity, TPI, BPI, roughness, and surface-area style metrics depend on grid resolution, smoothing, and focal-window size. Use projected coordinate systems when distances or slopes are interpreted in real linear units.
A terra::SpatRaster containing named metric layers.
derive_metric_stack(), derive_bpi(), metric_catalog()
bathy <- read_bathy(blueterra_example("bathy")) terrain <- derive_terrain(bathy, metrics = c("slope", "aspect", "bpi")) names(terrain)bathy <- read_bathy(blueterra_example("bathy")) terrain <- derive_terrain(bathy, metrics = c("slope", "aspect", "bpi")) names(terrain)
Estimates the mean aspect direction of a raster surface and converts that
compass bearing to the line-angle convention used by make_transects().
estimate_surface_orientation( bathy, area = NULL, orientation_weight = c("slope", "none"), min_slope = 0, return = c("transect_angle", "bearing", "both") )estimate_surface_orientation( bathy, area = NULL, orientation_weight = c("slope", "none"), min_slope = 0, return = c("transect_angle", "bearing", "both") )
bathy |
A single-layer bathymetric or elevation raster, or a raster input
accepted by |
area |
Optional polygon area used to crop and mask |
orientation_weight |
Weighting method. |
min_slope |
Minimum slope in degrees retained when
|
return |
Return type: |
Aspect is treated as a compass bearing where northness is cos(aspect) and
eastness is sin(aspect). Mean circular components are converted to a
compass bearing with atan2(eastness, northness). Transect lines are
undirected, so the line angle is normalized to [0, 180). A south-facing
mean aspect near 180 degrees therefore produces a transect angle near 90
degrees.
A numeric angle for "transect_angle" or "bearing", or a tibble
with bearing_deg, transect_angle_deg, orientation_weight,
min_slope, and n_orientation_cells when return = "both".
make_transects(), derive_aspect(), derive_slope()
bathy <- read_bathy(blueterra_example("hitw")) zones <- terra::vect(blueterra_example("zones")) hitw <- zones[zones$site_id == "hitw", ] estimate_surface_orientation(bathy, hitw)bathy <- read_bathy(blueterra_example("hitw")) zones <- terra::vect(blueterra_example("zones")) hitw <- zones[zones$site_id == "hitw", ] estimate_surface_orientation(bathy, hitw)
Extracts raster cell values under corridor polygons.
extract_isobath_corridors(metrics, corridors, ...)extract_isobath_corridors(metrics, corridors, ...)
metrics |
A metric raster stack. |
corridors |
Corridor polygons from |
... |
Additional arguments passed to |
A tibble with corridor identifiers and extracted raster values.
summarize_isobath_terrain(), summarize_terrain()
bathy <- read_bathy(blueterra_example("bathy")) terrain <- derive_terrain(bathy, metrics = c("slope", "bpi")) corridors <- make_isobath_corridors(bathy, depths = -50, width = 5) extract_isobath_corridors(terrain, corridors)bathy <- read_bathy(blueterra_example("bathy")) terrain <- derive_terrain(bathy, metrics = c("slope", "bpi")) corridors <- make_isobath_corridors(bathy, depths = -50, width = 5) extract_isobath_corridors(terrain, corridors)
Converts raster contour levels to line features.
extract_isobaths( x, depths, positive_depth = NULL, as = c("SpatVector", "sf"), ... )extract_isobaths( x, depths, positive_depth = NULL, as = c("SpatVector", "sf"), ... )
x |
A raster-like object accepted by |
depths |
Numeric contour levels. |
positive_depth |
Optional logical. If |
as |
Output type: |
... |
Additional arguments reserved for future extensions. |
Depth convention is explicit. For rasters stored as negative elevation,
either pass negative depths or set positive_depth = FALSE when passing
positive depth labels.
Isobath line features as terra::SpatVector by default.
bathy <- read_bathy(blueterra_example("bathy")) extract_isobaths(bathy, depths = c(-40, -60))bathy <- read_bathy(blueterra_example("bathy")) extract_isobaths(bathy, depths = c(-40, -60))
Extracts raster values at point locations.
extract_terrain_points(metrics, points, method = "bilinear", ...)extract_terrain_points(metrics, points, method = "bilinear", ...)
metrics |
A metric raster stack. |
points |
Points as |
method |
Extraction method passed to |
... |
Additional arguments passed to |
A tibble with point attributes and raster values.
bathy <- read_bathy(blueterra_example("bathy")) zones <- terra::vect(blueterra_example("zones")) pts <- terra::centroids(zones) extract_terrain_points(bathy, pts)bathy <- read_bathy(blueterra_example("bathy")) zones <- terra::vect(blueterra_example("zones")) pts <- terra::centroids(zones) extract_terrain_points(bathy, pts)
Buffers isobath contour lines to create depth-following corridor polygons.
make_isobath_corridors( x, depths, width, smooth = FALSE, as = c("SpatVector", "sf"), positive_depth = NULL, ... )make_isobath_corridors( x, depths, width, smooth = FALSE, as = c("SpatVector", "sf"), positive_depth = NULL, ... )
x |
A raster-like object accepted by |
depths |
Numeric contour levels. |
width |
One-sided buffer distance in map units. The nominal full corridor width is twice this value. |
smooth |
Logical. If |
as |
Output type: |
positive_depth |
Optional logical. If |
... |
Additional arguments reserved for future extensions. |
width is interpreted as a one-sided buffer distance in the CRS map units.
Projected CRS are strongly recommended. If the raster uses
longitude/latitude, the function warns before buffering because distance
interpretation may be misleading. Corridors are returned as independent
buffers and can overlap; their summaries are therefore not mutually
exclusive or additive.
Isobath corridor polygons as terra::SpatVector by default.
extract_isobaths(), summarize_isobath_terrain()
bathy <- read_bathy(blueterra_example("bathy")) make_isobath_corridors(bathy, depths = c(-40, -60), width = 5)bathy <- read_bathy(blueterra_example("bathy")) make_isobath_corridors(bathy, depths = c(-40, -60), width = 5)
Builds regularly spaced straight transects through polygon features.
make_transects( area, spacing, angle = NULL, bathy = NULL, orientation = c("auto", "surface", "bbox", "manual"), orientation_weight = c("slope", "none"), min_slope = 0, length = NULL, id_field = NULL, as = c("SpatVector", "sf") )make_transects( area, spacing, angle = NULL, bathy = NULL, orientation = c("auto", "surface", "bbox", "manual"), orientation_weight = c("slope", "none"), min_slope = 0, length = NULL, id_field = NULL, as = c("SpatVector", "sf") )
area |
A |
spacing |
Distance between transects in map units. |
angle |
Optional transect direction in degrees counterclockwise from the projected x axis. When supplied, this manual value overrides orientation estimation. |
bathy |
Optional bathymetry raster used to estimate a terrain-based
transect orientation when |
orientation |
Orientation strategy. |
orientation_weight |
Weighting for surface orientation. |
min_slope |
Minimum slope, in degrees, used when
|
length |
Optional transect length in map units. If |
id_field |
Optional field in |
as |
Output type: |
Transect spacing and length are interpreted in map units. Use a projected CRS
for metric distances. Candidate lines are created through each polygon
bounding box and clipped to the polygon with terra::intersect().
With angle = NULL and a supplied bathy raster, the default transect
direction is estimated from the mean surface aspect within each polygon.
Aspect is converted to northness and eastness, averaged as circular
components, and converted to the mathematical line angle used for transect
generation. For example, a south-facing mean aspect near 180 degrees yields a
transect angle near 90 degrees, producing north-south transects in projected
coordinates. The estimated angle, source metadata, and circular resultant
length are stored on the output lines. Resultant lengths near zero indicate
weakly concentrated aspects and an unstable mean direction.
A terra::SpatVector by default. If as = "sf", an sf object is
returned and the optional sf package must be installed.
estimate_surface_orientation(), sample_transects(),
extract_cross_sections()
zones <- terra::vect(blueterra_example("zones")) bathy <- read_bathy(blueterra_example("bathy")) transects <- make_transects(zones[1, ], spacing = 50, bathy = bathy) transects manual <- make_transects(zones[1, ], spacing = 50, angle = 90) manual[, c("angle_deg", "angle_source")]zones <- terra::vect(blueterra_example("zones")) bathy <- read_bathy(blueterra_example("bathy")) transects <- make_transects(zones[1, ], spacing = 50, bathy = bathy) transects manual <- make_transects(zones[1, ], spacing = 50, angle = 90) manual[, c("angle_deg", "angle_source")]
Returns a catalog of terrain metrics, labels, process groups, assumptions,
and source functions used by blueterra.
metric_catalog() process_groups()metric_catalog() process_groups()
The catalog is an interpretation aid, not a claim that terrain metrics directly measure ecological or oceanographic processes. Groups such as seafloor aspect, slope gradient, accumulation potential, seafloor position, seafloor rugosity, downslope pathway proximity, transport potential, and curvature describe terrain form and terrain-routing proxies. Accumulation, pathway, and transport interpretations require separate validation and are not direct current or sediment-flux measurements.
A tibble with columns metric, label, process_group,
description, units, source_function,
requires_optional_dependency, scale_sensitive, and
interpretation_notes.
derive_terrain(), assign_process_groups()
metric_catalog() process_groups()metric_catalog() process_groups()
A compact table describing the metrics returned by core blueterra
functions and their process-oriented interpretation groups.
metric_catalog_datametric_catalog_data
A tibble with columns:
Stable metric name.
Human-readable label.
Process-oriented terrain group.
Metric description.
Expected units.
Function that derives the metric.
Whether an optional dependency is needed.
Whether interpretation depends on raster scale.
Important interpretation notes.
Use metric_catalog() to retrieve this table in normal workflows.
Builds axis labels for plot_process_pca() from a terrain_pca() object.
pca_axis_labels( pca, components = c("PC1", "PC2"), top_n = 2, unique = TRUE, include_variance = TRUE )pca_axis_labels( pca, components = c("PC1", "PC2"), top_n = 2, unique = TRUE, include_variance = TRUE )
pca |
Output from |
components |
Components to label. |
top_n |
Number of high-loading variables included per component. |
unique |
Logical. Avoid repeating the same dominant variable across component labels when possible. |
include_variance |
Logical. Include percent variance explained. |
Variables are ranked by absolute loading for each component. These labels are descriptive aids for ordination plots; they do not replace inspection of the full loading table.
A named character vector of axis labels.
terrain_pca(), plot_process_pca()
df <- data.frame(a = rnorm(10), b = rnorm(10), c = rnorm(10)) pca_axis_labels(terrain_pca(df))df <- data.frame(a = rnorm(10), b = rnorm(10), c = rnorm(10)) pca_axis_labels(terrain_pca(df))
Creates ggplot2 maps for bathymetry and derived terrain metrics using
terra rasters and vectors. Hillshade can be drawn as a semitransparent
visual relief layer, and bathymetric contours, sampling rectangles, transects,
or other terra::SpatVector geometries can be overlaid.
plot_bathy( x, hillshade = TRUE, hillshade_alpha = 0.3, contours = TRUE, contour_interval = NULL, contour_color = "white", contour_linewidth = 0.25, vectors = NULL, vector_color = "white", vector_linewidth = 0.5, labels = NULL, label_field = NULL, title = NULL, subtitle = NULL, caption = NULL, legend_title = "Bathymetry", max_cells = getOption("blueterra.max_plot_cells", 10000) ) plot_metric( x, metric = NULL, bathy = NULL, hillshade = TRUE, hillshade_alpha = 0.3, contours = FALSE, contour_interval = NULL, contour_color = "white", contour_linewidth = 0.25, vectors = NULL, vector_color = "white", vector_linewidth = 0.5, labels = NULL, label_field = NULL, title = NULL, subtitle = NULL, caption = NULL, legend_title = NULL, max_cells = getOption("blueterra.max_plot_cells", 10000) ) plot_terrain_map( bathy, metric = NULL, vectors = NULL, contours = TRUE, contour_interval = 20, hillshade = TRUE, title = NULL, subtitle = NULL, caption = NULL, ... ) plot_hillshade(x, max_cells = getOption("blueterra.max_plot_cells", 10000)) plot_sampling_rectangles(bathy, rectangles, label_field = "site_id", ...) plot_transects(bathy, transects, color_by = NULL, show_legend = FALSE, ...) plot_metric_stack(x, max_cells = getOption("blueterra.max_plot_cells", 10000))plot_bathy( x, hillshade = TRUE, hillshade_alpha = 0.3, contours = TRUE, contour_interval = NULL, contour_color = "white", contour_linewidth = 0.25, vectors = NULL, vector_color = "white", vector_linewidth = 0.5, labels = NULL, label_field = NULL, title = NULL, subtitle = NULL, caption = NULL, legend_title = "Bathymetry", max_cells = getOption("blueterra.max_plot_cells", 10000) ) plot_metric( x, metric = NULL, bathy = NULL, hillshade = TRUE, hillshade_alpha = 0.3, contours = FALSE, contour_interval = NULL, contour_color = "white", contour_linewidth = 0.25, vectors = NULL, vector_color = "white", vector_linewidth = 0.5, labels = NULL, label_field = NULL, title = NULL, subtitle = NULL, caption = NULL, legend_title = NULL, max_cells = getOption("blueterra.max_plot_cells", 10000) ) plot_terrain_map( bathy, metric = NULL, vectors = NULL, contours = TRUE, contour_interval = 20, hillshade = TRUE, title = NULL, subtitle = NULL, caption = NULL, ... ) plot_hillshade(x, max_cells = getOption("blueterra.max_plot_cells", 10000)) plot_sampling_rectangles(bathy, rectangles, label_field = "site_id", ...) plot_transects(bathy, transects, color_by = NULL, show_legend = FALSE, ...) plot_metric_stack(x, max_cells = getOption("blueterra.max_plot_cells", 10000))
x |
A raster-like object accepted by |
hillshade |
Logical. Draw hillshade as a visual relief layer. |
hillshade_alpha |
Maximum alpha for the hillshade shadow overlay. |
contours |
Logical. Draw contour lines from |
contour_interval |
Optional contour interval in raster units. |
contour_color |
Contour line color. |
contour_linewidth |
Contour line width. |
vectors |
Optional |
vector_color |
Vector outline color. |
vector_linewidth |
Vector outline width. |
labels |
Optional label source. Use |
label_field |
Optional field used for vector labels. |
title, subtitle, caption
|
Plot text passed to |
legend_title |
Optional raster legend title. |
max_cells |
Maximum raster cells used for plotting. |
metric |
Optional metric raster or a layer name/index in |
bathy |
Optional bathymetry raster used to derive hillshade and contours
when |
... |
Additional plotting options passed from convenience wrappers to
|
rectangles |
Sampling rectangles or polygon zones. |
transects |
Transect line geometry. |
color_by |
Optional transect attribute used to color lines, such as
|
show_legend |
Logical. Show a legend when |
Plotting functions require ggplot2, which is suggested rather than
imported. Large rasters are regularly sampled before plotting to keep
examples and interactive work responsive. Hillshade is used only as a visual
relief layer; it is not a terrain predictor unless a user explicitly derives
and analyzes it as one.
A ggplot object.
derive_terrain(), plot_metric_stack()
if (requireNamespace("ggplot2", quietly = TRUE)) { bathy <- read_bathy(blueterra_example("bathy")) zones <- terra::vect(blueterra_example("zones")) plot_bathy(bathy, vectors = zones, labels = TRUE, label_field = "site_id") }if (requireNamespace("ggplot2", quietly = TRUE)) { bathy <- read_bathy(blueterra_example("bathy")) zones <- terra::vect(blueterra_example("zones")) plot_bathy(bathy, vectors = zones, labels = TRUE, label_field = "site_id") }
Plots raster values against transect distance.
plot_cross_sections( samples, value_col = NULL, group_col = "transect_id", color_col = NULL, show_legend = TRUE, points = FALSE, mean_profile = FALSE, mean_profile_na_rm = TRUE, normalize_distance = FALSE, profile_direction = c("top_to_bottom", "bottom_to_top", "as_sampled", "max_to_min", "min_to_max", "high_to_low", "low_to_high"), positive_depth = NULL, depth_increases_down = TRUE, title = NULL, subtitle = NULL, caption = NULL )plot_cross_sections( samples, value_col = NULL, group_col = "transect_id", color_col = NULL, show_legend = TRUE, points = FALSE, mean_profile = FALSE, mean_profile_na_rm = TRUE, normalize_distance = FALSE, profile_direction = c("top_to_bottom", "bottom_to_top", "as_sampled", "max_to_min", "min_to_max", "high_to_low", "low_to_high"), positive_depth = NULL, depth_increases_down = TRUE, title = NULL, subtitle = NULL, caption = NULL )
samples |
Output from |
value_col |
Optional value column. |
group_col |
Grouping column for transect lines. |
color_col |
Optional column used to color profiles. Defaults to
|
show_legend |
Logical. Show the line-color legend. |
points |
Logical. Draw sample points over profile lines. |
mean_profile |
Logical. Overlay an interpolated mean profile across transects. |
mean_profile_na_rm |
Logical. Remove missing interpolated profile values
when averaging the mean profile. The default, |
normalize_distance |
Logical. Plot distance as 0-1 normalized position along each transect. |
profile_direction |
Direction used to orient distance before plotting.
|
positive_depth |
Logical depth convention for |
depth_increases_down |
Logical. If |
title, subtitle, caption
|
Plot text. |
A ggplot object.
sample_transects(), plot_depth_profile()
if (requireNamespace("ggplot2", quietly = TRUE)) { bathy <- read_bathy(blueterra_example("bathy")) zones <- terra::vect(blueterra_example("zones")) transects <- make_transects(zones[1, ], spacing = 100, bathy = bathy) samples <- sample_transects(transects, bathy, n = 5) plot_cross_sections(samples) }if (requireNamespace("ggplot2", quietly = TRUE)) { bathy <- read_bathy(blueterra_example("bathy")) zones <- terra::vect(blueterra_example("zones")) transects <- make_transects(zones[1, ], spacing = 100, bathy = bathy) samples <- sample_transects(transects, bathy, n = 5) plot_cross_sections(samples) }
Plots sampled raster values along a transect profile or against depth.
plot_depth_profile( data, distance_col = "distance", depth_col = NULL, value_col = NULL, group_col = NULL, points = TRUE, line = TRUE, profile_layout = c("auto", "distance", "metric_by_depth"), profile_direction = c("top_to_bottom", "bottom_to_top", "as_sampled", "max_to_min", "min_to_max", "high_to_low", "low_to_high"), positive_depth = NULL, depth_increases_down = TRUE, title = NULL, subtitle = NULL, caption = NULL )plot_depth_profile( data, distance_col = "distance", depth_col = NULL, value_col = NULL, group_col = NULL, points = TRUE, line = TRUE, profile_layout = c("auto", "distance", "metric_by_depth"), profile_direction = c("top_to_bottom", "bottom_to_top", "as_sampled", "max_to_min", "min_to_max", "high_to_low", "low_to_high"), positive_depth = NULL, depth_increases_down = TRUE, title = NULL, subtitle = NULL, caption = NULL )
data |
A data frame. |
distance_col |
Distance column name. |
depth_col |
Depth or elevation column name. If |
value_col |
Value column to plot. Use this for sampled variables such as bathymetry, slope, rugosity, BPI, or curvature. |
group_col |
Optional grouping column. |
points |
Logical. Draw profile points. |
line |
Logical. Draw profile lines when at least two finite samples are available. |
profile_layout |
Plot layout. |
profile_direction |
Direction used to orient distance before plotting.
|
positive_depth |
Logical depth convention for |
depth_increases_down |
Logical. If |
title, subtitle, caption
|
Plot text. |
With profile_layout = "distance", the y-axis can be any sampled raster
variable: elevation, depth, slope, rugosity, BPI, curvature, or a custom
metric. With profile_layout = "metric_by_depth", depth or elevation is
placed on the y-axis and the selected terrain metric is placed on the x-axis.
Metadata columns such as transect angle, offset, width, and height are
ignored during automatic value-column inference.
A ggplot object.
if (requireNamespace("ggplot2", quietly = TRUE)) { df <- data.frame(distance = 1:5, depth = -c(10, 12, 20, 25, 30)) plot_depth_profile(df, depth_col = "depth") metric_df <- data.frame( distance = 1:5, bathy_m = -c(10, 12, 20, 25, 30), slope_deg = c(4, 6, 9, 12, 15) ) plot_depth_profile(metric_df, depth_col = "bathy_m", value_col = "slope_deg") }if (requireNamespace("ggplot2", quietly = TRUE)) { df <- data.frame(distance = 1:5, depth = -c(10, 12, 20, 25, 30)) plot_depth_profile(df, depth_col = "depth") metric_df <- data.frame( distance = 1:5, bathy_m = -c(10, 12, 20, 25, 30), slope_deg = c(4, 6, 9, 12, 15) ) plot_depth_profile(metric_df, depth_col = "bathy_m", value_col = "slope_deg") }
Plots isobath corridor polygons, optionally over hillshaded bathymetry with contour lines. The hillshade layer is visual context only.
plot_isobath_corridors( corridors, bathy = NULL, isobaths = NULL, hillshade = TRUE, background_contours = FALSE, source_isobaths = TRUE, isobath_color = "black", isobath_linewidth = 0.6, corridor_color = "white", corridor_linewidth = 0.45, corridor_fill = NA, corridor_alpha = 0.2, labels = TRUE, label_field = NULL, title = "Isobath Corridors", subtitle = NULL, caption = NULL, contours = NULL, ... )plot_isobath_corridors( corridors, bathy = NULL, isobaths = NULL, hillshade = TRUE, background_contours = FALSE, source_isobaths = TRUE, isobath_color = "black", isobath_linewidth = 0.6, corridor_color = "white", corridor_linewidth = 0.45, corridor_fill = NA, corridor_alpha = 0.2, labels = TRUE, label_field = NULL, title = "Isobath Corridors", subtitle = NULL, caption = NULL, contours = NULL, ... )
corridors |
Corridor polygons. |
bathy |
Optional raster background. |
isobaths |
Optional source isobath lines to draw over the corridors. |
hillshade |
Logical. Draw hillshade from |
background_contours |
Logical. Draw general bathymetric background
contours. Defaults to |
source_isobaths |
Logical. Draw the source isobaths used to create the corridors. |
isobath_color, isobath_linewidth
|
Source-isobath line styling. |
corridor_color, corridor_linewidth, corridor_fill, corridor_alpha
|
Corridor polygon styling. |
labels |
Logical. Label corridors with |
label_field |
Attribute used for labels. Defaults to |
title, subtitle, caption
|
Plot text. |
contours |
Deprecated alias for |
... |
Additional arguments passed to |
A ggplot object.
make_isobath_corridors(), plot_bathy()
if (requireNamespace("ggplot2", quietly = TRUE)) { bathy <- read_bathy(blueterra_example("bathy")) corridors <- make_isobath_corridors(bathy, depths = -50, width = 5) isobaths <- extract_isobaths(bathy, depths = -50) plot_isobath_corridors(corridors, bathy, isobaths = isobaths) }if (requireNamespace("ggplot2", quietly = TRUE)) { bathy <- read_bathy(blueterra_example("bathy")) corridors <- make_isobath_corridors(bathy, depths = -50, width = 5) isobaths <- extract_isobaths(bathy, depths = -50) plot_isobath_corridors(corridors, bathy, isobaths = isobaths) }
Plots density curves for one or more process-group metrics.
plot_process_density(data, value, group = NULL)plot_process_density(data, value, group = NULL)
data |
A data frame of terrain values. |
value |
Character name of the numeric value column. |
group |
Optional grouping column. |
A ggplot object.
if (requireNamespace("ggplot2", quietly = TRUE)) { df <- data.frame(value = rnorm(20), process = rep(c("a", "b"), each = 10)) plot_process_density(df, value = "value", group = "process") }if (requireNamespace("ggplot2", quietly = TRUE)) { df <- data.frame(value = rnorm(20), process = rep(c("a", "b"), each = 10)) plot_process_density(df, value = "value", group = "process") }
Plots the first two principal component score axes from terrain_pca().
plot_process_pca( pca, color_col = NULL, shape_col = NULL, label_loadings = TRUE, loading_arrows = TRUE, top_loadings = 3, axis_labels = c("loadings", "variance", "plain"), title = NULL, subtitle = NULL, caption = NULL )plot_process_pca( pca, color_col = NULL, shape_col = NULL, label_loadings = TRUE, loading_arrows = TRUE, top_loadings = 3, axis_labels = c("loadings", "variance", "plain"), title = NULL, subtitle = NULL, caption = NULL )
pca |
Output from |
color_col |
Optional score metadata column used for point color. |
shape_col |
Optional score metadata column used for point shape. |
label_loadings |
Logical. Label the largest loading vectors. |
loading_arrows |
Logical. Draw loading arrows scaled into score space. |
top_loadings |
Number of high-magnitude loading vectors to draw or label. |
axis_labels |
Axis label style: include dominant loadings and variance, variance only, or plain component names. |
title, subtitle, caption
|
Plot text. |
A ggplot object.
if (requireNamespace("ggplot2", quietly = TRUE)) { df <- data.frame(a = rnorm(20), b = rnorm(20), c = rnorm(20)) plot_process_pca(terrain_pca(df)) }if (requireNamespace("ggplot2", quietly = TRUE)) { df <- data.frame(a = rnorm(20), b = rnorm(20), c = rnorm(20)) plot_process_pca(terrain_pca(df)) }
Plots a summary column from summarize_terrain() or related functions.
plot_terrain_summary(summary, value, group = NULL)plot_terrain_summary(summary, value, group = NULL)
summary |
A summary data frame. |
value |
Summary value column. |
group |
Optional x-axis grouping column. Defaults to |
A ggplot object.
if (requireNamespace("ggplot2", quietly = TRUE)) { df <- data.frame(zone_id = 1:3, slope_mean = c(5, 7, 2)) plot_terrain_summary(df, value = "slope_mean") }if (requireNamespace("ggplot2", quietly = TRUE)) { df <- data.frame(zone_id = 1:3, slope_mean = c(5, 7, 2)) plot_terrain_summary(df, value = "slope_mean") }
Applies common preprocessing steps for terrain analysis: optional projection, resampling, cropping, masking, depth filtering, sign conversion, smoothing, and optional file-backed output.
prepare_bathy( x, crs = NULL, resolution = NULL, extent = NULL, mask = NULL, depth_range = NULL, positive_depth = NULL, method = "bilinear", smooth = FALSE, smooth_window = 3, filename = "", overwrite = FALSE )prepare_bathy( x, crs = NULL, resolution = NULL, extent = NULL, mask = NULL, depth_range = NULL, positive_depth = NULL, method = "bilinear", smooth = FALSE, smooth_window = 3, filename = "", overwrite = FALSE )
x |
A raster-like object accepted by |
crs |
Optional target CRS passed to |
resolution |
Optional target cell size. A single value is used for both axes; two values are used as x and y resolution. |
extent |
Optional crop extent: |
mask |
Optional polygon/vector mask. |
depth_range |
Optional numeric length-two range of retained depths or elevations. |
positive_depth |
Optional logical. If |
method |
Resampling and projection method passed to |
smooth |
Logical. If |
smooth_window |
Odd integer focal-window size for smoothing. |
filename |
Optional output raster path. |
overwrite |
Logical. Allow overwriting |
prepare_bathy() never automatically reprojects or flips depth signs. Those
operations occur only when crs or positive_depth are supplied. Distance-
based geomorphometry should generally be performed in a projected CRS with
linear units.
A terra::SpatRaster.
crop_bathy(), mask_bathy(), depth_filter()
bathy <- read_bathy(blueterra_example("bathy")) prepared <- prepare_bathy(bathy, depth_range = c(-90, -20), smooth = TRUE) preparedbathy <- read_bathy(blueterra_example("bathy")) prepared <- prepare_bathy(bathy, depth_range = c(-90, -20), smooth = TRUE) prepared
Converts a terrain table to a numeric predictor matrix and optional response vector.
prepare_model_matrix( data, vars = NULL, response = NULL, scale = FALSE, na.rm = TRUE )prepare_model_matrix( data, vars = NULL, response = NULL, scale = FALSE, na.rm = TRUE )
data |
A data frame. |
vars |
Optional predictor variable names. |
response |
Optional response column name. |
scale |
Logical. If |
na.rm |
Logical. Remove incomplete rows. |
A list with x, y, and data.
sample_terrain_cells(), terrain_pca()
df <- data.frame(y = c(0, 1, 0), slope = c(1, 2, 3), bpi = c(0.2, 0.1, 0.4)) prepare_model_matrix(df, response = "y")df <- data.frame(y = c(0, 1, 0), slope = c(1, 2, 3), bpi = c(0.2, 0.1, 0.4)) prepare_model_matrix(df, response = "y")
Reads a local raster file with terra::rast() and optionally validates that
the result is usable as a bathymetric or elevation surface.
read_bathy(path, ..., check = TRUE)read_bathy(path, ..., check = TRUE)
path |
Local raster file path. |
... |
Additional arguments passed to |
check |
Logical. If |
read_bathy() is data-source agnostic. The input can be any local raster
format supported by terra, including GeoTIFF and many GDAL-readable files.
The function treats the raster as a user-supplied terrain surface and
preserves its values, CRS, resolution, and vertical sign convention.
A terra::SpatRaster.
as_bathy(), validate_bathy(), prepare_bathy()
path <- blueterra_example("bathy") bathy <- read_bathy(path) bathypath <- blueterra_example("bathy") bathy <- read_bathy(path) bathy
Draws random or regular samples from raster cells and returns a table.
sample_terrain_cells( metrics, size, method = c("random", "regular"), na.rm = TRUE, xy = TRUE, seed = NULL )sample_terrain_cells( metrics, size, method = c("random", "regular"), na.rm = TRUE, xy = TRUE, seed = NULL )
metrics |
A metric raster stack. |
size |
Number of cells to sample. |
method |
Sampling method, |
na.rm |
Logical. Omit rows with missing values. |
xy |
Logical. Include cell coordinates. |
seed |
Optional random seed used before sampling. |
A tibble of sampled cell values.
extract_terrain_points(), prepare_model_matrix()
bathy <- read_bathy(blueterra_example("bathy")) sample_terrain_cells(bathy, size = 10)bathy <- read_bathy(blueterra_example("bathy")) sample_terrain_cells(bathy, size = 10)
Extracts raster values along transect lines at regular distances.
sample_transects( transects, x, spacing = NULL, n = NULL, method = "bilinear", drop_na = FALSE ) extract_cross_sections( transects, x, spacing = NULL, n = NULL, method = "bilinear" )sample_transects( transects, x, spacing = NULL, n = NULL, method = "bilinear", drop_na = FALSE ) extract_cross_sections( transects, x, spacing = NULL, n = NULL, method = "bilinear" )
transects |
Line geometry from |
x |
A |
spacing |
Optional sample spacing in map units. |
n |
Optional number of sample points per transect. |
method |
Extraction method passed to |
drop_na |
Logical. If |
If spacing and n are both NULL, twenty points are sampled per transect.
Distances are measured from the first line vertex and are in map units.
Transect attribute columns, including orientation metadata created by
make_transects(), are preserved in the sampled table.
A tibble with transect identifiers, distances, coordinates, and raster values.
make_transects(), summarize_cross_sections()
bathy <- read_bathy(blueterra_example("bathy")) zones <- terra::vect(blueterra_example("zones")) transects <- make_transects(zones[1, ], spacing = 100, bathy = bathy) sample_transects(transects, bathy, n = 5)bathy <- read_bathy(blueterra_example("bathy")) zones <- terra::vect(blueterra_example("zones")) transects <- make_transects(zones[1, ], spacing = 100, bathy = bathy) sample_transects(transects, bathy, n = 5)
Chooses a small set of catalog metrics for process-oriented summaries.
select_process_representatives( catalog = metric_catalog(), groups = NULL, metrics_available = NULL, representatives = NULL )select_process_representatives( catalog = metric_catalog(), groups = NULL, metrics_available = NULL, representatives = NULL )
catalog |
Optional catalog table. Defaults to |
groups |
Optional process groups to retain. |
metrics_available |
Optional vector of available metric names. |
representatives |
Optional named character vector mapping process-group names to representative metric names. |
The default representative is the first implemented metric in the catalog for each process group. Users should review and override representatives based on their raster resolution, focal scales, and scientific question.
A tibble with one representative metric per process group.
metric_catalog(), assign_process_groups()
select_process_representatives()select_process_representatives()
Applies a square moving-window mean filter.
smooth_bathy(x, window = 3, na.rm = TRUE, filename = "", overwrite = FALSE)smooth_bathy(x, window = 3, na.rm = TRUE, filename = "", overwrite = FALSE)
x |
A raster-like object accepted by |
window |
Odd integer focal-window size. |
na.rm |
Logical. Remove missing values inside the focal window. |
filename |
Optional output raster path. |
overwrite |
Logical. Allow overwriting |
Smoothing changes local gradients and can strongly affect slope, curvature, rugosity, TPI, and BPI. Use it deliberately and report the window size.
A terra::SpatRaster.
bathy <- read_bathy(blueterra_example("bathy")) smooth_bathy(bathy, window = 3)bathy <- read_bathy(blueterra_example("bathy")) smooth_bathy(bathy, window = 3)
Converts metric names to stable snake-case names or applies a user-supplied dictionary.
standardize_metric_names(x) rename_metric_layers(x, dictionary = NULL)standardize_metric_names(x) rename_metric_layers(x, dictionary = NULL)
x |
A |
dictionary |
Optional named character vector. Names are old metric names; values are new metric names. |
Standardization is conservative and does not change raster values. Use this helper to make layer names predictable before joining to the metric catalog or exporting model-ready tables.
An object of the same broad type as x.
standardize_metric_names(c("Slope (deg)", "Broad BPI"))standardize_metric_names(c("Slope (deg)", "Broad BPI"))
Summarizes raster values sampled along transects.
summarize_cross_sections( samples, value_col = NULL, group_col = "transect_id", fun = c("mean", "sd", "min", "max", "median"), na.rm = TRUE, normalize_distance = FALSE, n_bins = 50 )summarize_cross_sections( samples, value_col = NULL, group_col = "transect_id", fun = c("mean", "sd", "min", "max", "median"), na.rm = TRUE, normalize_distance = FALSE, n_bins = 50 )
samples |
Output from |
value_col |
Optional value column. Defaults to the first numeric column that is not an identifier or coordinate. |
group_col |
Column used to group cross-section samples. |
fun |
Summary functions. |
na.rm |
Logical. Remove missing values. |
normalize_distance |
Logical. If |
n_bins |
Number of normalized-distance bins when
|
A tibble with one row per group.
bathy <- read_bathy(blueterra_example("bathy")) zones <- terra::vect(blueterra_example("zones")) transects <- make_transects(zones[1, ], spacing = 100, bathy = bathy) samples <- sample_transects(transects, bathy, n = 5) summarize_cross_sections(samples)bathy <- read_bathy(blueterra_example("bathy")) zones <- terra::vect(blueterra_example("zones")) transects <- make_transects(zones[1, ], spacing = 100, bathy = bathy) samples <- sample_transects(transects, bathy, n = 5) summarize_cross_sections(samples)
Groups raster cells into depth or elevation bands and summarizes metric values within each band.
summarize_depth_bands( bathy, metrics = NULL, breaks, positive_depth = NULL, fun = c("mean", "sd", "min", "max", "median"), na.rm = TRUE )summarize_depth_bands( bathy, metrics = NULL, breaks, positive_depth = NULL, fun = c("mean", "sd", "min", "max", "median"), na.rm = TRUE )
bathy |
A bathymetric or elevation raster. |
metrics |
Optional metric raster stack. If |
breaks |
Numeric band breaks. |
positive_depth |
Optional logical. If |
fun |
Summary functions. |
na.rm |
Logical. Remove missing values. |
Depth bands are sensitive to vertical sign convention. For negative-elevation
bathymetry, use negative breaks or set positive_depth = TRUE with positive
depth breaks.
A tibble with one row per depth band and metric.
depth_filter(), summarize_terrain()
bathy <- read_bathy(blueterra_example("bathy")) summarize_depth_bands(bathy, breaks = c(-90, -60, -30, 0))bathy <- read_bathy(blueterra_example("bathy")) summarize_depth_bands(bathy, breaks = c(-90, -60, -30, 0))
Computes summary statistics for metric rasters inside corridor polygons.
summarize_isobath_terrain( metrics, corridors, fun = c("mean", "sd", "min", "max", "median"), na.rm = TRUE, exact = FALSE, ... )summarize_isobath_terrain( metrics, corridors, fun = c("mean", "sd", "min", "max", "median"), na.rm = TRUE, exact = FALSE, ... )
metrics |
A metric raster stack. |
corridors |
Corridor polygons. |
fun |
Summary functions. |
na.rm |
Logical. Remove missing values. |
exact |
Logical. Use coverage-fraction-weighted exact intersections
through |
... |
Additional arguments passed to |
A tibble with one row per corridor.
make_isobath_corridors(), summarize_terrain()
bathy <- read_bathy(blueterra_example("bathy")) terrain <- derive_terrain(bathy, metrics = c("slope", "bpi")) corridors <- make_isobath_corridors(bathy, depths = -50, width = 5) summarize_isobath_terrain(terrain, corridors)bathy <- read_bathy(blueterra_example("bathy")) terrain <- derive_terrain(bathy, metrics = c("slope", "bpi")) corridors <- make_isobath_corridors(bathy, depths = -50, width = 5) summarize_isobath_terrain(terrain, corridors)
Counts available metrics by process group.
summarize_process_groups(x, catalog = metric_catalog(), groups = NULL)summarize_process_groups(x, catalog = metric_catalog(), groups = NULL)
x |
A |
catalog |
Optional catalog table. Defaults to |
groups |
Optional named character vector passed to
|
This function summarizes which process groups are represented by a metric
stack. It does not compute raster statistics; use summarize_terrain() for
spatial summaries.
A tibble with process group counts.
assign_process_groups(), summarize_terrain()
terrain <- derive_terrain(read_bathy(blueterra_example("bathy"))) summarize_process_groups(terrain)terrain <- derive_terrain(read_bathy(blueterra_example("bathy"))) summarize_process_groups(terrain)
Computes summary statistics for raster metrics inside polygons, buffers, or corridor features.
summarize_terrain( metrics, zones, fun = c("mean", "sd", "min", "max", "median"), na.rm = TRUE, exact = FALSE, ... ) summarize_terrain_by_zone( metrics, zones, fun = c("mean", "sd", "min", "max", "median"), na.rm = TRUE, exact = FALSE, ... )summarize_terrain( metrics, zones, fun = c("mean", "sd", "min", "max", "median"), na.rm = TRUE, exact = FALSE, ... ) summarize_terrain_by_zone( metrics, zones, fun = c("mean", "sd", "min", "max", "median"), na.rm = TRUE, exact = FALSE, ... )
metrics |
A metric raster stack. |
zones |
Polygon zones as |
fun |
Summary functions. Supported values are |
na.rm |
Logical. Remove missing values before summarizing. |
exact |
Logical. If |
... |
Additional arguments passed to extraction functions. |
summarize_terrain() does not assume specific zones, depth ranges, or
ecological labels. For distance-sensitive summaries, use zones and rasters in
a projected CRS. With exact = TRUE, positive coverage_fraction values
weight means, population standard deviations, sums, counts, and medians.
Minimum and maximum are evaluated over intersected cells with positive
coverage. The resulting exact mean is area-weighted when raster cells have
equal area in the working CRS.
A tibble with zone identifiers, zone attributes, and wide summary
columns named metric_function.
summarize_depth_bands(), extract_terrain_points()
bathy <- read_bathy(blueterra_example("bathy")) terrain <- derive_terrain(bathy, metrics = c("slope", "bpi")) zones <- terra::vect(blueterra_example("zones")) summarize_terrain(terrain, zones)bathy <- read_bathy(blueterra_example("bathy")) terrain <- derive_terrain(bathy, metrics = c("slope", "bpi")) zones <- terra::vect(blueterra_example("zones")) summarize_terrain(terrain, zones)
Computes pairwise correlations among numeric terrain variables.
terrain_correlation( data, vars = NULL, method = "pearson", use = "pairwise.complete.obs" )terrain_correlation( data, vars = NULL, method = "pearson", use = "pairwise.complete.obs" )
data |
A data frame. |
vars |
Optional character vector of numeric variables. |
method |
Correlation method passed to |
use |
Missing-value handling passed to |
A tibble with variable pairs and correlation coefficients.
bathy <- read_bathy(blueterra_example("bathy")) terrain <- derive_terrain(bathy, metrics = c("slope", "bpi", "roughness")) cells <- sample_terrain_cells(terrain, size = 30) terrain_correlation(cells)bathy <- read_bathy(blueterra_example("bathy")) terrain <- derive_terrain(bathy, metrics = c("slope", "bpi", "roughness")) cells <- sample_terrain_cells(terrain, size = 30) terrain_correlation(cells)
Computes standardized differences between two groups for numeric terrain variables.
terrain_effect_size(data, group, vars = NULL, method = "cohens_d", ...)terrain_effect_size(data, group, vars = NULL, method = "cohens_d", ...)
data |
A data frame. |
group |
Character name of the grouping column. |
vars |
Optional character vector of numeric variables. |
method |
Effect-size method. Currently |
... |
Reserved for future methods. |
Cohen's d is computed as the difference in group means divided by pooled standard deviation. Exactly two non-missing groups are required.
A tibble with one row per variable.
df <- data.frame(group = rep(c("a", "b"), each = 5), slope = 1:10) terrain_effect_size(df, group = "group", vars = "slope")df <- data.frame(group = rep(c("a", "b"), each = 5), slope = 1:10) terrain_effect_size(df, group = "group", vars = "slope")
Runs PCA on numeric terrain variables and returns tidy scores, loadings, variance explained, and the fitted model.
terrain_pca( data, vars = NULL, center = TRUE, scale. = TRUE, metadata_cols = NULL, keep_metadata = TRUE, ... )terrain_pca( data, vars = NULL, center = TRUE, scale. = TRUE, metadata_cols = NULL, keep_metadata = TRUE, ... )
data |
A data frame. |
vars |
Optional character vector of numeric variables. |
center |
Logical passed to |
scale. |
Logical passed to |
metadata_cols |
Optional non-PCA columns appended to the score table. |
keep_metadata |
Logical. Preserve non-PCA columns in |
... |
Additional arguments passed to |
Rows with incomplete values in selected variables are omitted before PCA. PCA is descriptive and should be interpreted with scale, CRS, and sampling design in mind.
A list with scores, loadings, variance, model, vars, and
complete_rows.
prepare_model_matrix(), terrain_correlation()
bathy <- read_bathy(blueterra_example("bathy")) terrain <- derive_terrain(bathy, metrics = c("slope", "bpi", "roughness")) cells <- sample_terrain_cells(terrain, size = 30) terrain_pca(cells)bathy <- read_bathy(blueterra_example("bathy")) terrain <- derive_terrain(bathy, metrics = c("slope", "bpi", "roughness")) cells <- sample_terrain_cells(terrain, size = 30) terrain_pca(cells)
Fits one terrain PCA across all rows and one PCA within each group level.
terrain_pca_by_group( data, group, vars = NULL, center = TRUE, scale. = TRUE, min_rows = 5, ... )terrain_pca_by_group( data, group, vars = NULL, center = TRUE, scale. = TRUE, min_rows = 5, ... )
data |
A data frame. |
group |
Character name of the grouping column. |
vars |
Optional numeric variables used in PCA. |
center, scale.
|
Logical values passed to |
min_rows |
Minimum rows required for a group-specific PCA. |
... |
Additional arguments passed to |
Group-specific PCA is useful for checking whether ordination structure is
dominated by one site or sampling frame. Groups with fewer than min_rows
rows are omitted with a warning.
A named list with overall and groups. groups is a named list of
PCA objects.
terrain_pca(), plot_process_pca()
df <- data.frame(site = rep(c("a", "b"), each = 8), slope = rnorm(16), tri = rnorm(16), bpi = rnorm(16)) terrain_pca_by_group(df, group = "site")df <- data.frame(site = rep(c("a", "b"), each = 8), slope = rnorm(16), tri = rnorm(16), bpi = rnorm(16)) terrain_pca_by_group(df, group = "site")
Checks that an object is a readable terra::SpatRaster with dimensions,
layers, and values suitable for terrain analysis.
validate_bathy( x, require_crs = FALSE, require_values = TRUE, allow_multi = FALSE )validate_bathy( x, require_crs = FALSE, require_values = TRUE, allow_multi = FALSE )
x |
A raster-like object accepted by |
require_crs |
Logical. If |
require_values |
Logical. If |
allow_multi |
Logical. If |
Validation does not decide whether values represent positive depth or
negative elevation. Use check_bathy_units(), set_depth_positive(), or
set_depth_negative() when sign convention matters.
Invisibly returns the input raster.
check_bathy_crs(), check_bathy_units()
bathy <- read_bathy(blueterra_example("bathy")) validate_bathy(bathy)bathy <- read_bathy(blueterra_example("bathy")) validate_bathy(bathy)