Learn R Programming

SpaDES (version 1.0.1)

spread: Simulate a spread process on a landscape.

Description

This can be used to simulated fires or other things. Essentially, it starts from a collection of cells (loci) and spreads to neighbours, according to the directions and spreadProb arguments. This can become quite general, if spreadProb is 1 as it will expand from every loci until all pixels in the landscape have been covered. With mapID set to TRUE, the resulting map will be classified by the index of the pixel where that event propagated from. This can be used to examine things like fire size distributions.

Usage

spread(landscape, loci = NULL, spreadProb = 0.23, persistence = 0L,
  mask = NULL, maxSize = NULL, directions = 8L, iterations = NULL,
  lowMemory = getOption("spades.lowMemory"), returnIndices = FALSE, ...)

## S3 method for class 'RasterLayer':
spread(landscape, loci, spreadProb, persistence, mask,
  maxSize, directions = 8L, iterations = NULL, lowMemory, returnIndices,
  mapID = FALSE, plot.it = FALSE, ...)

Arguments

landscape
A RasterLayer object.
loci
A vector of locations in landscape
spreadProb
Numeric or rasterLayer. The overall probability of spreading, or probability raster driven.
persistence
A probability that a burning cell will continue to burn, per time step.
mask
non-NULL, a RasterLayer object congruent with landscape whose elements are 0,1, where 1 indicates "cannot spread to". Currently not implemented.
maxSize
Vector of the maximum number of pixels for a single or all events to be spread. Recycled to match loci length.
directions
The number adjacent cells in which to look; default is 8 (Queen case).
iterations
Number of iterations to spread. Leaving this NULL allows the spread to continue until stops spreading itself (i.e., exhausts itself).
lowMemory
Logical. If true, then function uses package ff internally. This is slower, but much lower memory footprint.
returnIndices
Logical. Should the function return a data.table with indices and values of successful spread events, or return a raster with values. See Details.
...
Additional parameters.
mapID
Logical. If TRUE, returns a raster of events ids. If FALSE, returns a raster of iteration numbers, i.e. the spread history of one or more events.
plot.it
If TRUE, then plot the raster at every iteraction, so one can watch the spread event grow.

Value

  • A RasterLayer indicating the spread of the process in the landscape.

Details

For large rasters, a combination of lowMemory=TRUE and returnIndices=TRUE will use the least amoun of memory.

Examples

Run this code
library(raster)
library(RColorBrewer)

# Make random forest cover map
a <- raster(extent(0,1e2,0,1e2), res=1)
hab <- gaussMap(a,speedup=1) # if raster is large (>1e6 pixels), use speedup>1
names(hab)="hab"
cells <- loci <- b <- as.integer(sample(1:ncell(a),1e1))
mask <- raster(a)
mask <- setValues(mask, 0)
mask[1:5000] <- 1
numCol <- ncol(a)
numCell <- ncell(a)
directions <- 8

# Transparency involves putting two more hex digits on the color code: 00 is fully transparent.
setColors(hab) <- paste(c("#FFFFFF", brewer.pal(8,"Greys")), c("00",rep("FF",8)), sep="")

#dev(4)
Plot(hab,new=TRUE,speedup=3) # note speedup is equivalent to making pyramids,
                             # so, some details are lost

# initiate 10 fires at to loci
fires <- spread(hab, loci=as.integer(sample(1:ncell(hab), 10)),
                0.235, 0, NULL, 1e8, 8, 1e6, mapID=TRUE)
#set colors of raster, including a transparent layer for zeros
setColors(fires, 10) <- c("#00000000", brewer.pal(8,"Reds")[5:8])
Plot(fires)
Plot(fires,addTo="hab")

#alternatively, set colors using cols= in the Plot function
Plot(hab,new=TRUE)
Plot(fires) # default color range makes zero transparent.
# Instead, to give a color to the zero values, use \\code{zero.color=}
Plot(fires, addTo="hab",
     cols=colorRampPalette(c("orange","darkred"))(10))
hab2 <- hab
Plot(hab2)
Plot(fires, addTo="hab2$hab", zero.color="white",
     cols=colorRampPalette(c("orange","darkred"))(10))
# or overplot the original (NOTE: legend stays at original values)
Plot(fires,
     cols=topo.colors(10))

Run the code above in your browser using DataLab