Skip to content

Commit

Permalink
version 1.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
dariomasante authored and cran-robot committed Dec 13, 2016
1 parent 8e0b1e7 commit d29092a
Show file tree
Hide file tree
Showing 17 changed files with 136 additions and 84 deletions.
12 changes: 6 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
Package: landscapeR
Title: Categorical Landscape Simulation Facility
Version: 1.1.2
Version: 1.1.3
Date: 2016-09-07
Authors@R: c(person(given = "Dario", family = "Masante", role = c("aut", "cre"), email = "[email protected]"))
Authors@R: c(person(given = "Dario", family = "Masante", role = c("aut", "cre"), email = "[email protected]"))
Copyright: Natural Environment Research Council (NERC) and Centre for
Ecology and Hydrology (CEH)
URL: https://github.com/dariomasante/landscapeR
BugReports: https://github.com/dariomasante/landscapeR/issues
Imports: raster
Suggests: knitr, rmarkdown
Description: Simulates categorical maps on actual geographical realms, starting from either empty landscapes or landscapes provided by the user (e.g. land use maps). Allows to tweak or create landscapes while retaining a high degree of control on its features, without the hassle of specifying each location attribute. In this it differs from other tools which generate null or neutral landscapes in a theoretical space. The basic algorithm currently implemented uses a simple agent style/cellular automata growth model, with no rules (apart from areas of exclusion). Outputs are raster dataset exportable to any common GIS format.
Description: Simulates categorical maps on actual geographical realms, starting from either empty landscapes or landscapes provided by the user (e.g. land use maps). Allows to tweak or create landscapes while retaining a high degree of control on its features, without the hassle of specifying each location attribute. In this it differs from other tools which generate null or neutral landscapes in a theoretical space. The basic algorithm currently implemented uses a simple agent style/cellular automata growth model, with no rules (apart from areas of exclusion) and von Neumann neighbourhood (four cells, aka Rook case). Outputs are raster dataset exportable to any common GIS format.
License: GPL (>= 3)
LazyLoad: yes
LazyData: TRUE
NeedsCompilation: no
RoxygenNote: 5.0.1
VignetteBuilder: knitr
Packaged: 2016-09-07 11:22:17 UTC; dmasan
Packaged: 2016-12-13 18:02:14 UTC; dmasan
Author: Dario Masante [aut, cre]
Maintainer: Dario Masante <[email protected]>
Maintainer: Dario Masante <[email protected]>
Repository: CRAN
Date/Publication: 2016-09-07 14:41:34
Date/Publication: 2016-12-13 21:24:11
32 changes: 16 additions & 16 deletions MD5
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
4b48ba9f5ec2f7179275812e51efb358 *DESCRIPTION
da3cb9749a8ed19a3a1f34eb9686facb *DESCRIPTION
61a106d579400fccc0ec8efc6d500d6d *NAMESPACE
7cb151654e8ea7de65e62f09c6c7afec *NEWS.md
b75f528daa3b271a7015d49cd186f3f6 *R/expandClass.R
f7413cfe3eadbde445db6e0682d9e03d *NEWS.md
c98f9b83673087a046aa1773d8d00c1b *R/expandClass.R
08127e0bda7cbdf93ab1755412b87cce *R/landscapeR-package.R
09bf83e8deb24866d53c660a2ca5c6c0 *R/makeClass.R
d7728388222b867a1653574da7e0d3c2 *R/makeLine.R
a6cedcdefcbdb4832022d78fd3c5977f *R/makePatch.R
6e7a0f6ed46c094b03637803ebfb5059 *R/rmSingle.R
069f3a97012cb8b27328d93be95a2ef7 *R/makeClass.R
2aa9b2bf49eea0c239c43af0d53a2a46 *R/makeLine.R
34fbbf860ef5a5e7e8bce1029726ec3c *R/makePatch.R
f88406fe7e71b669fa84ad396486a799 *R/rmSingle.R
fe7ff7e0947c9daab2b4b00cf6d3e0c7 *R/zzz.R
6424e2146149baa0cfc45a5600dcc513 *build/vignette.rds
6fbe40d2a4c543685ea49b7d68d82b2c *inst/COPYRIGHTS
464726e62c6ad0fe485a4b76f0a6567e *inst/doc/landscapeR.R
01ab4ef1bc8374abb04acc2ed251db32 *inst/doc/landscapeR.Rmd
69af454b18c51a43d4ce4d8c8458ba74 *inst/doc/landscapeR.html
e0a0184bc8a14d18e6b2108e701825a4 *man/expandClass.Rd
0161c105d034ee8634b02058eea25c70 *inst/doc/landscapeR.R
cfe410cda2724ce52400f88f03bc0030 *inst/doc/landscapeR.Rmd
70611d006f424723a51e06e88c41b209 *inst/doc/landscapeR.html
2dc11b416ed4038f7b3bfd7800eeb93d *man/expandClass.Rd
061baabcad8fd0f72cd37264dd888970 *man/landscapeR-package.Rd
5339e574f87235fd0f82291592526f30 *man/makeClass.Rd
ba89a8a6b8966f9c45ee861154fe59d5 *man/makeLine.Rd
67c94c78c8a133c470bce484ecb61c16 *man/makePatch.Rd
71d7f5b8af09f17c4a3c2ff31673f644 *man/rmSingle.Rd
01ab4ef1bc8374abb04acc2ed251db32 *vignettes/landscapeR.Rmd
501bb3c917e5b88a6dd8a137b37d1d93 *man/makeClass.Rd
78034a6f50373418e6ab5c2738e18fb6 *man/makeLine.Rd
864b0782b0c3bbaf4dcddd8e1071ea7c *man/makePatch.Rd
e80016f45623ed16c0a85dccb85afd65 *man/rmSingle.Rd
cfe410cda2724ce52400f88f03bc0030 *vignettes/landscapeR.Rmd
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
landscapeR v1.1.3 (Patch release date: 2016-12-13)
-----------------------------------------------
CHANGES:

