Skip to contents

Creates a regular grid of centre points covering an sf region, at a given spatial resolution. Optionally filters the grid by depth using a user-supplied depth function. Coordinates are returned in the same units as the model (divided by coord_multiplier).

Usage

make_prediction_grid(
  region,
  resolution,
  crs = NULL,
  coord_multiplier = 1000,
  min_depth = NULL,
  max_depth = NULL,
  depth_fun = NULL,
  bathy_style = "raster_continuous",
  drop_isolated = FALSE
)

Arguments

region

An sf polygon defining the prediction area (e.g. from make_survey_prediction_region()).

resolution

Numeric. Grid cell side length, in the model coordinate units (e.g. km). Internally multiplied by coord_multiplier to match the CRS units.

crs

Coordinate reference system. If NULL (default), taken from region.

coord_multiplier

Numeric factor to convert model units to CRS units. Default 1000.

min_depth, max_depth

Optional numeric depth limits. If either is supplied, grid cells with depth outside c(min_depth, max_depth) are dropped (min_depth defaults to 1, which removes land, and max_depth to Inf). Supplying either turns on depth extraction (see depth_fun/bathy_style).

depth_fun

Optional function taking an sf points object and returning a numeric vector of (positive) depths. Only used when min_depth or max_depth is set. If NULL (default), depth is extracted automatically via ggOceanMaps::get_depth() using bathy_style — supply your own depth_fun to use a different bathymetry source (e.g. a specific GEBCO file via bathy.style = "raster_user" and options(ggOceanMaps.userpath = ...), or a local raster/interpolation).

bathy_style

Character. bathy.style passed to ggOceanMaps::get_depth() when depth_fun is NULL. Default "raster_continuous" (ETOPO, bundled with ggOceanMaps — no extra download path needed). Ignored when depth_fun is supplied.

drop_isolated

Logical. Drop cells that have none of their eight neighbouring cells in the grid (after the depth filter)? Such single cells come from slivers of the region (a fjord mouth, a gap between islands, a fragment of the polygon) and show as stray pixels on maps. Default FALSE.

Value

A data frame (class sdmTMB_prediction_grid, so plot.sdmTMB_prediction_grid() can be used on it directly) with columns X, Y (in model units) and, when depth filtering is applied, a depth column. Carries crs, coord_multiplier and resolution attributes.

AI assistance

AI-assisted (model not recorded); not yet reviewed in full by the current model. Edited by Claude Opus 5.5 (Anthropic), 2026-11-24.

Author

Mikko Vihtakari

Examples

# \donttest{
data(sebastes)
eggan <- subset(sebastes, cruiseseries == "EggaN")
region <- make_survey_prediction_region(eggan, crs = 32633, concavity = 5)

# max_depth turns on depth extraction, via ggOceanMaps::get_depth() by
# default (bathy_style controls the bathymetry source); cells outside
# c(1, max_depth) are dropped. plot() then colours by depth automatically.
# Here we pass the small bundled demonstration bathymetry as `depth_fun`
# to avoid the large bathymetry download get_depth() needs on first use.
grid <- make_prediction_grid(
  region, resolution = 20, max_depth = 1000, depth_fun = sebastes_depth
)
range(grid$depth)
#> [1]  10 970
plot(grid)


# A depth band, e.g. the depth range a slope survey targets
band <- make_prediction_grid(
  region, resolution = 20, min_depth = 400, max_depth = 1350,
  depth_fun = sebastes_depth
)
range(band$depth)
#> [1]  400 1340
# }