diff --git a/Data/Victoria mangrove pixels.tif b/Data/Victoria mangrove pixels.tif new file mode 100644 index 0000000..adc1101 Binary files /dev/null and b/Data/Victoria mangrove pixels.tif differ diff --git a/Data/readme.txt b/Data/readme.txt new file mode 100644 index 0000000..ebcc7ee --- /dev/null +++ b/Data/readme.txt @@ -0,0 +1,5 @@ +Victoria mangrove pixels.tif is a 2017 Victorian mangrove map created by using XGBoost. + +I've used the extent: extent(c(329000, 375000, -4250000, -4215000)) as my sample window for now. +The minimum AOO ('correct answer') I got us 2, though 4 seems to be the median. Any method that +gets us to 2 quickest should be our target! \ No newline at end of file diff --git a/NAMESPACE b/NAMESPACE index af69102..8c7ab06 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -9,6 +9,7 @@ export(getArea) export(getAreaChange) export(getAreaEOO) export(getDeclineStats) +export(getMinAOO) export(gridUncertainty) export(gridUncertaintyBase) export(gridUncertaintyRandom) diff --git a/R/AOO_functions.R b/R/AOO_functions.R index aa63603..ebd8590 100644 --- a/R/AOO_functions.R +++ b/R/AOO_functions.R @@ -69,15 +69,15 @@ makeAOOGrid <- function (ecosystem.data, grid.size, min.percent.rule = TRUE, per x <- rasterize(xy, grid, fun='count') # returns a 10 * 10 raster where cell value is the number of points in the cell names(x) <- 'count' grid.shp <- rasterToPolygons(x, dissolve=FALSE) - if (min.percent.rule == FALSE){ - outGrid <- grid.shp - } - if (min.percent.rule == TRUE){ + + if (min.percent.rule){ cell.res <- res(ecosystem.data) area <- cell.res[1] * cell.res[2] one.pc.grid <- grid.size * grid.size / 100 # 1pc of grid cell threshold <- one.pc.grid * percent / area outGrid <- grid.shp[grid.shp$count > threshold,] # select only grids that meet one percent threshol + } else { + outGrid <- grid.shp } return (outGrid) } @@ -107,7 +107,6 @@ makeAOOGrid <- function (ecosystem.data, grid.size, min.percent.rule = TRUE, per #' AOO <- getAOO(r1, n, one.percent.rule = F) #' AOO # number of grid cells occupied by an ecosystem or species #' @export - getAOO <- function (ecosystem.data, grid.size, min.percent.rule = TRUE, percent = 1){ # Computes the number of 10x10km grid cells that are >1% covered by an ecosystem AOO.number = length(makeAOOGrid(ecosystem.data, grid.size, min.percent.rule, percent)) @@ -140,15 +139,15 @@ getAOOSilent <- function (ecosystem.data, grid, min.percent.rule = TRUE, percent x <- rasterize(xy, grid, fun='count') # returns a 10 * 10 raster where cell value is the number of points in the cell names(x) <- 'count' grid.shp <- rasterToPolygons(x, dissolve=FALSE) - if (min.percent.rule == FALSE){ - outGrid <- grid.shp - } - if (min.percent.rule == TRUE){ + + if (min.percent.rule){ cell.res <- res(ecosystem.data) area <- cell.res[1] * cell.res[2] one.pc.grid <- grid.size[1] * grid.size[2] / 100 # 1pc of grid cell threshold <- one.pc.grid * percent / area outGrid <- grid.shp[grid.shp$count > threshold,] # select only grids that meet one percent threshol + } else { + outGrid <- grid.shp } # end getAOO @@ -156,3 +155,68 @@ getAOOSilent <- function (ecosystem.data, grid, min.percent.rule = TRUE, percent return (AOO.number) } + + +#' Compute the Minimum Area of Occupancy (AOO) +#' +#' \code{getAOO} determines the number of area of occupancy (AOO) grid cells +#' occupied by a species or ecosystem. It includes capability for specifying +#' whether at least one percent of the grid cell needs to be occupied before it +#' is counted in the AOO. This functionality is important for assessing the IUCN +#' Red List of Ecosystems Criteria B. +#' +#' \code{getMinAOO} optimises the placement of the grid so the AOO is the +#' smalest possible. It does this using \code{constrOptim} with method SANN. +#' +#' @inheritParams makeAOOGrid +#' @param trace If TRUE, tracing information on the progress of the optimisation +#' is produced. +#' @return The number of grid cells occupied by the ecosystem or species +#' @author Nicholas Murray \email{murr.nick@@gmail.com}, Calvin Lee +#' \email{calvinkflee@@gmail.com}, John Wilshire +#' \email{john.h.wilshire@@gmail.com} +#' @family AOO functions +#' @references Bland, L.M., Keith, D.A., Miller, R.M., Murray, N.J. and +#' Rodriguez, J.P. (eds.) 2016. Guidelines for the application of IUCN Red +#' List of Ecosystems Categories and Criteria, Version 1.0. Gland, +#' Switzerland: IUCN. ix + 94pp. Available at the following web site: +#' \url{iucnrle.org/} +#' @examples +#' crs.UTM55N <- '+proj=utm +zone=55 +ellps=WGS84 +datum=WGS84 +units=m +no_defs' +#' r1 <- raster(ifelse((volcano<130), NA, 1), crs = crs.UTM55N) #t1 = 1990 +#' ext <- extent(0, 6100, 0, 8700) # set the extent of raster r1, 100m resolution +#' extent(r1) <- ext +#' (getMinAOO(r1, grid.size = 1000) -> AOO) # number of grid cells occupied by an ecosystem or species +#' @export + +getMinAOO <- function(ecosystem.data, grid.size, + min.percent.rule = TRUE, percent = 1, trace = TRUE) { + grid <- createGrid(ecosystem.data, grid.size) # create the inital grid + objective_fun <- function(x) { + getAOOSilent(ecosystem.data, + grid = shift(grid, x = x[1], y = x[2]), + min.percent.rule = min.percent.rule, + percent = percent) + } + + ub <- grid.size + lb <- 0 + ci <- c(lb, lb, -ub, -ub) + ui <- matrix(c(1, 0, -1, 0, + 0, 1, 0, -1), ncol = 2) + start <- runif(2, min = 0, max = grid.size) + constrOptim(start, + objective_fun, + method = "SANN", + ui = ui, + ci = ci, + grad = NULL, + control = list( + temp = grid.size, + tmax = 50, + maxit = 500, + parscale = c(grid.size, grid.size), + trace = trace) + ) -> o + o$value +} diff --git a/man/createGrid.Rd b/man/createGrid.Rd index b9c775b..614760b 100644 --- a/man/createGrid.Rd +++ b/man/createGrid.Rd @@ -36,7 +36,8 @@ Bland, L.M., Keith, D.A., Miller, R.M., Murray, N.J. and \code{\link{getRLEReport}} Other AOO functions: \code{\link{getAOOSilent}}, - \code{\link{getAOO}}, \code{\link{makeAOOGrid}} + \code{\link{getAOO}}, \code{\link{getMinAOO}}, + \code{\link{makeAOOGrid}} } \author{ Nicholas Murray \email{murr.nick@gmail.com}, Calvin Lee diff --git a/man/getAOO.Rd b/man/getAOO.Rd index bc93910..13bcf3e 100644 --- a/man/getAOO.Rd +++ b/man/getAOO.Rd @@ -45,7 +45,8 @@ Bland, L.M., Keith, D.A., Miller, R.M., Murray, N.J. and } \seealso{ Other AOO functions: \code{\link{createGrid}}, - \code{\link{getAOOSilent}}, \code{\link{makeAOOGrid}} + \code{\link{getAOOSilent}}, \code{\link{getMinAOO}}, + \code{\link{makeAOOGrid}} } \author{ Nicholas Murray \email{murr.nick@gmail.com}, Calvin Lee diff --git a/man/getAOOSilent.Rd b/man/getAOOSilent.Rd index fa4bcaf..a461c86 100644 --- a/man/getAOOSilent.Rd +++ b/man/getAOOSilent.Rd @@ -25,7 +25,8 @@ input of the grid parameter. Used for \code{gridUncertainty}. } \seealso{ Other AOO functions: \code{\link{createGrid}}, - \code{\link{getAOO}}, \code{\link{makeAOOGrid}} + \code{\link{getAOO}}, \code{\link{getMinAOO}}, + \code{\link{makeAOOGrid}} } \author{ Nicholas Murray \email{murr.nick@gmail.com}, Calvin Lee diff --git a/man/getMinAOO.Rd b/man/getMinAOO.Rd new file mode 100644 index 0000000..35ec847 --- /dev/null +++ b/man/getMinAOO.Rd @@ -0,0 +1,63 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/AOO_functions.R +\name{getMinAOO} +\alias{getMinAOO} +\title{Compute the Minimum Area of Occupancy (AOO)} +\usage{ +getMinAOO(ecosystem.data, grid.size, min.percent.rule = TRUE, percent = 1, + trace = TRUE) +} +\arguments{ +\item{ecosystem.data}{Raster object of an ecosystem or species distribution. +Please use a CRS with units measured in metres.} + +\item{grid.size}{A number specifying the width of the desired grid square (in +same units as your coordiante reference system)} + +\item{min.percent.rule}{Logical. If \code{TRUE}, a minimum area threshold +must be passed before a grid is counted as an AOO grid.} + +\item{percent}{Numeric. The minimum percent to be applied as a threshold for +the \code{min.percent.rule}} + +\item{trace}{If TRUE, tracing information on the progress of the optimisation +is produced.} +} +\value{ +The number of grid cells occupied by the ecosystem or species +} +\description{ +\code{getAOO} determines the number of area of occupancy (AOO) grid cells +occupied by a species or ecosystem. It includes capability for specifying +whether at least one percent of the grid cell needs to be occupied before it +is counted in the AOO. This functionality is important for assessing the IUCN +Red List of Ecosystems Criteria B. +} +\details{ +\code{getMinAOO} optimises the placement of the grid so the AOO is the +smalest possible. It does this using \code{constrOptim} with method SANN. +} +\examples{ +crs.UTM55N <- '+proj=utm +zone=55 +ellps=WGS84 +datum=WGS84 +units=m +no_defs' +r1 <- raster(ifelse((volcano<130), NA, 1), crs = crs.UTM55N) #t1 = 1990 +ext <- extent(0, 6100, 0, 8700) # set the extent of raster r1, 100m resolution +extent(r1) <- ext +(getMinAOO(r1, grid.size = 1000) -> AOO) # number of grid cells occupied by an ecosystem or species +} +\references{ +Bland, L.M., Keith, D.A., Miller, R.M., Murray, N.J. and + Rodriguez, J.P. (eds.) 2016. Guidelines for the application of IUCN Red + List of Ecosystems Categories and Criteria, Version 1.0. Gland, + Switzerland: IUCN. ix + 94pp. Available at the following web site: + \url{iucnrle.org/} +} +\seealso{ +Other AOO functions: \code{\link{createGrid}}, + \code{\link{getAOOSilent}}, \code{\link{getAOO}}, + \code{\link{makeAOOGrid}} +} +\author{ +Nicholas Murray \email{murr.nick@gmail.com}, Calvin Lee + \email{calvinkflee@gmail.com}, John Wilshire + \email{john.h.wilshire@gmail.com} +} diff --git a/man/makeAOOGrid.Rd b/man/makeAOOGrid.Rd index 482411a..73e4b3c 100644 --- a/man/makeAOOGrid.Rd +++ b/man/makeAOOGrid.Rd @@ -45,7 +45,8 @@ Bland, L.M., Keith, D.A., Miller, R.M., Murray, N.J. and } \seealso{ Other AOO functions: \code{\link{createGrid}}, - \code{\link{getAOOSilent}}, \code{\link{getAOO}} + \code{\link{getAOOSilent}}, \code{\link{getAOO}}, + \code{\link{getMinAOO}} } \author{ Nicholas Murray \email{murr.nick@gmail.com}, Calvin Lee diff --git a/redlistr.Rproj b/redlistr.Rproj index cba1b6b..205a4cd 100644 --- a/redlistr.Rproj +++ b/redlistr.Rproj @@ -2,7 +2,7 @@ Version: 1.0 RestoreWorkspace: No SaveWorkspace: No -AlwaysSaveHistory: Default +AlwaysSaveHistory: No EnableCodeIndexing: Yes UseSpacesForTab: Yes @@ -17,5 +17,5 @@ StripTrailingWhitespace: Yes BuildType: Package PackageUseDevtools: Yes -PackageInstallArgs: --no-multiarch --with-keep.source +PackageInstallArgs: --no-multiarch --with-keep.source --preclean PackageRoxygenize: rd,collate,namespace