* New mantainer's email address in the DESCRIPTION file
* Minor documentation edits in all functions
* Slight speed improvements with performant native R functions


landscapeR v1.1.2 (Patch release date: 2016-09-07)
-----------------------------------------------
CHANGES:
Expand Down
2 changes: 1 addition & 1 deletion R/expandClass.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ expandClass <- function(context, class, size, bgr=0, pts = NULL) {
ad <- .contigCells(pts, dim1, dim2)
## The following stands for {ad <- bgrCells[which(bgrCells %in% ad)]}
ad <- ad[.subset(mtx, ad) == bgr] # ad[mtx[ad] == bgr]
ad <- ad[!is.na(ad)]
ad <- ad[is.finite(ad)]
if(length(ad) == 0) {
edg <- edg[edg != pts]
if(length(edg) <= 1) {
Expand Down
7 changes: 4 additions & 3 deletions R/makeClass.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
#' @param context Raster object, a raster of an empty landscape or a mask, indicating where the patch cannot be generated (see \code{bgr} argument).
#' @param npatch number of patches per class
#' @param size integer. The size of patches, as number of raster cells. A single integer can be provided, in which case all patches will have that size.
#" @param pts integer or matrix. The seed point location around which the patches are built (random points are given by default). It can be an integer, as indeces of the cells in the raster, or a two columns matrix indicating x and y coordinates.
#" @return A vector of matrix cell numbers, or an raster object if \code{rast=TRUE}.
#" @param pts integer or matrix. The seed point location around which the patches are built (random points are given by default). It can be an integer, as indexes of the cells in the raster, or a two columns matrix indicating x and y coordinates.
#" @return A RasterLayer object, or a vector of cell numbers if \code{rast=FALSE}.
#' @details The patches created can be contiguous, therefore resembling a single patch with size
#' equal to the sum of contiguous cells.
#' equal to the sum of contiguous cells. The patches are created starting from the seed points (if provided) and iteratively sampling randomly neighbouring cells at the edge of the patch, according to von Neumann neighbourhood (four cells, aka Rook case).
#' There is a tolerance of +/- 3 cells from the patch size declared in \code{size} argument.
#' @examples
#' library(raster)
#'
Expand Down
9 changes: 5 additions & 4 deletions R/makeLine.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#" Create a linear patch
#" Create a linear patch (beta version).
#'
#' @description Create a linear patch, setting direction and convolution. The higher the convolution degree, the weaker the
#' linear shape (and direction).
Expand All @@ -17,7 +17,8 @@
#' library(raster)
#' r <- matrix(0,33,33)
#' r <- raster(r, xmn=0, xmx=10, ymn=0, ymx=10)
#' plot(makeLine(r, size=500, rast=TRUE))
#' plot(makeLine(r, size=50, spt = 545, direction=45, convol=0.05, rast=TRUE))
#'
#' @export
makeLine <- function(context, size, direction=NULL, convol=0.5, spt=NULL, bgr=0, edge=FALSE, rast=FALSE, val=1) {
if(!is.matrix(context)) {
Expand Down Expand Up @@ -55,7 +56,7 @@ makeLine <- function(context, size, direction=NULL, convol=0.5, spt=NULL, bgr=0,
while(cg < size){
ad <- .contigCells(spt, dim1, dim2)
ad <- ad[.subset(mtx, ad) == bgr]
ad <- ad[!is.na(ad)]
ad <- ad[is.finite(ad)]
if(length(ad) == 0) {
edg <- edg[edg != spt]
if(length(edg) <= 1) {
Expand Down Expand Up @@ -125,7 +126,7 @@ makeLine <- function(context, size, direction=NULL, convol=0.5, spt=NULL, bgr=0,
while(cg < size){
ad <- .contigCells(spt, dim1, dim2)
ad <- ad[.subset(mtx, ad) == bgr]
ad <- ad[!is.na(ad)]
ad <- ad[is.finite(ad)]
if(length(ad) == 0) {
edg <- edg[edg != spt]
if(length(edg) <= 1) {
Expand Down
8 changes: 4 additions & 4 deletions R/makePatch.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
#' @param context Raster object or matrix, an empty landscape raster or a mask indicating where the patch cannot be generated (see bgr below).
#' @param size integer. Size of the patch to be generated, as number of raster cells.
#' @param spt integer or matrix. The seed point location around which the patch is generated (a random point is given by default). It can be an integer, as index of the cell in the raster, or a two columns matrix indicating x and y coordinates (an integer vector of length 2 is accepted too).
#" @param bgr integer. Value of background cells, where a patch can be generated (default is zero). Cells/classes which cannot be changed must have a different value.
#" @param bgr integer. A single value of background cells, where a patch can be generated (default is zero). Cells/classes which cannot be changed must have a different value.
#' @param edge logical. Should the vector of edge cells of the patch be returned?
#' @param rast logical. If TRUE returns a Raster object, otherwise a vector of cell numbers where the patch occurs
#' @param val integer. The value to be assigned to patch cells, when \code{rast=TRUE}
#' @return A vector of raster cell numbers, or a RasterLayer object if \code{rast=TRUE}. If \code{edge=TRUE} a
#' list of two vectors is returned: one for the inner raster cells and the second for cells at the edge of the patch.
#" @details The patch is created starting from the seed point and iteratively sampling randomly neighbouring cells at the edge of the patch.
#" @details The patch is created starting from the seed point and iteratively sampling randomly neighbouring cells at the edge of the patch, according to von Neumann neighbourhood (four cells, aka Rook case).
#' There is a tolerance of +/- 3 cells from the patch size declared in \code{size} argument.
#" Also, argument \code{bgr} accepts a single value only, unlike \code{makeClass} that accept multiple.
#" Argument \code{bgr} accepts a single value only, unlike \code{makeClass} that accepts multiple and should therefore preferred.
#' @examples
#' library(raster)
#' mtx = matrix(0, 33, 33)
Expand Down Expand Up @@ -75,7 +75,7 @@ makePatch <- function(context, size, spt=NULL, bgr=0, edge=FALSE, rast=FALSE, va
ad <- .contigCells(spt, dim1, dim2)
## The following stands for {ad <- bgrCells[which(bgrCells %in% ad)]}. It was {d <- fastmatch::fmatch(ad, bgrCells, nomatch = 0);ad <- bgrCells[d]}
ad <- ad[.subset(mtx, ad) == bgr] #ad[mtx[ad] == bgr]
ad <- ad[!is.na(ad)]
ad <- ad[is.finite(ad)]
if(length(ad) == 0) {
edg <- edg[edg != spt]
if(length(edg) <= 1) {
Expand Down
18 changes: 10 additions & 8 deletions R/rmSingle.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,32 @@
#' This function reduces the "salt-pepper" effect, identifying or correcting those cells.
#' % ADD FUNCTIONALITY NOT ONLY SINGLES BUT USER DEFINED SIZE
#' @param rst input raster landscape.
#' @param rm logical, if TRUE returns the raster without single tones cells, if FALSE a vector of numbers identifying the single tones cells.
#' @return a raster without single tones cells. If \code{rm=TRUE}, a vector of numbers identifying the single tones cells.
#' @param rm logical, if TRUE returns the raster without single tones cells, if FALSE a vector of numbers identifying the index of single tones cells.
#' @return A raster without single tones cells. If \code{rm=FALSE}, it returns a vector of numbers identifying the index of single tones cells.
#' The value assigned to single tone cells is picked from one of the four neighbouring cells, selected at random.
#' @examples
#' library(raster)
#' m = matrix(0, 33, 33)
#' r = raster(m, xmn=0, xmx=10, ymn=0, ymx=10)
#' patchSize = 500
#'
#' ## Make a patch and introduce a single tone cell
#' r = makePatch(r, patchSize, spt=578, rast=TRUE)
#' r[578] = 0
#' plot(r)
#'
#' ## Introduce a single tone cell and remove it with rmSingle
#' r[578] = 0
#' ## Now remove it
#' plot( rmSingle(r) )
#'
#' ## Single tones can be identified but not removed:
#' rmSingle(r, rm = FALSE)
#' @export
#'
#' @export
rmSingle <- function(rst, rm = TRUE){
dim1 <- dim(rst)[1]
dim2 <- dim(rst)[2]
singles <- vector()
v <- vval <- raster::getValues(rst)
v <- which(!is.na(v))
v <- which(is.finite(v))
for (pt in v){ ## Faster than sapply or vapply!
if(pt %% dim2 == 0){
cc <- dim2
Expand All @@ -39,7 +41,7 @@ rmSingle <- function(rst, rm = TRUE){
ad <- c(rr-1,rr+1,rr,rr,cc,cc,cc-1,cc+1)
ad[ad <= 0 | c(ad[1:4] > dim1, ad[5:8] > dim2)] <- NA
ad <- ad[5:8] + (ad[1:4]-1)*dim2
ad <- ad[!is.na(ad)]
ad <- ad[is.finite(ad)]
if(all(.subset(vval, ad) != .subset(vval, pt))){
if(rm == TRUE){
vval[pt] <- sample(.subset(vval, ad), 1)
Expand Down
10 changes: 9 additions & 1 deletion inst/doc/landscapeR.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,17 @@ plot(rr)
## ------------------------------------------------------------------------
m[] <- 0
r <- raster(m, xmn=0, xmx=10, ymn=0, ymx=10)
rr <- makeLine(r, size=50, val=2, convol=0.05, spt=545, rast=TRUE)
rr <- makeLine(r, size=50, spt = 545, direction=45, convol=0.05, val=2, rast=TRUE)
plot(rr)

## ---- fig.width=4, fig.height=4------------------------------------------
rr <- matrix(0,100,100)
rr <- raster(rr, xmn=0, xmx=10, ymn=0, ymx=10)
for(i in c(550, 3050, 5050, 7550)){
rr = makeLine(rr, size=50, rast=TRUE, spt=i, direction=135, convol=0.25)
}
plot(expandClass(rr, 1, 250))

## ---- fig.width=6, warning=FALSE-----------------------------------------
rr <- makeClass(r, 10, 100)
par(mfrow=c(1,2))
Expand Down
16 changes: 12 additions & 4 deletions inst/doc/landscapeR.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ r <- raster(m, xmn=0, xmx=10, ymn=0, ymx=10)
```

### `makePatch`
This is the basic function to create a single patch. By default, `makePatch` returns a vector of cell indexes, so argument `rast=TRUE` must be specified to plot a map.
This is the basic function to create a single patch. However, `makeClass` should be preferred, even when creating a single patch (see below). By default, `makePatch` returns a vector of cell indexes, so to plot a map argument `rast=TRUE`. More features can be specified about the patch, but `makeClass` provide better exception/error handling.
```{r, eval=FALSE}
rr <- makePatch(r, size=500, rast=TRUE)
plot(rr)
```
More features can be specified about the patch. However, `makeClass` should be preferred, even when creating a single patch (see below).

### `makeClass`
`makeClass` generates a group of patches, as specified by arguments. Example:
Expand Down Expand Up @@ -124,10 +123,20 @@ Creates a linear feature, at a given convolution level and direction in degrees
```{r}
m[] <- 0
r <- raster(m, xmn=0, xmx=10, ymn=0, ymx=10)
rr <- makeLine(r, size=50, val=2, convol=0.05, spt=545, rast=TRUE)
rr <- makeLine(r, size=50, spt = 545, direction=45, convol=0.05, val=2, rast=TRUE)
plot(rr)
```

In combination with `expandClass` anisotropic features or landscapes can be created:
```{r, fig.width=4, fig.height=4}
rr <- matrix(0,100,100)
rr <- raster(rr, xmn=0, xmx=10, ymn=0, ymx=10)
for(i in c(550, 3050, 5050, 7550)){
rr = makeLine(rr, size=50, rast=TRUE, spt=i, direction=135, convol=0.25)
}
plot(expandClass(rr, 1, 250))
```

### `rmSingle`
Removes single tones from patches, reducing salt-pepper effect. The cells values are assigned from one random neighbouring cell (right plot).
```{r, fig.width=6, warning=FALSE}
Expand All @@ -138,4 +147,3 @@ rs <- rmSingle(rr)
plot(rs)
```


Loading

0 comments on commit d29092a

Please sign in to comment.