R/vignettes/synthetic_test.Rmd
synthetic_test.Rmd
knitr::opts_chunk$set(echo = TRUE)
8x8 pixel toy matrix made of three land use classes:
#Define the toy matrix
toy.mt <- matrix(c(
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,
2,2,2,1,1,2,2,2,
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,
3,3,3,3,3,3,3,3), ncol=8, byrow=TRUE)
storage.mode(toy.mt) <- "integer"
color_map <- c('#ef8a62', '#f7f7f7', '#67a9cf')
plot(rast(t(toy.mt)), col = color_map, axes = FALSE, box = FALSE, main="Toy matrix", plg=list(legend=c("SWF","Agri","Forest")))
text(rast(t(toy.mt)), digits=1)
iters = 10
test.1 <- swf.molder(
Hmatrix = toy.mt,
swfCover=0.9,
swfCat=1,
agriCat=2,
Q=1, # number of neighbour allocated per iterations
ExpDirection="orthogonal",
iterations = iters,
kernelCl=ncol(toy.mt), kernelRw=nrow(toy.mt),
NNeighbors=1, # number of px that a SWF pixel must have to be selected
maxDistance = 1,
queensCase=TRUE,
np=1)
iters = 10
test.1 <- swf.molder(
Hmatrix = toy.mt,
swfCover=0.90,
swfCat=1,
agriCat=2,
ExpDirection="mixed", # sets preferred direction of expantion
Q=1, # number of neighbour allocated per iterations
iterations = iters,
kernelCl=ncol(toy.mt), kernelRw=nrow(toy.mt),
NNeighbors=1, # number of px that a SWF pixel must have to be selected
maxDistance = 1,
queensCase=TRUE,
np=1)
Here lateral expansion is sought chosing only edge pixels and allocatin 1 SWF px per time - SWF pixel with 7 Agri Neighbour - 1 SWF px allocated per iteration - Allocation of new SWF pixels favours diagonal Agri neighbours
iters = 3
test.1 <- swf.molder(
Hmatrix = toy.mt,
swfCover=0.90,
swfCat=1,
agriCat=2,
ExpPriority="vertical",
ExpDirection="orthogonal", # sets preferred direction of expantion
Q=1, # number of neighbour allocated per iterations
iterations = iters,
kernelCl=ncol(toy.mt), kernelRw=nrow(toy.mt),
NNeighbors=7, # number of px that a SWF pixel must have to be selected
maxDistance = 1,
queensCase=FALSE,
np=1)
iters = 10
test.1 <- swf.molder(
Hmatrix = toy.mt,
swfCover=0.90,
swfCat=1,
agriCat=2,
ExpDirection="orthogonal", # sets preferred direction of expantion
Q=2, # number of neighbour allocated per iterations
iterations = iters,
kernelCl=ncol(toy.mt), kernelRw=nrow(toy.mt),
NNeighbors=5, # number of px that a SWF pixel must have to be selected
maxDistance = 1,
queensCase=TRUE,
np=1)
iters = 10
test.1 <- swf.molder(
Hmatrix = toy.mt,
swfCover=0.90,
swfCat=1,
agriCat=2,
ExpDirection="orthogonal", # sets preferred direction of expantion
Q=2, # number of neighbour allocated per iterations
iterations = iters,
kernelCl=ncol(toy.mt), kernelRw=nrow(toy.mt),
NNeighbors=5, # number of px that a SWF pixel must have to be selected
maxDistance = 1,
queensCase=TRUE,
np=1)
This mimic a “buffer” approach. To obtain it the minimum number of Agri NN for each SWF pixel must be 1 and the number of new allocated SWF pixel has to be 7 which is the maximum number of Agri neighbours that a SWF pixel has in the toy example. Theoretically would be 9.
iters = 10
test.1 <- swf.molder(
Hmatrix = toy.mt,
swfCover=0.90,
swfCat=1,
agriCat=2,
ExpDirection="orthogonal", # sets preferred direction of expansion
Q=7, # number of neighbour allocated per iterations
iterations = iters,
kernelCl=ncol(toy.mt), kernelRw=nrow(toy.mt),
NNeighbors=1, #number of px that a SWF pixel must have to be selected
maxDistance = 1,
queensCase=TRUE,
np=1)
This mimics a 2nd order “buffer” approach. To obtain it, the minimum number of Agri NN for each SWF pixel must be 1 and the number of new allocated SWF pixel has to be the maximum number of 2nd order Agri neighbours that the SWF pixel has in the toy example (8+16=24).
# Remaking the toy matrix with only 1 SWF pixel to make it easier to interpret
toy.mt <- matrix(c(
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,
2,2,2,1,2,2,2,2,
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,
3,3,3,3,3,3,3,3), ncol=8, byrow=TRUE)
plot(rast(t(toy.mt)), col = color_map, axes = FALSE, box = FALSE, main="Toy matrix", plg=list(legend=c("SWF","Agri","Forest")))
text(rast(t(toy.mt)), digits=1)
iters = 10
test.1 <- swf.molder(
Hmatrix = toy.mt,
swfCover=0.90,
swfCat=1,
agriCat=2,
ExpDirection="diagonal", # sets preferred direction of expantion
Q=24, # number of neighbour allocated per iterations
iterations = iters,
kernelCl=ncol(toy.mt), kernelRw=nrow(toy.mt),
NNeighbors=1, #number of px that a SWF pixel must have to be selected
maxDistance = 1,
queensCase=TRUE,
np=1)