specnumperpatch-probs: Initiate a specific number of agents in a map of patches

Description Usage Arguments Value Examples

Description

Instantiate a specific number of agents per patch. The user can either supply a table of how many to initiate in each patch, linked by a column in that table called pops.

Usage

1
specificNumPerPatch(patches, numPerPatchTable = NULL, numPerPatchMap = NULL)

Arguments

patches

RasterLayer of patches, with some sort of a patch id.

numPerPatchTable

A data.frame or data.table with a column named pops that matches the patches patch ids, and a second column num.in.pop with population size in each patch.

numPerPatchMap

A RasterLayer exactly the same as patches but with agent numbers rather than ids as the cell values per patch.

Value

A raster with 0s and 1s, where the 1s indicate starting locations of agents following the numbers above.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
library(raster)
library(data.table)
set.seed(1234)
Ntypes <- 4
ras <- randomPolygons(numTypes = Ntypes)
if(interactive()) {
  clearPlot()
  Plot(ras)
}

# Use numPerPatchTable
patchDT <- data.table(pops = 1:Ntypes, num.in.pop = c(1, 3, 5, 7))
rasAgents <- specificNumPerPatch(ras, patchDT)
rasAgents[is.na(rasAgents)] <- 0
#Plot(rasAgents)

library(testthat)
expect_true(all(unname(table(ras[rasAgents])) == patchDT$num.in.pop))

# Use numPerPatchMap
rasPatches <- ras
for (i in 1:Ntypes) {
  rasPatches[rasPatches==i] <- patchDT$num.in.pop[i]
}
if (interactive()) {
  clearPlot()
  Plot(ras, rasPatches)
}
rasAgents <- specificNumPerPatch(ras, numPerPatchMap = rasPatches)
rasAgents[is.na(rasAgents)] <- 0
if(interactive()) {
  clearPlot()
  Plot(rasAgents)
}


Search within the SpaDES package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.