Skip to content

Commit

Permalink
remove 'spreadFactor' and 'filterPatch' args from MPG() (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
achubaty committed Oct 24, 2016
1 parent 2554c65 commit ca3441a
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 110 deletions.
24 changes: 3 additions & 21 deletions R/MPG.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@
#' For lattice analyses, an integer gives the spacing in raster
#' cells between focal points in the lattice.
#'
#' @param filterPatch Optional. Remove patches from the analysis that are smaller
#' than a given number of cells.
#'
#' @param spreadFactor Optional. Fine-grained control over the accuracy of Voronoi polygons.
#' To reduce accuracy and increase speed, set this as
#' \code{spreadFactor=10} or \code{spreadFactor=100}.
#'
#' @param ... Additional arguments (not used).
#'
#' @return A \code{\link[=mpg-class]{mpg}} object.
Expand Down Expand Up @@ -109,8 +102,7 @@ setGeneric("MPG", function(cost, patch, ...) {
setMethod(
"MPG",
signature = c(cost = "RasterLayer", patch = "RasterLayer"),
definition = function(cost, patch, filterPatch = NULL,
spreadFactor = 0, ...) {
definition = function(cost, patch, ...) {
## Check patch and cost are comparable
if (!compareRaster(patch, cost, res = TRUE, orig = TRUE, stopiffalse = FALSE)) {
stop("grainscape: patch and cost rasters must be identical in extent, projection, origin and resolution.", call. = FALSE)
Expand All @@ -133,15 +125,6 @@ setMethod(
rasCost[] <- getValues(cost)
rasPatch[] <- getValues(patch)

## Check filterPatch
if (is.null(filterPatch)) {
## Set filterPatch smaller than area of cell
filterPatch <- (prod(res(rasCost))/10000) * 0.01
} else {
## Set filterPatch as area in hectares
filterPatch <- (prod(res(rasCost))/10000) * abs(filterPatch)
}

## Check that patch raster is binary, first corecing NAs to zeroes
rasPatch[is.na(rasPatch)] <- 0
if (!all(unique(rasPatch[]) %in% c(FALSE, TRUE))) {
Expand Down Expand Up @@ -221,7 +204,7 @@ setMethod(
setMethod(
"MPG",
signature = c(cost = "RasterLayer", patch = "numeric"),
definition = function(cost, patch, filterPatch = NULL, spreadFactor = 0, ...) {
definition = function(cost, patch, ...) {
## Produce the lattice patch rasters
focalPointDistFreq <- patch
patch <- cost
Expand All @@ -232,6 +215,5 @@ setMethod(
## Remove lattice points that fall on NA cost cells
patch[is.na(cost)] <- 0

MPG(cost = cost, patch = patch, filterPatch = filterPatch,
spreadFactor = spreadFactor, ...)
MPG(cost = cost, patch = patch, ...)
})
6 changes: 4 additions & 2 deletions R/deprecated.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ gsGraphDataFrame <- function(x) {

#' @export gsMPG
#' @inheritParams MPG
#' @param sa No longer used.
#' @param filterPatch,sa,spreadFactor No longer used.
#' @rdname grainscape-deprecated
#'
gsMPG <- function(cost, patch, sa = NULL, filterPatch = NULL, spreadFactor = 0) {
.Deprecated("MPG", old = "gsMPG")
if (!is.null(filterPatch)) warning("gsMPG(): argument 'filterPatch' was supplied but will be ignored.")
if (!is.null(sa)) warning("gsMPG(): argument 'sa' was supplied but will be ignored.")
MPG(cost, patch, filterPatch, spreadFactor)
if (spreadFactor != 0) warning("gsMPG(): argument 'spreadFactor' was supplied but will be ignored.")
MPG(cost, patch)
}
13 changes: 2 additions & 11 deletions man/MPG.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 1 addition & 8 deletions man/grainscape-deprecated.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 21 additions & 68 deletions man/grainscape-maps.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 69 additions & 0 deletions man/grainscape-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ca3441a

Please sign in to comment.