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
sfpolygon defining the prediction area (e.g. frommake_survey_prediction_region()).- resolution
Numeric. Grid cell side length, in the model coordinate units (e.g. km). Internally multiplied by
coord_multiplierto match the CRS units.- crs
Coordinate reference system. If
NULL(default), taken fromregion.- 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_depthdefaults to1, which removes land, andmax_depthtoInf). Supplying either turns on depth extraction (seedepth_fun/bathy_style).- depth_fun
Optional function taking an
sfpoints object and returning a numeric vector of (positive) depths. Only used whenmin_depthormax_depthis set. IfNULL(default), depth is extracted automatically viaggOceanMaps::get_depth()usingbathy_style— supply your owndepth_funto use a different bathymetry source (e.g. a specific GEBCO file viabathy.style = "raster_user"andoptions(ggOceanMaps.userpath = ...), or a local raster/interpolation).- bathy_style
Character.
bathy.stylepassed toggOceanMaps::get_depth()whendepth_funisNULL. Default"raster_continuous"(ETOPO, bundled with ggOceanMaps — no extra download path needed). Ignored whendepth_funis 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.
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
# }