vignettes/articles/ghp/scapesClassification_02_2_ISU.Rmd
scapesClassification_02_2_ISU.Rmd
The island shelf unit (ISU) is composed of two main elements: (i) shelves (i.e., relatively flat areas surrounding islands) and (ii) slopes (i.e., areas that connect island shelves to the seafloor).
Libraries and data are loaded and processed as explained in format input data.
# LOAD LIBRARIES
library(scapesClassification)
library(terra)
# LOAD DATA
grd <- list.files(system.file("extdata", package = "scapesClassification"), full.names = T)
grd <- grd[grepl("\\.grd", grd)]
grd <- grd[!grepl("hillshade", grd)]
rstack <- rast(grd)
# COMPUTE ATTRIBUTE TABLE
atbl <- attTbl(rstack, var_names = c("bathymetry", "local_bpi", "regional_bpi", "slope"))
# COMPUTE NEIGHBORHOOD LIST
nbs <- ngbList(rstack, rNumb = TRUE, attTbl = atbl) # neighbors are identified by their row number in the attribute table
In the following example we will show how the class vector of ISU cells is computed. However, in order to improve the reading experience, the plots’ code is hidden. It can be accessed in the *.RMD
file used to generate the html file.
The plotting procedure is to (i) convert a class vectors into a raster using the function cv.2.rast()
and to (ii) visualize the raster using R or an external software. In our example we will use the R packages mapview
and leaflet
to create interactive maps (note that mapview
do not support terra
raster objects yet, therefore, they have to be converted into raster
raster objects before plotting).
ISU cells will be identified in a series of steps. Each classification step will be saved as a class vector, a vector of length equal to the number of rows of the attribute table. The nth element of a class vector corresponds to the raster cell in the nth row of an attribute table (see also ?conditions
and class vectors).
Class vectors can be converted into a raster, plotted and saved using the function cv.2.rast()
. However, here we will present classification outputs as interactive maps using the R packages mapview
and leaflet
. The plots’ code can be accessed in the *.RMD file used to generate the html file.
Anchor cells are raster cells that can be easily assigned to a class because of some distinctive attribute(s). For example, cells ‘adjacent to an island’ by definition are ‘shelf cells’. We can derive this initial set of cells using two functions (Figure 1):
anchor.svo: returns a vector of cell numbers extracted at the locations of a spatial vector object. In this example, ‘land cells’ are defined as raster cells extracted at island locations that are incomplete cases (arg. only_NAs = T
) and at contiguous locations that are also incomplete cases (arg. fill_NAs = T
);
anchor.cell: converts a vector of cell numbers into a class vector. In this example, all cells adjacent to ‘land cells’ are classified as ‘ISU-anchor cells’.
# ISLAND SHAPEFILE PATH
shp <- system.file("extdata", "Azores.shp", package = "scapesClassification")
# EXTRACT LAND POSITIONS
anchorLAND <- anchor.svo(r = rstack, dsn = shp, only_NAs = TRUE, fill_NAs = TRUE)
# IDENTIFY ANCHOR CELLS
anchorCELL <- anchor.cell(attTbl = atbl, r = rstack, anchor = anchorLAND, class = 1,
class2cell = FALSE, # class not attributed to land cells
class2nbs = TRUE) # class attributed to cell adjacent to land cells
In the previous section we identified the portion of ‘shelf cells’ contiguous to an island. The remaining shelf cells can be identified considering that (i) island shelves tend to be flat and that (ii) raster cells surrounded by shelf cells can be assumed to be part of the shelf. These rules can be implemented using the function cond.4.nofn()
(Figure 2).
slope < 5º
connected with an anchor cell (see focal evaluation) and (ii) hole cells, cells with at least 60% of neighbors belonging to a ‘shelf cell’ class.
# FLAT CELLS
flatCELLS <- cond.4.nofn(atbl, nbs, rNumb = TRUE, classVector = anchorCELL, # update previous class vector
class = 2, # flat cell class
nbs_of = c(1, 2), # focal cells
cond = "slope <= 5",# condition (slope refers to the column `slope` of `atbl`)
min.bord = 0.2) # a test cell is classified only if cond=TRUE AND
# if at least 20% of its neighbors belong to a shelf cell class
# HOLE CELLS
holeCELLS <- cond.4.nofn(atbl, nbs, rNumb = TRUE, classVector = flatCELLS, # update previous class vector
class = 3, # hole cell class
nbs_of = c(1, 2, 3),# focal cells
cond = "TRUE", # conditions are always true
min.bord = 0.6) # a test cell is classified only if 60% of its neighbors
# belong to a shelf cell class
slope < 5º
connected with an anchor cells. Hole cell: cells with at least 60% of neighbors belonging to a ‘shelf cell’ class. Slope, slope values (due to plot re-projection, displayed and original values might be slightly different).
Note that flatness is a property shared by several classes such as flat tops or abyssal plains. In order to exclusively identify shelf cells, the flatness rule has to only be evaluated only at locations in continuity with ISU anchor cells (see focal evaluation).
Class vectors are updated each time they are passed to a classification function. Cells that have not been classified and that meet the conditions get a classification number. The class vector holeCELLS
was the latest to be computed and it includes all the shelf cell classes (Figure 2).
# ISLAND SHELF CELLS
unique(holeCELLS)
## [1] NA 2 3 1
# holeCELLS == 1, ISU anchor cells
# holeCELLS == 2, ISU flat cells
# holeCELLS == 3, ISU hole cells
# holeCELLS == NA, unclassified cells
ISU slopes can be defined as raster cells that connect shelf cells to the seafloor. Seafloor cells tend to have near zero or negative benthic position index (BPI) values. We will use the function cond.4.nofn()
and two layers (regional_bpi
and local_bpi
, see input data) to identify ‘slope cells’. The use of regional and local BPI layers help to identify both large and small features that elevate above the seafloor and to better classify slope cells (Figure 3).
In this example, slope cells are in continuity with shelf cells and respect the following classification rules:
regional_bpi > 100
OR
local_bpi{} > 100
, peval = 0.4
;
The tag {}
flags an absolute neighborhood condition: test cells receive a classification number only if the rule is true for at least as many evaluations as the ones specified by the argument peval
.
slope <- cond.4.nofn(atbl, nbs, rNumb = TRUE, classVector = holeCELLS, # update previous class vector
class = 4, # slope cell class
nbs_of = c(1,2,3,4), # focal cells
cond = "regional_bpi > 100 | local_bpi{} > 100", # conditions
peval = 0.4) # minimum number of positive evaluations (neighborhood condition, ?conditions)
The class vector slope
includes all the cells of the island shelf unit (Figure 3). It is always possible to save and share classification steps as *.RDS files. In this case, the ISU classification is saved in the file 'ISU_Cells.RDS'
and shared as part of the package data.
# ISU CELLS
unique(slope)
## [1] NA 4 2 3 1
# slope3 == 1, ISU anchor cells
# slope3 == 2, ISU flat cells
# slope3 == 3, ISU hole cells
# slope3 == 4, ISU slope cells
# slope3 == NA, unclassified cells